diff options
author | Jordan Byrne <draknyte1@hotmail.com> | 2017-12-03 17:59:52 +1000 |
---|---|---|
committer | Jordan Byrne <draknyte1@hotmail.com> | 2017-12-03 17:59:52 +1000 |
commit | a88252907e40b8dd44e830febea21c93ae9bd4c5 (patch) | |
tree | 0be039db89d9d152c335a20c2397dd48efa6563a | |
parent | 7d78127c44c1cf374392f85072214c3886bbfb29 (diff) | |
download | GT5-Unofficial-a88252907e40b8dd44e830febea21c93ae9bd4c5.tar.gz GT5-Unofficial-a88252907e40b8dd44e830febea21c93ae9bd4c5.tar.bz2 GT5-Unofficial-a88252907e40b8dd44e830febea21c93ae9bd4c5.zip |
+ Base work for a Dragon Capture Jar added.
+ Added more NBT utils.
3 files changed, 228 insertions, 11 deletions
diff --git a/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java b/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java new file mode 100644 index 0000000000..fa091bf3bf --- /dev/null +++ b/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java @@ -0,0 +1,16 @@ +package gtPlusPlus.api.interfaces; + +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; + +public interface IEntityCatcher { + + public boolean hasEntity(ItemStack aStack); + + public Entity getStoredEntity(ItemStack aStack); + + public boolean setStoredEntity(ItemStack aStack, Entity aEntity); + + public Class getStoredEntityClass(ItemStack aStack); + +} diff --git a/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java b/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java new file mode 100644 index 0000000000..f771679d23 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/general/capture/ItemEntityCatcher.java @@ -0,0 +1,81 @@ +package gtPlusPlus.core.item.general.capture; + +import java.util.UUID; + +import gtPlusPlus.api.interfaces.IEntityCatcher; +import gtPlusPlus.core.util.nbt.NBTUtils; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class ItemEntityCatcher extends Item implements IEntityCatcher { + + @Override + public boolean hasEntity(ItemStack aStack) { + if (NBTUtils.hasKey(aStack, "mHasEntity")){ + return NBTUtils.getBoolean(aStack, "mHasEntity"); + } + return false; + } + + @Override + public Entity getStoredEntity(ItemStack aStack) { + if (aStack == null || !NBTUtils.getBooleanTagCompound(aStack, "mEntity", "mHasEntity")){ + return null; + } + + NBTTagCompound mEntityData; + Class<? extends Entity> mEntityClass; + String mClassName; + int mEntityID, mEntityHashcode; + UUID mUuidPersistent, mUuidUnique; + + mEntityData = NBTUtils.getTagCompound(aStack, "mEntity", "mEntityData"); + mEntityID = NBTUtils.getIntegerTagCompound(aStack, "mEntity", "mEntityID"); + mClassName = NBTUtils.getStringTagCompound(aStack, "mEntity", "mClassName"); + mUuidPersistent = UUID.fromString(NBTUtils.getStringTagCompound(aStack, "mEntity", "mUuidPersistent")); + mUuidUnique = UUID.fromString(NBTUtils.getStringTagCompound(aStack, "mEntity", "mUuidUnique")); + mEntityHashcode = NBTUtils.getIntegerTagCompound(aStack, "mEntity", "mEntityHashcode"); + } + + @Override + public boolean setStoredEntity(ItemStack aStack, Entity aEntity) { + if (aEntity == null){ + NBTUtils.setBoolean(aStack, "mHasEntity", true); + return false; + } + + NBTTagCompound mEntityData; + Class<? extends Entity> mEntityClass; + String mClassName; + int mEntityID, mEntityHashcode; + UUID mUuidPersistent, mUuidUnique; + + mEntityData = aEntity.getEntityData(); + mEntityClass = aEntity.getClass(); + mClassName = mEntityClass.getName(); + mEntityID = aEntity.getEntityId(); + mEntityHashcode = aEntity.hashCode(); + mUuidPersistent = aEntity.getPersistentID(); + mUuidUnique = aEntity.getUniqueID(); + + NBTUtils.createTagCompound(aStack, "mEntity", "mEntityData", mEntityData); + NBTUtils.createIntegerTagCompound(aStack, "mEntity", "mEntityID", mEntityID); + NBTUtils.createStringTagCompound(aStack, "mEntity", "mClassName", mClassName); + NBTUtils.createStringTagCompound(aStack, "mEntity", "mUuidPersistent", mUuidPersistent.toString()); + NBTUtils.createStringTagCompound(aStack, "mEntity", "mUuidUnique", mUuidUnique.toString()); + NBTUtils.createIntegerTagCompound(aStack, "mEntity", "mEntityHashcode", mEntityHashcode); + NBTUtils.createBooleanTagCompound(aStack, "mEntity", "mHasEntity", true); + return true; + } + + @Override + public Class getStoredEntityClass(ItemStack aStack) { + // TODO Auto-generated method stub + return null; + } + + + +} diff --git a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java index 817dc9807f..3f9db5a3e4 100644 --- a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java +++ b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java @@ -251,17 +251,15 @@ public class NBTUtils { } public static boolean hasKey(ItemStack stack, String key) { - if (stack.hasTagCompound()) { - final NBTTagCompound itemData = stack.getTagCompound(); - if (itemData.hasKey(key)) { - return true; - } + final NBTTagCompound itemData = getNBT(stack); + if (itemData.hasKey(key)) { + return true; } return false; } public static boolean createIntegerTagCompound(ItemStack rStack, String tagName, String keyName, int keyValue) { - final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagMain = getNBT(rStack); final NBTTagCompound tagNBT = new NBTTagCompound(); tagNBT.setInteger(keyName, keyValue); tagMain.setTag(tagName, tagNBT); @@ -270,7 +268,7 @@ public class NBTUtils { } public static boolean createLongTagCompound(ItemStack rStack, String tagName, String keyName, long keyValue) { - final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagMain = getNBT(rStack); final NBTTagCompound tagNBT = new NBTTagCompound(); tagNBT.setLong(keyName, keyValue); tagMain.setTag(tagName, tagNBT); @@ -279,7 +277,7 @@ public class NBTUtils { } public static boolean createStringTagCompound(ItemStack rStack, String tagName, String keyName, String keyValue) { - final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagMain = getNBT(rStack); final NBTTagCompound tagNBT = new NBTTagCompound(); tagNBT.setString(keyName, keyValue); tagMain.setTag(tagName, tagNBT); @@ -287,8 +285,43 @@ public class NBTUtils { return true; } + public static boolean createFloatTagCompound(ItemStack rStack, String tagName, String keyName, float keyValue) { + final NBTTagCompound tagMain = getNBT(rStack); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setFloat(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static boolean createDoubleTagCompound(ItemStack rStack, String tagName, String keyName, double keyValue) { + final NBTTagCompound tagMain = getNBT(rStack); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setDouble(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static boolean createBooleanTagCompound(ItemStack rStack, String tagName, String keyName, boolean keyValue) { + final NBTTagCompound tagMain = getNBT(rStack); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setBoolean(keyName, keyValue); + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static boolean createTagCompound(ItemStack rStack, String tagName, NBTTagCompound keyValue) { + final NBTTagCompound tagMain = getNBT(rStack); + NBTTagCompound tagNBT = keyValue; + tagMain.setTag(tagName, tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + public static int getIntegerTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = aStack.getTagCompound(); + NBTTagCompound aNBT = getNBT(aStack); if (aNBT != null) { aNBT = aNBT.getCompoundTag(tagName); if (aNBT != null) { @@ -299,7 +332,7 @@ public class NBTUtils { } public static long getLongTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = aStack.getTagCompound(); + NBTTagCompound aNBT = getNBT(aStack); if (aNBT != null) { aNBT = aNBT.getCompoundTag(tagName); if (aNBT != null) { @@ -310,7 +343,7 @@ public class NBTUtils { } public static String getStringTagCompound(ItemStack aStack, String tagName, String keyName) { - NBTTagCompound aNBT = aStack.getTagCompound(); + NBTTagCompound aNBT = getNBT(aStack); if (aNBT != null) { aNBT = aNBT.getCompoundTag(tagName); if (aNBT != null) { @@ -320,6 +353,50 @@ public class NBTUtils { return null; } + public static float getFloatTagCompound(ItemStack aStack, String tagName, String keyName) { + NBTTagCompound aNBT = getNBT(aStack); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getFloat(keyName); + } + } + return 0; + } + + public static double getDoubleTagCompound(ItemStack aStack, String tagName, String keyName) { + NBTTagCompound aNBT = getNBT(aStack); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getDouble(keyName); + } + } + return 0; + } + + public static boolean getBooleanTagCompound(ItemStack aStack, String tagName, String keyName) { + NBTTagCompound aNBT = getNBT(aStack); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT.getBoolean(keyName); + } + } + return false; + } + + public static NBTTagCompound getTagCompound(ItemStack aStack, String tagName) { + NBTTagCompound aNBT = getNBT(aStack); + if (aNBT != null && hasKey(aStack, tagName)) { + aNBT = aNBT.getCompoundTag(tagName); + if (aNBT != null) { + return aNBT; + } + } + return null; + } + public static boolean hasKeyInTagCompound(ItemStack stack, String tag, String key) { NBTTagCompound aNBT = stack.getTagCompound(); if (aNBT != null) { @@ -331,4 +408,47 @@ public class NBTUtils { return false; } + public static boolean tryCloneTagCompoundDataIntoSubTag(ItemStack aStack, NBTTagCompound aTagCompound) { + try { + NBTTagCompound aNBT = aTagCompound; + if (aNBT != null) { + if (!aNBT.hasNoTags()) { + Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap"); + if (mInternalMap != null) { + for (Map.Entry<?, ?> e : mInternalMap.entrySet()) { + Utils.LOG_INFO("Key: " + e.getKey().toString() + " | Value: " + e.getValue().toString()); + if (e.getValue().getClass() == String.class){ + createStringTagCompound(aStack, "mEntityTag", (String) e.getKey(), (String) e.getValue()); + } + else if (e.getValue().getClass() == Boolean.class || e.getValue().getClass() == boolean.class){ + createBooleanTagCompound(aStack, "mEntityTag", (String) e.getKey(), (boolean) e.getValue()); + } + else if (e.getValue().getClass() == Integer.class || e.getValue().getClass() == int.class){ + createIntegerTagCompound(aStack, "mEntityTag", (String) e.getKey(), (int) e.getValue()); + } + else if (e.getValue().getClass() == Double.class || e.getValue().getClass() == double.class){ + createDoubleTagCompound(aStack, "mEntityTag", (String) e.getKey(), (double) e.getValue()); + } + else if (e.getValue().getClass() == Long.class || e.getValue().getClass() == long.class){ + createLongTagCompound(aStack, "mEntityTag", (String) e.getKey(), (long) e.getValue()); + } + else if (e.getValue().getClass() == Float.class || e.getValue().getClass() == float.class){ + createFloatTagCompound(aStack, "mEntityTag", (String) e.getKey(), (float) e.getValue()); + } + else { + + + } + + } + return true; + } + } + } + return false; + } catch (Throwable t) { + return false; + } + } + } |