mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 11:29:23 +01:00
Fix energy storage
This commit is contained in:
parent
e870e5c48b
commit
8fd600dc86
22 changed files with 46 additions and 24 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LiquidFuelRecipe> recipeHolder = tile.getRecipeForCurrentFluid();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue