diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-09-12 11:19:33 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-09-12 11:19:33 +1000 |
commit | f91fdfd23342cb2b3d759fe2c317ab632352d0b5 (patch) | |
tree | 6b2b893886ce519ba782dfb960cdd5dc3538c79b /src/Java/gtPlusPlus/core/util/nbt | |
parent | 7721a5dd91d121a0921350572a45a1a39ee1ecfe (diff) | |
download | GT5-Unofficial-f91fdfd23342cb2b3d759fe2c317ab632352d0b5.tar.gz GT5-Unofficial-f91fdfd23342cb2b3d759fe2c317ab632352d0b5.tar.bz2 GT5-Unofficial-f91fdfd23342cb2b3d759fe2c317ab632352d0b5.zip |
+ Basic support for Project Table results within the large Auto-Crafter.
% More Project Table work.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/nbt')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java new file mode 100644 index 0000000000..010016d5f1 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java @@ -0,0 +1,75 @@ +package gtPlusPlus.core.util.nbt; + +import static gtPlusPlus.core.item.ModItems.ZZZ_Empty; + +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.util.item.ItemUtils; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class NBTUtils { + + public static NBTTagCompound getNBT(ItemStack aStack) { + NBTTagCompound rNBT = aStack.getTagCompound(); + return ((rNBT == null) ? new NBTTagCompound() : rNBT); + } + + public static void setBookTitle(ItemStack aStack, String aTitle) { + NBTTagCompound tNBT = getNBT(aStack); + tNBT.setString("title", aTitle); + GT_Utility.ItemNBT.setNBT(aStack, tNBT); + } + + public static String getBookTitle(ItemStack aStack) { + NBTTagCompound tNBT = getNBT(aStack); + return tNBT.getString("title"); + } + + public static ItemStack[] readItemsFromNBT(ItemStack itemstack){ + NBTTagCompound tNBT = getNBT(itemstack); + final NBTTagList list = tNBT.getTagList("Items", 10); + ItemStack inventory[] = new ItemStack[list.tagCount()]; + for(int i = 0;i<list.tagCount();i++){ + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("Slot"); + if((slot >= 0) && (slot < list.tagCount())){ + if (ItemStack.loadItemStackFromNBT(data) == ItemUtils.getSimpleStack(ZZZ_Empty)){ + inventory[slot] = null; + } + else { + inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + + } + } + return inventory; + } + + public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored){ + NBTTagCompound tNBT = getNBT(itemstack); + final NBTTagList list = new NBTTagList(); + for(int i = 0;i<stored.length;i++){ + final ItemStack stack = stored[i]; + if(stack != null){ + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + else { + final NBTTagCompound data = new NBTTagCompound(); + ItemStack nullstack = ItemUtils.getSimpleStack(ZZZ_Empty); + nullstack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + tNBT.setTag("Items", list); + itemstack.setTagCompound(tNBT); + return itemstack; + } + + +} |