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);
}
}
afterUpgradesApplication();
}
if (world == null || world.isClient) {
return;
@ -175,6 +176,9 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
resetSpeedMulti();
}
protected void afterUpgradesApplication() {
}
public int getFacingInt() {
Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockMachineBase) {

View file

@ -346,7 +346,8 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
super.readNbt(tag);
NbtCompound data = tag.getCompound("PowerAcceptor");
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;
}
@Override
protected void afterUpgradesApplication() {
if (checkOverfill && getStored() > getMaxStoredPower()) {
setStored(getStored());
}
}
public long getStored() {
return energyContainer.amount;
}