diff options
Diffstat (limited to 'src/Java/gtPlusPlus/api/objects')
3 files changed, 238 insertions, 1 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java index 4663229514..3583a04a74 100644 --- a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java +++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java @@ -3,7 +3,7 @@ package gtPlusPlus.api.objects.data; import java.io.Serializable; import java.util.*; -public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable, Collection<V>, Queue<V> { +public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable, Collection<V>, Queue<V>, List<V> { /** * The Internal Map @@ -22,11 +22,55 @@ public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable, Collect this(new LinkedHashMap<Integer, V>()); } + public Map<Integer, V> getMap(){ + return mInternalMap; + } + public AutoMap(Map<Integer, V> defaultMapType) { mInternalMap = defaultMapType; mInternalNameMap = new LinkedHashMap<String, Integer>(); } + /** + * Generates an AutoMap from the List. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(List<V> aList) { + mInternalMap = new LinkedHashMap<Integer, V>(); + mInternalNameMap = new LinkedHashMap<String, Integer>(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + /** + * Generates an AutoMap from a Set. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(Set<V> aList) { + mInternalMap = new LinkedHashMap<Integer, V>(); + mInternalNameMap = new LinkedHashMap<String, Integer>(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + /** + * Generates an AutoMap from a Collection. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(Collection<V> aList) { + mInternalMap = new LinkedHashMap<Integer, V>(); + mInternalNameMap = new LinkedHashMap<String, Integer>(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + @Override public Iterator<V> iterator() { return values().iterator(); @@ -211,5 +255,78 @@ public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable, Collect public V peek() { return element(); } + + @Override + public boolean addAll(int index, Collection<? extends V> c) { + for (V y : c) { + add(y); + } + return true; + } + + @Override + public V set(int index, V element) { + return mInternalMap.put(index, element); + } + + @Override + public void add(int index, V element) { + add(element); + } + + @Override + public V remove(int index) { + V h = mInternalMap.get(index); + set(index, null); + return h; + } + + @Override + public int indexOf(Object o) { + int aCount = 0; + for (V of : mInternalMap.values()) { + if (of != o) { + aCount++; + continue; + } + else { + return aCount; + } + } + return -1; + } + + @Override + public int lastIndexOf(Object o) { + //TODO + return indexOf(o); + } + + @Override + public ListIterator<V> listIterator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ListIterator<V> listIterator(int index) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<V> subList(int fromIndex, int toIndex) { + AutoMap<V> aNewSubList = new AutoMap<V>(); + for (int slot=fromIndex; slot<=toIndex; slot++) { + V obj = mInternalMap.get(slot); + if (obj == null) { + continue; + } + else { + aNewSubList.put(obj); + } + } + return aNewSubList; + } } diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java b/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java new file mode 100644 index 0000000000..722ac00b64 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java @@ -0,0 +1,65 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.core.util.minecraft.EntityUtils; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +/** + * Generates an AABB around an entity. + * @author Alkalus + * + */ +public class AABB { + + private final AxisAlignedBB mAabb; + private final World mWorld; + + /** + * Creates a AxisAlignedBB based around an Entity. + * @param aEntity - The Entity to work with. + * @param x - Maximum X from origin. + * @param y - Maximum Y from origin. + * @param z - Maximum Z from origin. + */ + public AABB(Entity aEntity, int x, int y, int z) { + if (aEntity == null) { + mAabb = null; + mWorld = null; + } + else { + mWorld = aEntity.worldObj; + BlockPos aEntityLocation = EntityUtils.findBlockPosUnderEntity(aEntity); + int xMin, xMax, yMin, yMax, zMin, zMax; + xMin = aEntityLocation.xPos; + yMin = aEntityLocation.yPos; + zMin = aEntityLocation.zPos; + xMax = aEntityLocation.xPos + x; + yMax = aEntityLocation.yPos + y; + zMax = aEntityLocation.zPos + z; + mAabb = AxisAlignedBB.getBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax); + } + + } + + /** + * Used to get the AxisAlignedBB from this class. + * @return + */ + public AxisAlignedBB get() { + return mAabb; + } + + /** + * Used to determine if this object is valid or not. + * @return + */ + public boolean valid() { + return mAabb != null && mWorld != null; + } + + public World world() { + return mWorld; + } + +} diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java b/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java new file mode 100644 index 0000000000..e610f8fdf0 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/TexturePackage.java @@ -0,0 +1,55 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.LinkedHashMap; +import java.util.Set; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.util.IIcon; + +public class TexturePackage { + + private AutoMap<IIcon> mAnimationArray = new AutoMap<IIcon>(); + + public IIcon getFrame(int aFrame) { + if (aFrame < 0 || aFrame >= mAnimationArray.size()) { + return mAnimationArray.get(0); + } + return mAnimationArray.get(aFrame); + } + + public boolean addFrame(IIcon aFrame) { + if (aFrame != null) { + return mAnimationArray.add(aFrame); + } + return false; + } + + public boolean addFrames(AutoMap<IIcon> aFrames) { + for (IIcon h : aFrames) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + public boolean addFrames(LinkedHashMap<?, IIcon> aFrames) { + for (IIcon h : aFrames.values()) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + public boolean addFrames(Set<IIcon> aFrames) { + for (IIcon h : aFrames) { + if (!addFrame(h)) { + return false; + } + } + return true; + } + + +} |