Created
February 12, 2014 14:37
-
-
Save IamRob-/8956650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //Save data | |
| public void updateStackTagCompound(ItemStack itemStack, ItemStack[] values) { | |
| if (itemStack.stackTagCompound == null) { | |
| itemStack.setTagCompound(new NBTTagCompound()); | |
| } | |
| NBTTagList list = new NBTTagList(); | |
| for (int i = 0; i < values.length; i++) { | |
| ItemStack stack = values[i]; | |
| NBTTagCompound link = new NBTTagCompound(); | |
| if (stack != null) { | |
| System.out.println(stack.getItem().toString()); | |
| link.setInteger("itemno", stack.itemID); | |
| link.setInteger("meta", stack.getItemDamage()); | |
| link.setInteger("index", i); | |
| if (stack.stackTagCompound != null) { | |
| link.setTag("data", stack.stackTagCompound); | |
| } | |
| list.appendTag(link); | |
| } | |
| } | |
| itemStack.stackTagCompound.setTag("link_holder_inventory", list); | |
| } | |
| //load data | |
| public ItemStack[] readFromStackCompound(ItemStack itemstack) { | |
| if (itemstack.stackTagCompound == null) { | |
| System.out.println("Tag null"); | |
| return new ItemStack[InventoryLinkHolder.inventorySize]; | |
| } | |
| ItemStack[] items = new ItemStack[InventoryLinkHolder.inventorySize]; | |
| NBTTagList list = itemstack.stackTagCompound.getTagList("link_holder_inventory"); | |
| for (int i = 0; i < list.tagCount(); i++) { | |
| NBTTagCompound link = (NBTTagCompound) list.tagAt(i); | |
| int itemNo = link.getInteger("itemno"); | |
| int meta = link.getInteger("meta"); | |
| NBTTagCompound tag = link.getCompoundTag("data"); | |
| int index = link.getInteger("index"); | |
| if (itemNo != -1) { | |
| items[index] = new ItemStack(itemNo, 1, meta); | |
| System.out.println(items[index].toString()); | |
| items[index].setTagCompound(tag); | |
| } | |
| } | |
| System.out.println("Items returned" + list.tagCount()); | |
| return items; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment