Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- NBTTagList list = new NBTTagList();
- for (int i = 0; i < getSizeInventory(); i++){
- if (getStackInSlot(i) != null) {
- NBTTagCompound stackTag = new NBTTagCompound();
- stackTag.setByte("Slot", (byte) i);
- getStackInSlot(i).writeToNBT(stackTag);
- list.appendTag(list);
- }
- }
- compound.setTag("Items", list);
- if (hasCustomName()) {
- compound.setString("Custom Name", getCustomName());
- }
- }
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- NBTTagList list = compound.getTagList("Items", 10);
- for (int i = 0; i < list.tagCount(); i++){
- NBTTagCompound stackTag = list.getCompoundTagAt(i);
- int slot = stackTag.getByte("Slot") & 255;
- setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
- }
- if (compound.hasKey("Custom Name", 8)) {
- setCustomName(compound.getString("Custom Name"));
- }
- }
Add Comment
Please, Sign In to add comment