Skip to content

Commit 5248e78

Browse files
committed
short circuit ejector component when nothing to eject
1 parent a72b8bd commit 5248e78

File tree

8 files changed

+60
-0
lines changed

8 files changed

+60
-0
lines changed

src/main/java/mekanism/common/capabilities/holder/ConfigHolder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public boolean canOutput() {
3333
return true;
3434
}
3535

36+
@Override
37+
public boolean isEmpty() {
38+
return false;
39+
}
40+
3641
@Override
3742
public int hashCode() {
3843
return 0;

src/main/java/mekanism/common/tile/component/TileComponentEjector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ private void outputItems(Direction facing, ConfigInfo info) {
275275
continue;
276276
}
277277
ISlotInfo slotInfo = info.getSlotInfo(dataType);
278+
if (slotInfo != null && slotInfo.isEmpty()) {
279+
continue;//don't even bother getting caps etc
280+
}
278281
if (slotInfo instanceof InventorySlotInfo inventorySlotInfo) {
279282
//Validate the slot info is of the correct type
280283
Set<Direction> outputs = getSidesForData(info, facing, dataType);

src/main/java/mekanism/common/tile/component/config/slot/ChemicalSlotInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ protected ChemicalSlotInfo(boolean canInput, boolean canOutput, List<TANK> tanks
3232
this.tanks = tanks;
3333
}
3434

35+
@Override
36+
public boolean isEmpty() {
37+
for (TANK tank : getTanks()) {
38+
if (!tank.isEmpty()) {
39+
return false;
40+
}
41+
}
42+
return true;
43+
}
44+
3545
public List<TANK> getTanks() {
3646
return tanks;
3747
}

src/main/java/mekanism/common/tile/component/config/slot/EnergySlotInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public EnergySlotInfo(boolean canInput, boolean canOutput, List<IEnergyContainer
1616
this.containers = containers;
1717
}
1818

19+
@Override
20+
public boolean isEmpty() {
21+
for (IEnergyContainer container : getContainers()) {
22+
if (!container.isEmpty()) {
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
1929
public List<IEnergyContainer> getContainers() {
2030
return containers;
2131
}

src/main/java/mekanism/common/tile/component/config/slot/FluidSlotInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ public FluidSlotInfo(boolean canInput, boolean canOutput, List<IExtendedFluidTan
1919
public List<IExtendedFluidTank> getTanks() {
2020
return tanks;
2121
}
22+
23+
@Override
24+
public boolean isEmpty() {
25+
for (IExtendedFluidTank tank : getTanks()) {
26+
if (!tank.isEmpty()) {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
2232
}

src/main/java/mekanism/common/tile/component/config/slot/HeatSlotInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public HeatSlotInfo(boolean canInput, boolean canOutput, List<IHeatCapacitor> ca
1616
this.capacitors = capacitors;
1717
}
1818

19+
@Override
20+
public boolean isEmpty() {
21+
return false;
22+
}
23+
1924
public List<IHeatCapacitor> getHeatCapacitors() {
2025
return capacitors;
2126
}

src/main/java/mekanism/common/tile/component/config/slot/ISlotInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ public interface ISlotInfo {
99
default boolean isEnabled() {
1010
return canInput() || canOutput();
1111
}
12+
13+
/**
14+
* Relevant to Output modes
15+
*
16+
* @return true if none of the slots contain anything to output, and ejecting can be skipped
17+
*/
18+
boolean isEmpty();
1219
}

src/main/java/mekanism/common/tile/component/config/slot/InventorySlotInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public List<IInventorySlot> getSlots() {
2424
return inventorySlots;
2525
}
2626

27+
@Override
28+
public boolean isEmpty() {
29+
for (IInventorySlot slot : getSlots()) {
30+
if (!slot.isEmpty()) {
31+
return false;
32+
}
33+
}
34+
return true;
35+
}
36+
2737
public boolean hasSlot(IInventorySlot slot) {
2838
return getSlots().contains(slot);
2939
}

0 commit comments

Comments
 (0)