diff options
Diffstat (limited to 'src/Java/gtPlusPlus/api/objects')
11 files changed, 256 insertions, 26 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/MaterialHelper.java b/src/Java/gtPlusPlus/api/objects/MaterialHelper.java deleted file mode 100644 index d63ab7a15a..0000000000 --- a/src/Java/gtPlusPlus/api/objects/MaterialHelper.java +++ /dev/null @@ -1,18 +0,0 @@ -package gtPlusPlus.api.objects; - -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.util.item.ItemUtils; -import net.minecraft.item.ItemStack; - -public class MaterialHelper { - - public static ItemStack getComponentFromMaterial(OrePrefixes oreprefix, Material material, int amount){ - return ItemUtils.getOrePrefixStack(oreprefix, material, amount); - } - public static ItemStack getComponentFromGtMaterial(OrePrefixes oreprefix, Materials material, int amount){ - return ItemUtils.getGregtechOreStack(oreprefix, material, amount); - } - -} diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java new file mode 100644 index 0000000000..a8d24d36d8 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java @@ -0,0 +1,77 @@ +package gtPlusPlus.api.objects.data; + +import java.io.Serializable; +import java.util.*; + +public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable { + + /** + * The Internal Map + */ + private Map<Integer, V> mInternalMap = new HashMap<Integer, V>(); + + /** + * The Internal ID + */ + private int mInternalID = 0; + private static final long serialVersionUID = 3771412318075131790L; + + @Override + public Iterator<V> iterator() { + return values().iterator(); + } + + public synchronized boolean setValue(V object){ + int mOriginalID = this.mInternalID; + put(object); + if (this.mInternalMap.get(mOriginalID).equals(object) || mOriginalID > this.mInternalID){ + return true; + } + else { + return false; + } + } + + public synchronized V put(V object){ + return set(object); + } + + public synchronized V set(V object){ + return mInternalMap.put(mInternalID++, object); + } + + public synchronized V get(int id){ + return mInternalMap.get(id); + } + + public synchronized Collection<V> values(){ + return mInternalMap.values(); + } + + public synchronized int size(){ + return mInternalMap.size(); + } + + public synchronized int hashcode(){ + return mInternalMap.hashCode(); + } + + public synchronized boolean containsKey(int key){ + return mInternalMap.containsKey(key); + } + + public synchronized boolean containsValue(V value){ + return mInternalMap.containsValue(value); + } + + public synchronized boolean isEmpty(){ + return mInternalMap.isEmpty(); + } + + public synchronized boolean clear(){ + this.mInternalID = 0; + this.mInternalMap.clear(); + return true; + } + +} diff --git a/src/Java/gtPlusPlus/api/objects/data/Pair.java b/src/Java/gtPlusPlus/api/objects/data/Pair.java new file mode 100644 index 0000000000..6ab781cf1e --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/data/Pair.java @@ -0,0 +1,27 @@ +package gtPlusPlus.api.objects.data; + +import java.io.Serializable; + +public class Pair<K,V> implements Serializable { + + /** + * SVUID + */ + private static final long serialVersionUID = 1250550491092812443L; + private final K key; + private final V value; + + public Pair(final K key, final V value){ + this.key = key; + this.value = value; + } + + final public K getKey(){ + return this.key; + } + + final public V getValue(){ + return this.value; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/objects/data/Quad.java b/src/Java/gtPlusPlus/api/objects/data/Quad.java new file mode 100644 index 0000000000..01c62e95e6 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/data/Quad.java @@ -0,0 +1,33 @@ +package gtPlusPlus.api.objects.data; + +public class Quad<K,V,C,R> { + + private final K key; + private final V value; + private final C value2; + private final R value3; + + public Quad(final K key, final V value, final C value2, final R value3){ + this.key = key; + this.value = value; + this.value2 = value2; + this.value3 = value3; + } + + final public K getKey(){ + return this.key; + } + + final public V getValue_1(){ + return this.value; + } + + final public C getValue_2(){ + return this.value2; + } + + final public R getValue_3(){ + return this.value3; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/objects/data/Triplet.java b/src/Java/gtPlusPlus/api/objects/data/Triplet.java new file mode 100644 index 0000000000..affb03d868 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/data/Triplet.java @@ -0,0 +1,27 @@ +package gtPlusPlus.api.objects.data; + +public class Triplet<K,V,C> { + + private final K key; + private final V value; + private final C count; + + public Triplet(final K key, final V value, final C value2){ + this.key = key; + this.value = value; + this.count = value2; + } + + final public K getValue_1(){ + return this.key; + } + + final public V getValue_2(){ + return this.value; + } + + final public C getValue_3(){ + return this.count; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java new file mode 100644 index 0000000000..d258d1fe73 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -0,0 +1,85 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.io.Serializable; + +public class BlockPos implements Serializable{ + + private static final long serialVersionUID = -7271947491316682006L; + public final int xPos; + public final int yPos; + public final int zPos; + public final int dim; + + public BlockPos(int x, int y, int z){ + this(x, y, z, 0); + } + + public BlockPos(int x, int y, int z, int dim){ + this.xPos = x; + this.yPos = y; + this.zPos = z; + this.dim = dim; + } + + public String getLocationString() { + return "[X: "+this.xPos+"][Y: "+this.yPos+"][Z: "+this.zPos+"][Dim: "+this.dim+"]"; + } + + @Override + public int hashCode() { + int hash = 5; + hash += (13 * this.xPos); + hash += (19 * this.yPos); + hash += (31 * this.zPos); + hash += (17 * this.dim); + return hash; + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other == this) { + return true; + } + if(!(other instanceof BlockPos)) { + return false; + } + BlockPos otherPoint = (BlockPos)other; + return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos && this.dim == otherPoint.dim; + } + + public int distanceFrom(BlockPos target) { + if (target.dim != this.dim) { + return Short.MIN_VALUE; + } + return distanceFrom(target.xPos, target.yPos, target.zPos); + } + + /** + * + * @param x X coordinate of target. + * @param y Y coordinate of target. + * @param z Z coordinate of target. + * @return square of distance + */ + public int distanceFrom(int x, int y, int z) { + int distanceX = this.xPos - x; + int distanceY = this.yPos - y; + int distanceZ = this.zPos - z; + return distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ; + } + + public boolean isWithinRange(BlockPos target, int range) { + if (target.dim != this.dim) { + return false; + } + return isWithinRange(target.xPos, target.yPos, target.zPos, range); + } + + public boolean isWithinRange(int x, int y, int z, int range) { + return distanceFrom(x, y, z) <= (range * range); + } + +} diff --git a/src/Java/gtPlusPlus/api/objects/ChunkManager.java b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java index 0bace04bf8..b411e8875a 100644 --- a/src/Java/gtPlusPlus/api/objects/ChunkManager.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java @@ -6,14 +6,14 @@ * permission unless otherwise specified on the * license page at http://railcraft.info/wiki/info:license. */ -package gtPlusPlus.api.objects; +package gtPlusPlus.api.objects.minecraft; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gtPlusPlus.GTplusplus; -import gtPlusPlus.core.util.array.BlockPos; -import gtPlusPlus.core.util.array.Triplet; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.Triplet; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader; import java.util.HashSet; diff --git a/src/Java/gtPlusPlus/api/objects/DimChunkPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java index bea0a4ec3b..010e522a14 100644 --- a/src/Java/gtPlusPlus/api/objects/DimChunkPos.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java @@ -1,6 +1,5 @@ -package gtPlusPlus.api.objects; +package gtPlusPlus.api.objects.minecraft; -import gtPlusPlus.core.util.array.BlockPos; import net.minecraft.client.Minecraft; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; diff --git a/src/Java/gtPlusPlus/api/objects/GenericStack.java b/src/Java/gtPlusPlus/api/objects/minecraft/GenericStack.java index b3bc94364f..f5db1d9e3a 100644 --- a/src/Java/gtPlusPlus/api/objects/GenericStack.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/GenericStack.java @@ -1,4 +1,4 @@ -package gtPlusPlus.api.objects; +package gtPlusPlus.api.objects.minecraft; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; diff --git a/src/Java/gtPlusPlus/api/objects/CSPRNG_DO_NOT_USE.java b/src/Java/gtPlusPlus/api/objects/random/CSPRNG_DO_NOT_USE.java index 19200846ca..b2dc984456 100644 --- a/src/Java/gtPlusPlus/api/objects/CSPRNG_DO_NOT_USE.java +++ b/src/Java/gtPlusPlus/api/objects/random/CSPRNG_DO_NOT_USE.java @@ -33,7 +33,7 @@ * http://www.opensource.org/licenses/bsd-license.php */ -package gtPlusPlus.api.objects; +package gtPlusPlus.api.objects.random; import java.math.BigInteger; import java.security.SecureRandom; import java.util.Random; diff --git a/src/Java/gtPlusPlus/api/objects/XSTR.java b/src/Java/gtPlusPlus/api/objects/random/XSTR.java index 3ff0792f6e..7f83df52c4 100644 --- a/src/Java/gtPlusPlus/api/objects/XSTR.java +++ b/src/Java/gtPlusPlus/api/objects/random/XSTR.java @@ -1,4 +1,4 @@ -package gtPlusPlus.api.objects; +package gtPlusPlus.api.objects.random; /** * A subclass of java.util.random that implements the Xorshift random number * generator |