From b04d194eeb345d1d88113bbd507f995ae2fb6b60 Mon Sep 17 00:00:00 2001 From: HbmMods Date: Thu, 7 Apr 2016 23:20:01 +0200 Subject: [PATCH] Fixed bug where saving stuff to NBT would result an overflow --- .../blocks/TileEntityFusionMultiblock.java | 26 ++++++++++++------- .../blocks/TileEntityMachineGenerator.java | 16 ++++++------ .../blocks/TileEntityReactorMultiblock.java | 18 ++++++------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/com/hbm/blocks/TileEntityFusionMultiblock.java b/com/hbm/blocks/TileEntityFusionMultiblock.java index c11fb7ffc..6c2030c15 100644 --- a/com/hbm/blocks/TileEntityFusionMultiblock.java +++ b/com/hbm/blocks/TileEntityFusionMultiblock.java @@ -153,6 +153,11 @@ public class TileEntityFusionMultiblock extends TileEntity implements ISidedInve public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("items", 10); + + water = nbt.getShort("water") * 1000; + deut = nbt.getShort("deut") * 1000; + power = nbt.getShort("power") * 1000; + trit = nbt.getShort("trit") * 1000; slots = new ItemStack[getSizeInventory()]; @@ -165,20 +170,15 @@ public class TileEntityFusionMultiblock extends TileEntity implements ISidedInve slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); } } - - water = nbt.getShort("water"); - deut = nbt.getShort("deut"); - power = nbt.getShort("power"); - trit = nbt.getShort("trit"); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setShort("water", (short) water); - nbt.setShort("deut", (short) deut); - nbt.setShort("power", (short) power); - nbt.setShort("trit", (short) trit); + nbt.setShort("water", (short) (water/1000)); + nbt.setShort("deut", (short) (deut/1000)); + nbt.setShort("power", (short) (power/1000)); + nbt.setShort("trit", (short) (trit/1000)); NBTTagList list = new NBTTagList(); for(int i = 0; i < slots.length; i++) @@ -1018,11 +1018,19 @@ public class TileEntityFusionMultiblock extends TileEntity implements ISidedInve { this.slots[2].stackSize--; this.deut += 1000000; + if(this.slots[2].stackSize == 0) + { + this.slots[2] = null; + } } if(slots[3] != null && slots[3].getItem() == ModItems.cell_tritium && this.trit + 1000000 <= tritMax) { this.slots[3].stackSize--; this.trit += 1000000; + if(this.slots[3].stackSize == 0) + { + this.slots[3] = null; + } } if(slots[0] != null && slots[0].getItem() == ModItems.inf_water) diff --git a/com/hbm/blocks/TileEntityMachineGenerator.java b/com/hbm/blocks/TileEntityMachineGenerator.java index ff3cbe9b4..5e4208ebd 100644 --- a/com/hbm/blocks/TileEntityMachineGenerator.java +++ b/com/hbm/blocks/TileEntityMachineGenerator.java @@ -147,10 +147,10 @@ public class TileEntityMachineGenerator extends TileEntity implements ISidedInve super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("items", 10); - water = nbt.getShort("water"); - cool = nbt.getShort("cool"); - power = nbt.getShort("power"); - heat = nbt.getShort("heat"); + water = nbt.getShort("water") * 100; + cool = nbt.getShort("cool") * 100; + power = nbt.getShort("power") * 100; + heat = nbt.getShort("heat") * 100; slots = new ItemStack[getSizeInventory()]; for(int i = 0; i < list.tagCount(); i++) @@ -167,10 +167,10 @@ public class TileEntityMachineGenerator extends TileEntity implements ISidedInve @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setShort("water", (short) water); - nbt.setShort("cool", (short) cool); - nbt.setShort("power", (short) power); - nbt.setShort("heat", (short) heat); + nbt.setShort("water", (short) (water/100)); + nbt.setShort("cool", (short) (cool/100)); + nbt.setShort("power", (short) (power/100)); + nbt.setShort("heat", (short) (heat/100)); NBTTagList list = new NBTTagList(); for(int i = 0; i < slots.length; i++) diff --git a/com/hbm/blocks/TileEntityReactorMultiblock.java b/com/hbm/blocks/TileEntityReactorMultiblock.java index e0a44665c..4b6a65ef1 100644 --- a/com/hbm/blocks/TileEntityReactorMultiblock.java +++ b/com/hbm/blocks/TileEntityReactorMultiblock.java @@ -173,6 +173,11 @@ public class TileEntityReactorMultiblock extends TileEntity implements ISidedInv public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("items", 10); + + water = nbt.getShort("water") * 1000; + cool = nbt.getShort("cool") * 1000; + power = nbt.getShort("power") * 100; + heat = nbt.getShort("heat") * 100; slots = new ItemStack[getSizeInventory()]; @@ -185,20 +190,15 @@ public class TileEntityReactorMultiblock extends TileEntity implements ISidedInv slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); } } - - water = nbt.getShort("water"); - cool = nbt.getShort("cool"); - power = nbt.getShort("power"); - heat = nbt.getShort("heat"); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setShort("water", (short) water); - nbt.setShort("cool", (short) cool); - nbt.setShort("power", (short) power); - nbt.setShort("heat", (short) heat); + nbt.setShort("water", (short) (water/1000)); + nbt.setShort("cool", (short) (cool/1000)); + nbt.setShort("power", (short) (power/100)); + nbt.setShort("heat", (short) (heat/100)); NBTTagList list = new NBTTagList(); for(int i = 0; i < slots.length; i++)