Skip to content

Commit

Permalink
Fix ME output hatch void protection again
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 2, 2024
1 parent 48842f2 commit 28c9f8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,11 @@ protected static boolean dumpFluid(List<MTEHatchOutput> aOutputHatches, FluidSta
continue;
}
if (!tHatch.canStoreFluid(copiedFluidStack)) continue;

if (tHatch instanceof MTEHatchOutputME tMEHatch) {
if (!tMEHatch.canAcceptFluid()) continue;
}

int tAmount = tHatch.fill(copiedFluidStack, false);
if (tAmount >= copiedFluidStack.amount) {
boolean filled = tHatch.fill(copiedFluidStack, true) >= copiedFluidStack.amount;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/util/OutputHatchWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public boolean isEmptyAndAcceptsAnyFluid() {
public boolean canStoreFluid(@NotNull FluidStack fluidStack) {
return outputHatch.canStoreFluid(fluidStack) && filter.test(fluidStack);
}

public MTEHatchOutput unwrap() {
return outputHatch;
}
}
21 changes: 19 additions & 2 deletions src/main/java/gregtech/api/util/VoidProtectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import gregtech.api.interfaces.tileentity.IVoidable;
import gregtech.api.logic.FluidInventoryLogic;
import gregtech.api.logic.ItemInventoryLogic;
import gregtech.common.tileentities.machines.MTEHatchOutputME;

/**
* Helper class to calculate how many parallels of items / fluids can fit in the output buses / hatches.
Expand Down Expand Up @@ -255,7 +256,14 @@ private int calculateMaxFluidParallels() {
}

for (IFluidStore tHatch : hatches) {
int tSpaceLeft = tHatch.getCapacity() - tHatch.getFluidAmount();
int tSpaceLeft;
if (tHatch instanceof MTEHatchOutputME tMEHatch) {
tSpaceLeft = tMEHatch.canAcceptFluid() ? Integer.MAX_VALUE : 0;
} else if (tHatch instanceof OutputHatchWrapper w && w.unwrap() instanceof MTEHatchOutputME tMEHatch) {
tSpaceLeft = tMEHatch.canAcceptFluid() ? Integer.MAX_VALUE : 0;
} else {
tSpaceLeft = tHatch.getCapacity() - tHatch.getFluidAmount();
}

// check if hatch filled
if (tSpaceLeft <= 0) continue;
Expand Down Expand Up @@ -289,7 +297,16 @@ private int calculateMaxFluidParallels() {
ParallelStackInfo<FluidStack> tParallel = aParallelQueue.poll();
assert tParallel != null; // will always be true, specifying assert here to avoid IDE/compiler warnings
Integer tCraftSize = tFluidOutputMap.get(tParallel.stack);
int tSpaceLeft = tHatch.getCapacity();

int tSpaceLeft;
if (tHatch instanceof MTEHatchOutputME tMEHatch) {
tSpaceLeft = tMEHatch.canAcceptFluid() ? Integer.MAX_VALUE : 0;
} else if (tHatch instanceof OutputHatchWrapper w && w.unwrap() instanceof MTEHatchOutputME tMEHatch) {
tSpaceLeft = tMEHatch.canAcceptFluid() ? Integer.MAX_VALUE : 0;
} else {
tSpaceLeft = tHatch.getCapacity();
}

tParallel.batch += (tParallel.partial + tSpaceLeft) / tCraftSize;
tParallel.partial = (tParallel.partial + tSpaceLeft) % tCraftSize;
aParallelQueue.add(tParallel);
Expand Down

0 comments on commit 28c9f8e

Please sign in to comment.