From 999f8c6d2947ee9b9da285b214ee3c01238dc9c0 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Tue, 6 Aug 2013 14:03:31 -0400 Subject: [PATCH] changed crate save format changed it to save directly from the itemstack too allow for NBT extra data on the stack though it shouldn't have any. --- .../common/machine/TileEntityCrate.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/minecraft/dark/assembly/common/machine/TileEntityCrate.java b/src/minecraft/dark/assembly/common/machine/TileEntityCrate.java index d815b6815..c0c60baa8 100644 --- a/src/minecraft/dark/assembly/common/machine/TileEntityCrate.java +++ b/src/minecraft/dark/assembly/common/machine/TileEntityCrate.java @@ -15,7 +15,6 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import dark.api.IExternalInv; -import dark.api.IInvBox; import dark.assembly.common.AssemblyLine; import dark.core.blocks.TileEntityInv; @@ -28,13 +27,13 @@ public class TileEntityCrate extends TileEntityInv implements IPacketReceiver, I public long prevClickTime = -1000; @Override - public IInvBox getInventory() + public InventoryCrate getInventory() { if (this.inventory == null) { inventory = new InventoryCrate(this); } - return this.inventory; + return (InventoryCrate) this.inventory; } @Override @@ -234,16 +233,24 @@ public class TileEntityCrate extends TileEntityInv implements IPacketReceiver, I public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); + /* Crate data */ + this.blockMetadata = nbt.getInteger("size"); + /* Load inventory old data if present */ this.getInventory().loadInv(nbt); - if (nbt.hasKey("Items")) + /* Load current two inv methods */ + ItemStack stack = null; + if (!nbt.hasKey("Items") && nbt.hasKey("itemID") && nbt.hasKey("itemMeta")) { - ItemStack stack = new ItemStack(nbt.getInteger("itemID"), nbt.getInteger("Count"), nbt.getInteger("itemMeta")); - this.blockMetadata = nbt.getInteger("size"); - if (stack != null && stack.itemID != 0 && stack.stackSize > 0) - { - this.sampleStack = stack; - this.getInventory().buildInventory(this.sampleStack); - } + stack = new ItemStack(nbt.getInteger("itemID"), nbt.getInteger("Count"), nbt.getInteger("itemMeta")); + } + else + { + stack = ItemStack.loadItemStackFromNBT(nbt); + } + if (stack != null && stack.itemID != 0 && stack.stackSize > 0) + { + this.sampleStack = stack; + this.getInventory().buildInventory(this.sampleStack); } } @@ -252,15 +259,16 @@ public class TileEntityCrate extends TileEntityInv implements IPacketReceiver, I public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); + /* Re-Build sample stack for saving */ this.buildSampleStack(false); - ItemStack stack = this.getSampleStack(); - nbt.setInteger("size", this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); - if (stack != null) + /* Save sample stack */ + if (this.getSampleStack() != null) { - nbt.setInteger("itemID", stack.itemID); - nbt.setInteger("itemMeta", stack.getItemDamage()); - nbt.setInteger("Count", stack.stackSize); + this.getSampleStack().writeToNBT(nbt); } + /* save metadata to improve loading conditions */ + nbt.setInteger("size", this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + } }