Fixed bug where saving stuff to NBT would result an overflow

This commit is contained in:
HbmMods 2016-04-07 23:20:01 +02:00
parent b80861f398
commit b04d194eeb
3 changed files with 34 additions and 26 deletions

View File

@ -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)

View File

@ -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++)

View File

@ -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++)