Fix #2504: Don't check energy capacity when reading NBT, but check after applying upgrades (#2507)

This commit is contained in:
Technici4n 2021-09-20 08:59:40 +02:00 committed by GitHub
parent f7e1ad1367
commit a5aa7acc83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -155,6 +155,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
((IUpgrade) stack.getItem()).process(this, this, stack); ((IUpgrade) stack.getItem()).process(this, this, stack);
} }
} }
afterUpgradesApplication();
} }
if (world == null || world.isClient) { if (world == null || world.isClient) {
return; return;
@ -175,6 +176,9 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
resetSpeedMulti(); resetSpeedMulti();
} }
protected void afterUpgradesApplication() {
}
public int getFacingInt() { public int getFacingInt() {
Block block = world.getBlockState(pos).getBlock(); Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockMachineBase) { if (block instanceof BlockMachineBase) {

View file

@ -346,7 +346,8 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
super.readNbt(tag); super.readNbt(tag);
NbtCompound data = tag.getCompound("PowerAcceptor"); NbtCompound data = tag.getCompound("PowerAcceptor");
if (shouldHandleEnergyNBT()) { if (shouldHandleEnergyNBT()) {
this.setStored(data.getLong("energy")); // Bypass the overfill check in setStored() because upgrades have not yet been applied.
this.energyContainer.amount = data.getLong("energy");
} }
} }
@ -367,6 +368,13 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
extraPowerInput = 0; extraPowerInput = 0;
} }
@Override
protected void afterUpgradesApplication() {
if (checkOverfill && getStored() > getMaxStoredPower()) {
setStored(getStored());
}
}
public long getStored() { public long getStored() {
return energyContainer.amount; return energyContainer.amount;
} }