Skip to content

Commit c2ea3e4

Browse files
committed
Fix a few different machines showing that they are using energy when they are not actively doing so #7684. Also fix electric pumps not using energy as often as they are meant to
1 parent c9d8462 commit c2ea3e4

13 files changed

+82
-19
lines changed

src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void addGuiElements() {
4040
return energyContainer.getEnergyPerTick().greaterThan(energyContainer.getEnergy());
4141
});
4242
addRenderableWidget(new GuiVisualsTab(this, tile));
43-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
43+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive));
4444
int tileChunkX = SectionPos.blockToSectionCoord(tile.getBlockPos().getX());
4545
int tileChunkZ = SectionPos.blockToSectionCoord(tile.getBlockPos().getZ());
4646
for (int x = -TileEntityDimensionalStabilizer.MAX_LOAD_RADIUS; x <= TileEntityDimensionalStabilizer.MAX_LOAD_RADIUS; x++) {

src/main/java/mekanism/client/gui/GuiModificationStation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public GuiModificationStation(MekanismTileContainer<TileEntityModificationStatio
3434
protected void addGuiElements() {
3535
super.addGuiElements();
3636
addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 154, 40));
37-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
37+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::usedEnergy));
3838
addRenderableWidget(new GuiProgress(tile::getScaledProgress, ProgressType.LARGE_RIGHT, this, 65, 123));
3939
removeButton = addRenderableWidget(new TranslationButton(this, 34, 96, 108, 17, MekanismLang.BUTTON_REMOVE,
4040
() -> Mekanism.packetHandler().sendToServer(new PacketRemoveModule(tile.getBlockPos(), selectedModule.getData()))));

src/main/java/mekanism/client/gui/element/tab/GuiEnergyTab.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@ public GuiEnergyTab(IGuiWrapper gui, IInfoHandler handler) {
3333
infoHandler = handler;
3434
}
3535

36-
public GuiEnergyTab(IGuiWrapper gui, MachineEnergyContainer<?> energyContainer) {
37-
this(gui, () -> List.of(MekanismLang.USING.translate(EnergyDisplay.of(energyContainer.getEnergyPerTick())),
38-
MekanismLang.NEEDED.translate(EnergyDisplay.of(energyContainer.getNeeded()))));
39-
//TODO: Re-evaluate uses of this constructor at some point, as well as the isActive constructor
40-
}
41-
4236
public GuiEnergyTab(IGuiWrapper gui, MachineEnergyContainer<?> energyContainer, FloatingLongSupplier lastEnergyUsed) {
4337
this(gui, () -> List.of(MekanismLang.USING.translate(EnergyDisplay.of(lastEnergyUsed.get())),
4438
MekanismLang.NEEDED.translate(EnergyDisplay.of(energyContainer.getNeeded()))));
4539
}
4640

41+
//TODO: Re-evaluate uses of this constructor at some point
4742
public GuiEnergyTab(IGuiWrapper gui, MachineEnergyContainer<?> energyContainer, BooleanSupplier isActive) {
4843
this(gui, () -> {
4944
//Note: This isn't the most accurate using calculation as deactivation doesn't sync instantly

src/main/java/mekanism/client/gui/machine/GuiElectricPump.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected void addGuiElements() {
5353
addRenderableWidget(new GuiFluidGauge(() -> tile.fluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 6, 13))
5454
.warning(WarningType.NO_SPACE_IN_OUTPUT, () -> tile.fluidTank.getNeeded() < tile.estimateIncrementAmount());
5555
//TODO: Eventually we may want to consider showing a warning if the block under the pump is of the wrong type or there wasn't a valid spot to suck
56-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
56+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::usedEnergy));
5757
}
5858

5959
@Override

src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected void addGuiElements() {
5353
return energyContainer.getEnergyPerTick().greaterThan(energyContainer.getEnergy());
5454
});
5555
addRenderableWidget(new GuiFluidGauge(() -> tile.fluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 6, 13));
56-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
56+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::usedEnergy));
5757
}
5858

5959
@Override

src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import mekanism.client.gui.element.tab.GuiEnergyTab;
1414
import mekanism.common.Mekanism;
1515
import mekanism.common.MekanismLang;
16+
import mekanism.common.capabilities.energy.MachineEnergyContainer;
1617
import mekanism.common.inventory.container.slot.SlotOverlay;
1718
import mekanism.common.inventory.container.tile.MekanismTileContainer;
19+
import mekanism.common.inventory.warning.WarningTracker.WarningType;
1820
import mekanism.common.item.ItemCraftingFormula;
1921
import mekanism.common.network.to_server.PacketGuiInteract;
2022
import mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction;
@@ -45,11 +47,17 @@ public GuiFormulaicAssemblicator(MekanismTileContainer<TileEntityFormulaicAssemb
4547
@Override
4648
protected void addGuiElements() {
4749
super.addGuiElements();
48-
addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 159, 15));
50+
addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 159, 15)).warning(WarningType.NOT_ENOUGH_ENERGY, () -> {
51+
if (tile.getAutoMode() && tile.hasRecipe()) {
52+
MachineEnergyContainer<TileEntityFormulaicAssemblicator> energyContainer = tile.getEnergyContainer();
53+
return energyContainer.getEnergyPerTick().greaterThan(energyContainer.getEnergy());
54+
}
55+
return false;
56+
});
4957
//Overwrite the output slots with a "combined" slot
5058
addRenderableWidget(new GuiSlot(SlotType.OUTPUT_LARGE, this, 115, 16));
5159
addRenderableWidget(new GuiProgress(() -> tile.getOperatingTicks() / (double) tile.getTicksRequired(), ProgressType.TALL_RIGHT, this, 86, 43).jeiCrafting());
52-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
60+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::usedEnergy));
5361
encodeFormulaButton = addRenderableWidget(new MekanismImageButton(this, 7, 45, 14, getButtonLocation("encode_formula"),
5462
() -> Mekanism.packetHandler().sendToServer(new PacketGuiInteract(GuiInteraction.ENCODE_FORMULA, tile)), getOnHover(MekanismLang.ENCODE_FORMULA)));
5563
stockControlButton = addRenderableWidget(new MekanismImageButton(this, 26, 75, 16, getButtonLocation("stock_control"),

src/main/java/mekanism/client/gui/machine/GuiResistiveHeater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected void addGuiElements() {
4141
MekanismLang.RESISTIVE_HEATER_USAGE.translate(EnergyDisplay.of(tile.getEnergyContainer().getEnergyPerTick()))
4242
)).clearFormat());
4343
addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 164, 15));
44-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
44+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getEnergyUsed));
4545
addRenderableWidget(new GuiHeatTab(this, () -> {
4646
Component temp = MekanismUtils.getTemperatureDisplay(tile.getTotalTemperature(), TemperatureUnit.KELVIN, true);
4747
Component transfer = MekanismUtils.getTemperatureDisplay(tile.getLastTransferLoss(), TemperatureUnit.KELVIN, false);

src/main/java/mekanism/client/gui/machine/GuiSeismicVibrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void addGuiElements() {
3535
MachineEnergyContainer<TileEntitySeismicVibrator> energyContainer = tile.getEnergyContainer();
3636
return energyContainer.getEnergyPerTick().greaterThan(energyContainer.getEnergy());
3737
});
38-
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer()));
38+
addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive));
3939
}
4040

4141
@Override

src/main/java/mekanism/common/tile/TileEntityModificationStation.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import mekanism.api.RelativeSide;
99
import mekanism.api.gear.IModule;
1010
import mekanism.api.gear.ModuleData;
11+
import mekanism.api.math.FloatingLong;
1112
import mekanism.common.capabilities.Capabilities;
1213
import mekanism.common.capabilities.energy.MachineEnergyContainer;
1314
import mekanism.common.capabilities.holder.energy.EnergyContainerHelper;
@@ -22,6 +23,7 @@
2223
import mekanism.common.inventory.container.MekanismContainer;
2324
import mekanism.common.inventory.container.slot.ContainerSlotType;
2425
import mekanism.common.inventory.container.slot.SlotOverlay;
26+
import mekanism.common.inventory.container.sync.SyncableBoolean;
2527
import mekanism.common.inventory.container.sync.SyncableInt;
2628
import mekanism.common.inventory.slot.EnergyInventorySlot;
2729
import mekanism.common.inventory.slot.InputInventorySlot;
@@ -42,6 +44,7 @@ public class TileEntityModificationStation extends TileEntityMekanism implements
4244

4345
public int ticksRequired = BASE_TICKS_REQUIRED;
4446
public int operatingTicks;
47+
private boolean usedEnergy = false;
4548
@WrappingComputerMethod(wrapper = ComputerIInventorySlotWrapper.class, methodNames = "getEnergyItem")
4649
private EnergyInventorySlot energySlot;
4750
@WrappingComputerMethod(wrapper = ComputerIInventorySlotWrapper.class, methodNames = "getModuleItem")
@@ -84,6 +87,7 @@ protected IInventorySlotHolder getInitialInventory(IContentsListener listener) {
8487
protected void onUpdateServer() {
8588
super.onUpdateServer();
8689
energySlot.fillContainerOrConvert();
90+
FloatingLong clientEnergyUsed = FloatingLong.ZERO;
8791
if (MekanismUtils.canFunction(this)) {
8892
boolean operated = false;
8993
if (energyContainer.getEnergy().greaterOrEqual(energyContainer.getEnergyPerTick()) && !moduleSlot.isEmpty() && !containerSlot.isEmpty()) {
@@ -96,7 +100,7 @@ protected void onUpdateServer() {
96100
if (module == null || module.getInstalledCount() < data.getMaxStackSize()) {
97101
operated = true;
98102
operatingTicks++;
99-
energyContainer.extract(energyContainer.getEnergyPerTick(), Action.EXECUTE, AutomationType.INTERNAL);
103+
clientEnergyUsed = energyContainer.extract(energyContainer.getEnergyPerTick(), Action.EXECUTE, AutomationType.INTERNAL);
100104
if (operatingTicks == ticksRequired) {
101105
operatingTicks = 0;
102106
((IModuleContainerItem) stack.getItem()).addModule(stack, data);
@@ -110,6 +114,11 @@ protected void onUpdateServer() {
110114
operatingTicks = 0;
111115
}
112116
}
117+
usedEnergy = !clientEnergyUsed.isZero();
118+
}
119+
120+
public boolean usedEnergy() {
121+
return usedEnergy;
113122
}
114123

115124
public void removeModule(Player player, ModuleData<?> type) {
@@ -143,5 +152,6 @@ public void saveAdditional(@NotNull CompoundTag nbtTags) {
143152
public void addContainerTrackers(MekanismContainer container) {
144153
super.addContainerTrackers(container);
145154
container.track(SyncableInt.create(() -> operatingTicks, value -> operatingTicks = value));
155+
container.track(SyncableBoolean.create(this::usedEnergy, value -> usedEnergy = value));
146156
}
147157
}

src/main/java/mekanism/common/tile/machine/TileEntityElectricPump.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import mekanism.common.integration.computer.SpecialComputerMethodWrapper.ComputerIInventorySlotWrapper;
3333
import mekanism.common.integration.computer.annotation.ComputerMethod;
3434
import mekanism.common.integration.computer.annotation.WrappingComputerMethod;
35+
import mekanism.common.inventory.container.MekanismContainer;
36+
import mekanism.common.inventory.container.sync.SyncableBoolean;
3537
import mekanism.common.inventory.slot.EnergyInventorySlot;
3638
import mekanism.common.inventory.slot.FluidInventorySlot;
3739
import mekanism.common.inventory.slot.OutputInventorySlot;
@@ -91,6 +93,7 @@ public class TileEntityElectricPump extends TileEntityMekanism implements IConfi
9193
* How many ticks this machine has been operating for.
9294
*/
9395
public int operatingTicks;
96+
private boolean usedEnergy = false;
9497
/**
9598
* The nodes that have full sources near them or in them
9699
*/
@@ -141,20 +144,31 @@ protected void onUpdateServer() {
141144
super.onUpdateServer();
142145
energySlot.fillContainerOrConvert();
143146
inputSlot.drainTank(outputSlot);
147+
FloatingLong clientEnergyUsed = FloatingLong.ZERO;
144148
if (MekanismUtils.canFunction(this) && (fluidTank.isEmpty() || estimateIncrementAmount() <= fluidTank.getNeeded())) {
145149
FloatingLong energyPerTick = energyContainer.getEnergyPerTick();
146150
if (energyContainer.extract(energyPerTick, Action.SIMULATE, AutomationType.INTERNAL).equals(energyPerTick)) {
151+
if (!activeType.isEmpty()) {
152+
//If we have an active type of fluid, use energy. This can cause there to be ticks where there isn't actually
153+
// anything to suck that use energy, but those will balance out with the first set of ticks where it doesn't
154+
// use any energy until it actually picks up the first block
155+
clientEnergyUsed = energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
156+
}
147157
operatingTicks++;
148158
if (operatingTicks >= ticksRequired) {
149159
operatingTicks = 0;
150160
if (suck()) {
151-
energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
161+
if (clientEnergyUsed.isZero()) {
162+
//If it didn't already have an active type (hasn't used energy this tick), then extract energy
163+
clientEnergyUsed = energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
164+
}
152165
} else {
153166
reset();
154167
}
155168
}
156169
}
157170
}
171+
usedEnergy = !clientEnergyUsed.isZero();
158172
if (!fluidTank.isEmpty()) {
159173
FluidUtils.emit(Collections.singleton(Direction.UP), fluidTank, this, 256 * (1 + upgradeComponent.getUpgrades(Upgrade.SPEED)));
160174
}
@@ -351,6 +365,16 @@ public MachineEnergyContainer<TileEntityElectricPump> getEnergyContainer() {
351365
return energyContainer;
352366
}
353367

368+
public boolean usedEnergy() {
369+
return usedEnergy;
370+
}
371+
372+
@Override
373+
public void addContainerTrackers(MekanismContainer container) {
374+
super.addContainerTrackers(container);
375+
container.track(SyncableBoolean.create(this::usedEnergy, value -> usedEnergy = value));
376+
}
377+
354378
//Methods relating to IComputerTile
355379
@ComputerMethod(nameOverride = "reset")
356380
private void resetPump() throws ComputerException {

src/main/java/mekanism/common/tile/machine/TileEntityFluidicPlenisher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class TileEntityFluidicPlenisher extends TileEntityMekanism implements IC
7575
* How many ticks this machine has been operating for.
7676
*/
7777
public int operatingTicks;
78+
private boolean usedEnergy = false;
7879

7980
private MachineEnergyContainer<TileEntityFluidicPlenisher> energyContainer;
8081
@WrappingComputerMethod(wrapper = ComputerFluidTankWrapper.class, methodNames = {"getFluid", "getFluidCapacity", "getFluidNeeded", "getFluidFilledPercentage"})
@@ -127,11 +128,12 @@ protected void onUpdateServer() {
127128
super.onUpdateServer();
128129
energySlot.fillContainerOrConvert();
129130
inputSlot.fillTank(outputSlot);
131+
FloatingLong clientEnergyUsed = FloatingLong.ZERO;
130132
if (MekanismUtils.canFunction(this) && !fluidTank.isEmpty()) {
131133
FloatingLong energyPerTick = energyContainer.getEnergyPerTick();
132134
if (energyContainer.extract(energyPerTick, Action.SIMULATE, AutomationType.INTERNAL).equals(energyPerTick)) {
133135
if (!finishedCalc) {
134-
energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
136+
clientEnergyUsed = energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
135137
}
136138
operatingTicks++;
137139
if (operatingTicks >= ticksRequired) {
@@ -141,7 +143,7 @@ protected void onUpdateServer() {
141143
if (canReplace(below, false, false) && canExtractBucket() &&
142144
WorldUtils.tryPlaceContainedLiquid(null, level, below, fluidTank.getFluid(), null)) {
143145
level.gameEvent(null, GameEvent.FLUID_PLACE, below);
144-
energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
146+
clientEnergyUsed = energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
145147
fluidTank.extract(FluidType.BUCKET_VOLUME, Action.EXECUTE, AutomationType.INTERNAL);
146148
}
147149
} else {
@@ -150,6 +152,7 @@ protected void onUpdateServer() {
150152
}
151153
}
152154
}
155+
usedEnergy = !clientEnergyUsed.isZero();
153156
}
154157

155158
private boolean canExtractBucket() {
@@ -316,6 +319,11 @@ protected boolean makesComparatorDirty(@Nullable SubstanceType type) {
316319
public void addContainerTrackers(MekanismContainer container) {
317320
super.addContainerTrackers(container);
318321
container.track(SyncableBoolean.create(() -> finishedCalc, value -> finishedCalc = value));
322+
container.track(SyncableBoolean.create(this::usedEnergy, value -> usedEnergy = value));
323+
}
324+
325+
public boolean usedEnergy() {
326+
return usedEnergy;
319327
}
320328

321329
public MachineEnergyContainer<TileEntityFluidicPlenisher> getEnergyContainer() {

src/main/java/mekanism/common/tile/machine/TileEntityFormulaicAssemblicator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class TileEntityFormulaicAssemblicator extends TileEntityConfigurableMach
7777

7878
private int ticksRequired = BASE_TICKS_REQUIRED;
7979
private int operatingTicks;
80+
private boolean usedEnergy = false;
8081
private boolean autoMode = false;
8182
private boolean isRecipe = false;
8283
private boolean stockControl = false;
@@ -218,6 +219,7 @@ protected void onUpdateServer() {
218219
nextMode();
219220
}
220221

222+
FloatingLong clientEnergyUsed = FloatingLong.ZERO;
221223
if (autoMode && formula != null && ((getControlType() == RedstoneControl.PULSE && pulseOperations > 0) || MekanismUtils.canFunction(this))) {
222224
boolean canOperate = true;
223225
if (!isRecipe) {
@@ -235,7 +237,7 @@ protected void onUpdateServer() {
235237
} else {
236238
FloatingLong energyPerTick = energyContainer.getEnergyPerTick();
237239
if (energyContainer.extract(energyPerTick, Action.SIMULATE, AutomationType.INTERNAL).equals(energyPerTick)) {
238-
energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
240+
clientEnergyUsed = energyContainer.extract(energyPerTick, Action.EXECUTE, AutomationType.INTERNAL);
239241
operatingTicks++;
240242
}
241243
}
@@ -245,6 +247,7 @@ protected void onUpdateServer() {
245247
} else {
246248
operatingTicks = 0;
247249
}
250+
usedEnergy = !clientEnergyUsed.isZero();
248251
}
249252

250253
private void checkFormula() {
@@ -670,6 +673,10 @@ public MachineEnergyContainer<TileEntityFormulaicAssemblicator> getEnergyContain
670673
return energyContainer;
671674
}
672675

676+
public boolean usedEnergy() {
677+
return usedEnergy;
678+
}
679+
673680
@Override
674681
public void addContainerTrackers(MekanismContainer container) {
675682
super.addContainerTrackers(container);
@@ -678,6 +685,7 @@ public void addContainerTrackers(MekanismContainer container) {
678685
container.track(SyncableInt.create(this::getTicksRequired, value -> ticksRequired = value));
679686
container.track(SyncableBoolean.create(this::hasRecipe, value -> isRecipe = value));
680687
container.track(SyncableBoolean.create(this::getStockControl, value -> stockControl = value));
688+
container.track(SyncableBoolean.create(this::usedEnergy, value -> usedEnergy = value));
681689
container.track(SyncableBoolean.create(() -> formula != null, hasFormula -> {
682690
if (hasFormula) {
683691
if (formula == null && isRemote()) {

0 commit comments

Comments
 (0)