Skip to content

Commit

Permalink
short circuit ejector component when nothing to eject
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Aug 18, 2024
1 parent a72b8bd commit 5248e78
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public boolean canOutput() {
return true;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public int hashCode() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ private void outputItems(Direction facing, ConfigInfo info) {
continue;
}
ISlotInfo slotInfo = info.getSlotInfo(dataType);
if (slotInfo != null && slotInfo.isEmpty()) {
continue;//don't even bother getting caps etc
}
if (slotInfo instanceof InventorySlotInfo inventorySlotInfo) {
//Validate the slot info is of the correct type
Set<Direction> outputs = getSidesForData(info, facing, dataType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ protected ChemicalSlotInfo(boolean canInput, boolean canOutput, List<TANK> tanks
this.tanks = tanks;
}

@Override
public boolean isEmpty() {
for (TANK tank : getTanks()) {
if (!tank.isEmpty()) {
return false;
}
}
return true;
}

public List<TANK> getTanks() {
return tanks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public EnergySlotInfo(boolean canInput, boolean canOutput, List<IEnergyContainer
this.containers = containers;
}

@Override
public boolean isEmpty() {
for (IEnergyContainer container : getContainers()) {
if (!container.isEmpty()) {
return false;
}
}
return true;
}

public List<IEnergyContainer> getContainers() {
return containers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ public FluidSlotInfo(boolean canInput, boolean canOutput, List<IExtendedFluidTan
public List<IExtendedFluidTank> getTanks() {
return tanks;
}

@Override
public boolean isEmpty() {
for (IExtendedFluidTank tank : getTanks()) {
if (!tank.isEmpty()) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public HeatSlotInfo(boolean canInput, boolean canOutput, List<IHeatCapacitor> ca
this.capacitors = capacitors;
}

@Override
public boolean isEmpty() {
return false;
}

public List<IHeatCapacitor> getHeatCapacitors() {
return capacitors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ public interface ISlotInfo {
default boolean isEnabled() {
return canInput() || canOutput();
}

/**
* Relevant to Output modes
*
* @return true if none of the slots contain anything to output, and ejecting can be skipped
*/
boolean isEmpty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public List<IInventorySlot> getSlots() {
return inventorySlots;
}

@Override
public boolean isEmpty() {
for (IInventorySlot slot : getSlots()) {
if (!slot.isEmpty()) {
return false;
}
}
return true;
}

public boolean hasSlot(IInventorySlot slot) {
return getSlots().contains(slot);
}
Expand Down

0 comments on commit 5248e78

Please sign in to comment.