Skip to content

Commit

Permalink
Change TileInventory inventory saving so it can handle special saving…
Browse files Browse the repository at this point in the history
…/loading
  • Loading branch information
bonii-xx committed Apr 19, 2016
1 parent 3e49e5f commit 3114329
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main/java/slimeknights/mantle/tileentity/TileInventory.java
Expand Up @@ -206,15 +206,9 @@ public void closeInventory(EntityPlayer player) {
@Override
public void readFromNBT(NBTTagCompound tags) {
super.readFromNBT(tags);
readInventoryFromNBT(tags);
}

public void readInventoryFromNBT(NBTTagCompound tags) {
super.readFromNBT(tags);

this.resize(tags.getInteger("InventorySize"));

readInventoryFromNBT(this, tags);
readInventoryFromNBT(tags);

if(tags.hasKey("CustomName", 8)) {
this.inventoryTitle = tags.getString("CustomName");
Expand All @@ -227,15 +221,16 @@ public void writeToNBT(NBTTagCompound tags) {

tags.setInteger("InventorySize", inventory.length);

writeInventoryToNBT(this, tags);
writeInventoryToNBT(tags);

if(this.hasCustomName()) {
tags.setString("CustomName", this.inventoryTitle);
}
}

/** Writes the contents of the inventory to the tag */
public static void writeInventoryToNBT(IInventory inventory, NBTTagCompound tag) {
public void writeInventoryToNBT(NBTTagCompound tag) {
IInventory inventory = this;
NBTTagList nbttaglist = new NBTTagList();

for(int i = 0; i < inventory.getSizeInventory(); i++) {
Expand All @@ -251,7 +246,8 @@ public static void writeInventoryToNBT(IInventory inventory, NBTTagCompound tag)
}

/** Reads a an inventory from the tag. Overwrites current content */
public static void readInventoryFromNBT(IInventory inventory, NBTTagCompound tag) {
public void readInventoryFromNBT(NBTTagCompound tag) {
IInventory inventory = this;
NBTTagList nbttaglist = tag.getTagList("Items", 10);

for(int i = 0; i < nbttaglist.tagCount(); ++i) {
Expand Down

0 comments on commit 3114329

Please sign in to comment.