Fixed energy storage lost during chunk loading on upgradeable blocks

This commit is contained in:
LemADEC 2016-07-14 19:17:25 +02:00
parent 488c1b04ca
commit ddc0cbfc32

View file

@ -83,7 +83,7 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
} }
public int getEnergyStored() { public int getEnergyStored() {
return energyStored_internal; return clamp(0, getMaxEnergyStored(), energyStored_internal);
} }
// Methods to override // Methods to override
@ -159,7 +159,7 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
* Override this to use custom storage or measure energy consumption statistics of this kind. * Override this to use custom storage or measure energy consumption statistics of this kind.
*/ */
public int consumeAllEnergy() { public int consumeAllEnergy() {
int temp = energyStored_internal; int temp = getEnergyStored();
energyStored_internal = 0; energyStored_internal = 0;
return temp; return temp;
} }
@ -250,7 +250,7 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
@Override @Override
@Optional.Method(modid = "IC2") @Optional.Method(modid = "IC2")
public double getDemandedEnergy() { public double getDemandedEnergy() {
return Math.max(0.0D, convertInternalToEU(getMaxEnergyStored() - energyStored_internal)); return Math.max(0.0D, convertInternalToEU(getMaxEnergyStored() - getEnergyStored()));
} }
@Override @Override
@ -337,7 +337,7 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
int toAdd_RF = Math.min(maxReceive_RF, maxStored_RF - energyStored_RF); int toAdd_RF = Math.min(maxReceive_RF, maxStored_RF - energyStored_RF);
if (!simulate) { if (!simulate) {
energyStored_internal = Math.min(getMaxEnergyStored(), energyStored_internal + convertRFtoInternal(toAdd_RF)); energyStored_internal = Math.min(getMaxEnergyStored(), getEnergyStored() + convertRFtoInternal(toAdd_RF));
} }
return toAdd_RF; return toAdd_RF;
@ -415,9 +415,6 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
public void readFromNBT(NBTTagCompound tag) { public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag); super.readFromNBT(tag);
energyStored_internal = tag.getInteger("energy"); energyStored_internal = tag.getInteger("energy");
if (energyStored_internal > getMaxEnergyStored()) {
energyStored_internal = getMaxEnergyStored();
}
if (tag.hasKey("upgrades")) { if (tag.hasKey("upgrades")) {
NBTTagCompound upgradeTag = tag.getCompoundTag("upgrades"); NBTTagCompound upgradeTag = tag.getCompoundTag("upgrades");
for (UpgradeType type : UpgradeType.values()) { for (UpgradeType type : UpgradeType.values()) {
@ -431,10 +428,7 @@ public abstract class TileEntityAbstractEnergy extends TileEntityAbstractInterfa
@Override @Override
public void writeToNBT(NBTTagCompound tag) { public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag); super.writeToNBT(tag);
if (energyStored_internal < 0) { tag.setInteger("energy", getEnergyStored());
energyStored_internal = 0;
}
tag.setInteger("energy", energyStored_internal);
if (!deprecated_upgrades.isEmpty()) { if (!deprecated_upgrades.isEmpty()) {
NBTTagCompound upgradeTag = new NBTTagCompound(); NBTTagCompound upgradeTag = new NBTTagCompound();
for (UpgradeType type : UpgradeType.values()) { for (UpgradeType type : UpgradeType.values()) {