Advertisement
Guest User

Untitled

a guest
Jun 4th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. @Override
  2. public NBTTagCompound writeToNBT(NBTTagCompound compound){
  3.     compound = super.writeToNBT(compound);
  4.  
  5.     NBTTagCompound items = new NBTTagCompound();
  6.     for(int i = 0; i < inventory.length; i++) {
  7.         ItemStack stack = inventory[i];
  8.         if(stack != null) {
  9.             compound.setTag("" + i, stack.writeToNBT(new NBTTagCompound()));
  10.         }
  11.     }
  12.     compound.setTag("items", items);
  13.  
  14.     return compound;
  15. }
  16.  
  17. @Override
  18. public void readFromNBT(NBTTagCompound compound){
  19.     super.readFromNBT(compound);
  20.  
  21.     NBTTagCompound items = compound.getCompoundTag("items");
  22.     for(int i = 0; i < inventory.length; i++){
  23.         inventory[i] = items.hasKey("" + i) ? ItemStack.loadItemStackFromNBT(items.getCompoundTag("" + i)) : null;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement