Guest User

Untitled

a guest
May 15th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. @Override
  2. public void writeToNBT(NBTTagCompound compound) {
  3. super.writeToNBT(compound);
  4.  
  5. NBTTagList list = new NBTTagList();
  6. for (int i = 0; i < getSizeInventory(); i++){
  7. if (getStackInSlot(i) != null) {
  8. NBTTagCompound stackTag = new NBTTagCompound();
  9. stackTag.setByte("Slot", (byte) i);
  10. getStackInSlot(i).writeToNBT(stackTag);
  11. list.appendTag(list);
  12. }
  13. }
  14. compound.setTag("Items", list);
  15.  
  16. if (hasCustomName()) {
  17. compound.setString("Custom Name", getCustomName());
  18. }
  19. }
  20.  
  21. @Override
  22. public void readFromNBT(NBTTagCompound compound) {
  23. super.readFromNBT(compound);
  24. NBTTagList list = compound.getTagList("Items", 10);
  25. for (int i = 0; i < list.tagCount(); i++){
  26. NBTTagCompound stackTag = list.getCompoundTagAt(i);
  27. int slot = stackTag.getByte("Slot") & 255;
  28. setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
  29. }
  30.  
  31. if (compound.hasKey("Custom Name", 8)) {
  32. setCustomName(compound.getString("Custom Name"));
  33. }
  34. }
Add Comment
Please, Sign In to add comment