This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
212 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions
106
src/main/java/com/scottkillen/mod/koresample/common/util/WeightedSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.scottkillen.mod.koresample.common.util; | ||
|
||
import com.google.common.base.Objects; | ||
import com.google.common.collect.HashMultiset; | ||
import com.google.common.collect.Multiset; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Random; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
@SuppressWarnings({ "WeakerAccess", "StandardVariableNames" }) | ||
public class WeightedSet<T> implements Collection<T> | ||
{ | ||
private final Random random; | ||
private final Multiset<T> elements = HashMultiset.create(); | ||
|
||
public static <T> WeightedSet<T> newWeightedSet() { return new WeightedSet<T>(); } | ||
|
||
public static <T> WeightedSet<T> newWeightedSet(Random random) { return new WeightedSet<T>(random); } | ||
|
||
public WeightedSet() | ||
{ | ||
this(new Random()); | ||
} | ||
|
||
public WeightedSet(Random random) | ||
{ | ||
checkNotNull(random, "Random generator is required."); | ||
|
||
this.random = random; | ||
} | ||
|
||
public T randomPick() | ||
{ | ||
final int pick = random.nextInt(elements.size()); | ||
int count = 0; | ||
for (final T t : elements.elementSet()) | ||
{ | ||
count += elements.count(t); | ||
if (count >= pick) return t; | ||
} | ||
//noinspection ReturnOfNull | ||
return null; | ||
} | ||
|
||
public void setWeight(T t, int weight) { elements.setCount(t, weight); } | ||
|
||
@Override | ||
public int size() { return elements.size(); } | ||
|
||
@Override | ||
public boolean isEmpty() { return elements.isEmpty(); } | ||
|
||
@Override | ||
public boolean contains(Object o) { return elements.contains(o); } | ||
|
||
@Override | ||
public Iterator<T> iterator() { return elements.iterator(); } | ||
|
||
@Override | ||
public Object[] toArray() { return elements.toArray(); } | ||
|
||
@SuppressWarnings({ "SuspiciousToArrayCall", "TypeParameterHidesVisibleType" }) | ||
@Override | ||
public <T> T[] toArray(T[] a) { return elements.toArray(a); } | ||
|
||
@Override | ||
public boolean add(T t) { return elements.add(t); } | ||
|
||
@Override | ||
public boolean remove(Object o) { return elements.remove(o); } | ||
|
||
@Override | ||
public boolean containsAll(Collection<?> c) { return elements.containsAll(c); } | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends T> c) { return elements.addAll(c); } | ||
|
||
@Override | ||
public boolean removeAll(Collection<?> c) { return elements.removeAll(c); } | ||
|
||
@Override | ||
public boolean retainAll(Collection<?> c) { return elements.retainAll(c); } | ||
|
||
@Override | ||
public void clear() { elements.clear(); } | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (!(o instanceof WeightedSet)) return false; | ||
|
||
final WeightedSet<?> that = (WeightedSet<?>) o; | ||
return elements.equals(that.elements); | ||
} | ||
|
||
@Override | ||
public int hashCode() { return elements.hashCode(); } | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return Objects.toStringHelper(this).add("random", random).add("elements", elements).toString(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/scottkillen/mod/koresample/common/util/multiblock/SubBlockManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.scottkillen.mod.koresample.common.util.multiblock; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraft.client.renderer.texture.IIconRegister; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.util.IIcon; | ||
import java.util.List; | ||
|
||
public interface SubBlockManager | ||
{ | ||
@SideOnly(Side.CLIENT) | ||
IIcon getIcon(int side, int meta); | ||
|
||
@SideOnly(Side.CLIENT) | ||
void registerIcons(IIconRegister register); | ||
|
||
@SideOnly(Side.CLIENT) | ||
void getSubBlocks(Item item, CreativeTabs tabs, List list); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon, 16 Feb 2015 00:21:40 -0500 | ||
#Sun, 31 May 2015 21:41:35 -0400 | ||
mcversion=1.7.10 | ||
forgeversion=10.13.2.1291 | ||
version_major=1 | ||
version_series=2 | ||
version_revision=5 | ||
version_series=3 | ||
version_revision=0 |