Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ME output hatch void protection again #3594

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public boolean canDumpItemToME() {
return false;
}

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

@Override
public VoidingMode getDefaultVoidingMode() {
return VoidingMode.VOID_ALL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.MTEHatchOutputME;

public class MTEMegaDistillTower extends MegaMultiBlockBase<MTEMegaDistillTower> implements ISurvivalConstructable {

Expand Down Expand Up @@ -391,6 +392,32 @@ protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic().setMaxParallel(Configuration.Multiblocks.megaMachinesMax);
}

@Override
public boolean canDumpFluidToME() {

// All fluids can be dumped to ME only if each layer contains a ME Output Hatch.
for (List<MTEHatchOutput> tLayerOutputHatches : this.mOutputHatchesByLayer) {

boolean foundMEHatch = false;

for (IFluidStore tHatch : tLayerOutputHatches) {
if (tHatch instanceof MTEHatchOutputME tMEHatch) {
if (tMEHatch.canAcceptFluid()) {
foundMEHatch = true;
break;
}
}
}

// Exit if we didn't find a valid hatch on this layer.
if (!foundMEHatch) {
return false;
}
}

return true;
}

@Override
protected void addFluidOutputs(FluidStack[] outputFluids) {
for (int i = 0; i < outputFluids.length && i < this.mOutputHatchesByLayer.size(); i++) {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/gregtech/api/interfaces/fluid/IFluidStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ public interface IFluidStore extends IFluidTank {
* @return Whether to allow given fluid to be inserted into this.
*/
boolean canStoreFluid(@Nonnull FluidStack fluidStack);

/**
* @return The amount of fluid that can be stored in this.
*/
default int getAvailableSpace() {
return getCapacity() - getFluidAmount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ default int getFluidOutputLimit() {
* as this might be called every tick and cause lag.
*/
boolean canDumpItemToME();

/**
* @return If this machine has ability to dump fluid outputs to ME network.
* This doesn't need to check if it can actually dump to ME,
* as this might be called every tick and cause lag.
*/
boolean canDumpFluidToME();
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import gregtech.common.tileentities.machines.MTEHatchInputBusME;
import gregtech.common.tileentities.machines.MTEHatchInputME;
import gregtech.common.tileentities.machines.MTEHatchOutputBusME;
import gregtech.common.tileentities.machines.MTEHatchOutputME;
import gregtech.common.tileentities.machines.multi.MTELargeTurbine;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
Expand Down Expand Up @@ -1321,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 Expand Up @@ -2289,6 +2295,18 @@ public boolean canDumpItemToME() {
return false;
}

@Override
public boolean canDumpFluidToME() {
for (IFluidStore tHatch : getFluidOutputSlots(new FluidStack[0])) {
if (tHatch instanceof MTEHatchOutputME) {
if ((((MTEHatchOutputME) tHatch).canAcceptFluid())) {
return true;
}
}
}
return false;
}

@Override
public Pos2d getVoidingModeButtonPos() {
return new Pos2d(8, 91);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ public boolean canDumpItemToME() {
return false;
}

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

@Override
public boolean supportsInputSeparation() {
return true;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gregtech/api/util/OutputHatchWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public boolean canStoreFluid(@NotNull FluidStack fluidStack) {
return outputHatch.canStoreFluid(fluidStack) && filter.test(fluidStack);
}

@Override
public int getAvailableSpace() {
return outputHatch.getAvailableSpace();
public MTEHatchOutput unwrap() {
return outputHatch;
}
}
23 changes: 20 additions & 3 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 @@ -214,7 +215,7 @@ private void determineParallel() {
return;
}
}
if (protectExcessFluid && fluidOutputs.length > 0) {
if (protectExcessFluid && fluidOutputs.length > 0 && !machine.canDumpFluidToME()) {
maxParallel = Math.min(calculateMaxFluidParallels(), maxParallel);
if (maxParallel <= 0) {
isFluidFull = true;
Expand Down Expand Up @@ -255,7 +256,14 @@ private int calculateMaxFluidParallels() {
}

for (IFluidStore tHatch : hatches) {
int tSpaceLeft = tHatch.getAvailableSpace();
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.getAvailableSpace();

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
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ public boolean canAcceptFluid() {
return getCachedAmount() < getCacheCapacity();
}

/**
* Get the available fluid space, up to max int.
*/
@Override
public int getAvailableSpace() {
long availableSpace = getCacheCapacity() - getCachedAmount();
if (availableSpace > Integer.MAX_VALUE) availableSpace = Integer.MAX_VALUE;
return (int) availableSpace;
}

/**
* Attempt to store fluid in connected ME network. Returns how much fluid is accepted (if the network was down e.g.)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import gregtech.api.recipe.RecipeMaps;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.tileentities.machines.MTEHatchOutputME;

public class MTEDistillationTower extends MTEEnhancedMultiBlockBase<MTEDistillationTower>
implements ISurvivalConstructable {
Expand Down Expand Up @@ -292,6 +293,15 @@ protected void addFluidOutputs(FluidStack[] outputFluids) {
}
}

@Override
public boolean canDumpFluidToME() {
// All fluids can be dumped to ME only if each layer contains a ME Output Hatch.
return this.mOutputHatchesByLayer.stream()
.allMatch(
tLayerOutputHatches -> tLayerOutputHatches.stream()
.anyMatch(tHatch -> (tHatch instanceof MTEHatchOutputME tMEHatch) && (tMEHatch.canAcceptFluid())));
}

@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import gregtech.api.util.GTUtility;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.common.pollution.PollutionConfig;
import gregtech.common.tileentities.machines.MTEHatchOutputME;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList;
Expand Down Expand Up @@ -434,6 +435,15 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@Override
public boolean canDumpFluidToME() {
// All fluids can be dumped to ME only if each layer contains a ME Output Hatch.
return this.mOutputHatchesByLayer.stream()
.allMatch(
tLayerOutputHatches -> tLayerOutputHatches.stream()
.anyMatch(tHatch -> (tHatch instanceof MTEHatchOutputME tMEHatch) && (tMEHatch.canAcceptFluid())));
}

@Override
public void setItemNBT(NBTTagCompound aNBT) {
if (mUpgraded) aNBT.setBoolean("mUpgraded", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.OverclockCalculator;
import gregtech.api.util.shutdown.ShutDownReasonRegistry;
import gregtech.common.tileentities.machines.MTEHatchOutputME;
import gtPlusPlus.api.recipe.GTPPRecipeMaps;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.material.MaterialsElements;
Expand Down Expand Up @@ -260,8 +259,7 @@ public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBu
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
mCasing = 0;
if (checkPiece(mName, 3, 3, 0) && mCasing >= 27) {
if ((mOutputHatches.size() >= 3 || mOutputHatches.stream()
.anyMatch(h -> h instanceof MTEHatchOutputME)) && !mInputHatches.isEmpty()
if ((mOutputHatches.size() >= 3 || canDumpFluidToME()) && !mInputHatches.isEmpty()
&& mDynamoHatches.size() == 4
&& mMufflerHatches.size() == 4) {
this.turnCasingActive(false);
Expand Down
Loading