diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java index cd166edd9..c25280622 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockShockSuppressor.java @@ -72,7 +72,7 @@ public class BlockShockSuppressor extends Block implements EntityBlock { for (BlockPos pos : posesToRemove) { if (suppressor.storage.getEnergyStored() >= use) { - suppressor.storage.extractEnergy(use, false); + suppressor.storage.extractEnergyInternal(use, false); affectedBlocks.remove(pos); } else { break; @@ -80,7 +80,7 @@ public class BlockShockSuppressor extends Block implements EntityBlock { } for (Entity entity : entitiesToRemove) { if (suppressor.storage.getEnergyStored() >= use) { - suppressor.storage.extractEnergy(use, false); + suppressor.storage.extractEnergyInternal(use, false); affectedEntities.remove(entity); } else { break; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java index 3f3090016..c6b782224 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Mth; import net.neoforged.neoforge.energy.EnergyStorage; public class CustomEnergyStorage extends EnergyStorage { @@ -32,6 +33,26 @@ public class CustomEnergyStorage extends EnergyStorage { return super.extractEnergy(maxExtract, simulate); } + public int extractEnergyInternal(int maxExtract, boolean simulate) { + int before = this.maxExtract; + this.maxExtract = Integer.MAX_VALUE; + + int toReturn = this.extractEnergy(maxExtract, simulate); + + this.maxExtract = before; + return toReturn; + } + + public int receiveEnergyInternal(int maxReceive, boolean simulate) { + int before = this.maxReceive; + this.maxReceive = Integer.MAX_VALUE; + + int toReturn = this.receiveEnergy(maxReceive, simulate); + + this.maxReceive = before; + return toReturn; + } + public boolean isDirty() { return dirty; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 4d4976e54..10ab8b1a2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -185,7 +185,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple @Override public void extractEnergy(int amount) { - this.storage.extractEnergy(amount, false); + this.storage.extractEnergyInternal(amount, false); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java index c4fb616f8..49cdd8cfa 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java @@ -116,7 +116,7 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements Men } } else { tile.burnTime--; - tile.storage.receiveEnergy(tile.producePerTick, false); + tile.storage.receiveEnergyInternal(tile.producePerTick, false); } if ((tile.lastBurnTime != tile.burnTime || tile.lastProducePerTick != tile.producePerTick) && tile.sendUpdateWithInterval()) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java index 491be2045..95a521474 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java @@ -108,7 +108,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements Me if ((FluidStack.isSameFluid(r.getOutput(), tile.tank.getFluid()) || tile.tank.isEmpty()) && r.getOutput().getAmount() <= tile.tank.getCapacity() - tile.tank.getFluidAmount()) { if (tile.storage.getEnergyStored() >= ENERGY_USE) { tile.currentProcessTime++; - tile.storage.extractEnergy(ENERGY_USE, false); + tile.storage.extractEnergyInternal(ENERGY_USE, false); if (tile.currentProcessTime >= TIME) { tile.currentProcessTime = 0; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java index a1cd3a3f1..a7feab55b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe; import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoalGenerator; @@ -108,7 +109,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements tile.currentBurnTime--; int produce = tile.currentRecipe.value().getTotalEnergy() / tile.currentRecipe.value().getBurnTime(); if (produce > 0) { - tile.storage.receiveEnergy(produce, false); + tile.storage.receiveEnergyInternal(produce, false); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java index f7e86320e..a3359886a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java @@ -189,7 +189,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements } this.brewTime++; - this.storage.extractEnergy(ENERGY_USED, false); + this.storage.extractEnergyInternal(ENERGY_USED, false); if (this.brewTime >= TIME_USED) { this.brewTime = 0; ItemStack output = new ItemStack(ActuallyItems.COFFEE_CUP.get()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java index 9aad60b18..d8f5e6049 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java @@ -131,7 +131,7 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto finishCrushing(SLOT_INPUT_1, SLOT_OUTPUT_1_1, SLOT_OUTPUT_1_2); firstCrushTime = 0; } - storage.extractEnergy(ENERGY_USE, false); + storage.extractEnergyInternal(ENERGY_USE, false); } crushed = storage.getEnergyStored() >= ENERGY_USE; } else { @@ -149,7 +149,7 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto finishCrushing(SLOT_INPUT_2, SLOT_OUTPUT_2_1, SLOT_OUTPUT_2_2); secondCrushTime = 0; } - storage.extractEnergy(ENERGY_USE, false); + storage.extractEnergyInternal(ENERGY_USE, false); } crushed = storage.getEnergyStored() >= ENERGY_USE; } else { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java index a205941b3..270f0b1e7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -51,7 +51,7 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I int energy = item.getUsePerTick(tile.inv.getStackInSlot(0), tile, tile.ticksElapsed); if (tile.storage.getEnergyStored() >= energy) { if (item.update(tile.inv.getStackInSlot(0), tile, tile.ticksElapsed)) { - tile.storage.extractEnergy(energy, false); + tile.storage.extractEnergyInternal(energy, false); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java index 001194122..cdc584d61 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java @@ -96,7 +96,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase { boolean done = tile.processTime >= recipe.getTime(); for (TileEntityDisplayStand stand : stands) { - stand.storage.extractEnergy(recipe.getEnergyPerStand() / recipe.getTime(), false); + stand.storage.extractEnergyInternal(recipe.getEnergyPerStand() / recipe.getTime(), false); if (done) { stand.inv.getStackInSlot(0).shrink(1); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java index f100573df..19ced761b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java @@ -74,7 +74,7 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements Menu boolean canTakeUp = capability.map(cap -> cap.getEnergyStored() >= cap.getMaxEnergyStored()).orElse(false); if (received > 0) { - tile.storage.extractEnergy(received, false); + tile.storage.extractEnergyInternal(received, false); } if (canTakeUp) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java index 49007be5f..b694f864e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java @@ -72,7 +72,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha boolean canTakeUp = capability.map(cap -> cap.getEnergyStored() <= 0).orElse(false); if (extracted > 0) { - tile.storage.receiveEnergy(extracted, false); + tile.storage.receiveEnergyInternal(extracted, false); } if (canTakeUp) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index 6bbc8f05c..d2b06db55 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -213,7 +213,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer @Override public void extractEnergy(int amount) { - this.storage.extractEnergy(amount, false); + this.storage.extractEnergyInternal(amount, false); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java index f4bdefb4a..aa65d8c3b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java @@ -259,7 +259,7 @@ public class TileEntityFireworkBox extends TileEntityBase implements IEnergyDisp if (this.storage.getEnergyStored() >= USE_PER_SHOT) { this.spawnFireworks(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()); - this.storage.extractEnergy(USE_PER_SHOT, false); + this.storage.extractEnergyInternal(USE_PER_SHOT, false); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java index 7b5bad33d..079311ef3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -81,7 +81,7 @@ public class TileEntityHeatCollector extends TileEntityBase implements ISharingE } if (blocksAround.size() >= BLOCKS_NEEDED) { - tile.storage.receiveEnergy(ENERGY_PRODUCE, false); + tile.storage.receiveEnergyInternal(ENERGY_PRODUCE, false); tile.setChanged(); tile.disappearTime++; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java index 83dcf1d4e..eebd636db 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java @@ -71,7 +71,7 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I if (tile.currentWorkTime >= 200) { tile.currentWorkTime = 0; level.setBlock(tile.worldPosition.above(), Blocks.LAVA.defaultBlockState(), 2); - tile.storage.extractEnergy(ENERGY_USE, false); + tile.storage.extractEnergyInternal(ENERGY_USE, false); } } else { tile.currentWorkTime = 0; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 55fd54ef1..e9cdc4ca9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -87,7 +87,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE level.setBlockAndUpdate(theCoord, Blocks.AIR.defaultBlockState()); - tile.storage.receiveEnergy(energyProduced, false); + tile.storage.receiveEnergyInternal(energyProduced, false); AssetUtil.spawnLaserWithTimeServer((ServerLevel) level, pos.getX(), pos.getY(), pos.getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), 0x3EA34A, 25, 0, 0.075F, 0.8F); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java index 16ddd678c..3f99c9532 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java @@ -111,7 +111,7 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen this.level.levelEvent(2001, coordsBlock, Block.getId(this.level.getBlockState(coordsBlock))); this.level.setBlockAndUpdate(coordsBlock, Blocks.AIR.defaultBlockState()); StackUtil.addAll(this.inv, drops, false); - this.storage.extractEnergy(ENERGY_USE, false); + this.storage.extractEnergyInternal(ENERGY_USE, false); this.setChanged(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index c840a1cde..72e321177 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -132,7 +132,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn if (tile.currentBurnTime > 0 && tile.currentEnergyProduce > 0) { tile.currentBurnTime--; - tile.storage.receiveEnergy(tile.currentEnergyProduce, false); + tile.storage.receiveEnergyInternal(tile.currentEnergyProduce, false); } else if (!tile.isRedstonePowered) { RecipeHolder recipeHolder = tile.getRecipeForCurrentFluid(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java index c3bbc879e..c89804c9c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -96,7 +96,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy int received = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM)) .map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); if (received > 0) { - tile.storage.extractEnergy(received, false); + tile.storage.extractEnergyInternal(received, false); } } } else { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java index ef871fefa..fc21a5406 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java @@ -141,7 +141,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements tile.finishBurning(SLOT_INPUT_1, SLOT_OUTPUT_1); tile.firstSmeltTime = 0; } - tile.storage.extractEnergy(ENERGY_USE, false); + tile.storage.extractEnergyInternal(ENERGY_USE, false); } smelted = true; } else { @@ -155,7 +155,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements tile.finishBurning(SLOT_INPUT_2, SLOT_OUTPUT_2); tile.secondSmeltTime = 0; } - tile.storage.extractEnergy(ENERGY_USE, false); + tile.storage.extractEnergyInternal(ENERGY_USE, false); } smelted = true; } else { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java index 48b899c37..4248d72e7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java @@ -156,7 +156,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements StackUtil.addAll(this.inv, drops, false); this.setChanged(); - this.storage.extractEnergy(actualUse, false); + this.storage.extractEnergyInternal(actualUse, false); this.shootParticles(pos.getX(), pos.getY(), pos.getZ()); } else { return false;