diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java index d0e22aa505b..a5f427f6039 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java @@ -193,6 +193,12 @@ public void onPlacement() { rebuildNetwork(); } + @Override + public void onLoad() { + calculateEnergyUsage(); + super.onLoad(); + } + // Used when this controller is initially placed. Try to find all possible // storage instances that are connected and within our distance radius // todo rework this to use neighbor cache somehow @@ -237,16 +243,6 @@ public void rebuildNetwork() { oldInstances.remove(pos); oldPositions.remove(pos); - energyConsumption += switch (storage.getType()) { - case ITEM, FLUID -> { - int tier = storage instanceof ITieredMetaTileEntity tieredMTE ? tieredMTE.getTier() : 1; - yield GTValues.V[tier] / 2; - } - case PROXY -> 2L; - case EXTENDER -> 1L; - default -> 0L; - }; - // check against already check posses so we don't recheck a checked pos for (EnumFacing facing : EnumFacing.VALUES) { BlockPos offsetPos = pos.offset(facing); @@ -278,11 +274,29 @@ public void rebuildNetwork() { if (storage != null) storage.setDisconnected(); } handler.rebuildCache(); + calculateEnergyUsage(); energyContainer.setMaxCapacity(energyConsumption * 16L); - writeCustomData(GregtechDataCodes.UPDATE_ENERGY_PER, buf -> buf.writeLong(energyConsumption)); markDirty(); } + private void calculateEnergyUsage() { + for (var pos : storagePositions) { + var storage = getStorage(pos, false); + if (storage == null) continue; + + energyConsumption += switch (storage.getType()) { + case ITEM, FLUID -> { + int tier = storage instanceof ITieredMetaTileEntity tieredMTE ? tieredMTE.getTier() : 1; + yield tier > 4 ? 256L : 16L; + } + case PROXY -> 8L; + case EXTENDER -> 2L; + default -> 0L; + }; + } + writeCustomData(GregtechDataCodes.UPDATE_ENERGY_PER, buf -> buf.writeLong(energyConsumption)); + } + private void reinitializeEnergyContainer() { energyContainer = new QuantumControllerEnergyContainer(this); } @@ -309,7 +323,6 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) { list.appendTag(new NBTTagLong(pos.toLong())); } tagCompound.setTag("StorageInstances", list); - tagCompound.setLong("EnergyConsumption", energyConsumption); return tagCompound; } @@ -320,7 +333,6 @@ public void readFromNBT(NBTTagCompound data) { for (int i = 0; i < list.tagCount(); i++) { storagePositions.add(BlockPos.fromLong(((NBTTagLong) list.get(i)).getLong())); } - energyConsumption = data.getLong("EnergyConsumption"); } @SuppressWarnings("unchecked")