From 62b6fc8498d754ae388f92b933b656da5f38dee0 Mon Sep 17 00:00:00 2001 From: Maya <10861407+serenibyss@users.noreply.github.com> Date: Mon, 2 Dec 2024 08:12:05 -0600 Subject: Fix ME output hatch void protection again (#3594) --- .../multis/mega/MTEMegaDistillTower.java | 27 ++++++++++++++++++++++ .../gregtech/api/interfaces/fluid/IFluidStore.java | 7 ------ .../api/interfaces/tileentity/IVoidable.java | 7 ++++++ .../implementations/MTEMultiBlockBase.java | 18 +++++++++++++++ .../multiblock/base/Controller.java | 5 ++++ .../java/gregtech/api/util/OutputHatchWrapper.java | 5 ++-- .../gregtech/api/util/VoidProtectionHelper.java | 23 +++++++++++++++--- .../tileentities/machines/MTEHatchOutputME.java | 10 -------- .../machines/multi/MTEDistillationTower.java | 10 ++++++++ .../advanced/MTEAdvDistillationTower.java | 10 ++++++++ .../multi/production/MTENuclearReactor.java | 4 +--- 11 files changed, 100 insertions(+), 26 deletions(-) (limited to 'src/main') diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java index e98158ec7f..4c3199f33f 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MTEMegaDistillTower.java @@ -56,6 +56,7 @@ import gregtech.api.recipe.RecipeMaps; 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 implements ISurvivalConstructable { @@ -391,6 +392,32 @@ public class MTEMegaDistillTower extends MegaMultiBlockBase 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 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++) { diff --git a/src/main/java/gregtech/api/interfaces/fluid/IFluidStore.java b/src/main/java/gregtech/api/interfaces/fluid/IFluidStore.java index 5b5bb08c87..047cf4df5b 100644 --- a/src/main/java/gregtech/api/interfaces/fluid/IFluidStore.java +++ b/src/main/java/gregtech/api/interfaces/fluid/IFluidStore.java @@ -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(); - } } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java index f55d71debc..841fd07bba 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java @@ -79,4 +79,11 @@ public interface IVoidable { * 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(); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 2a5e3c1552..4a8f69fe9a 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -109,6 +109,7 @@ import gregtech.common.tileentities.machines.MTEHatchCraftingInputME; 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; @@ -1321,6 +1322,11 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity 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; @@ -2289,6 +2295,18 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity 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); diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java index c0fb6cedb4..d6b4ef7fe3 100644 --- a/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java @@ -914,6 +914,11 @@ public abstract class Controller, P extends MuTEProce return false; } + @Override + public boolean canDumpFluidToME() { + return false; + } + @Override public boolean supportsInputSeparation() { return true; diff --git a/src/main/java/gregtech/api/util/OutputHatchWrapper.java b/src/main/java/gregtech/api/util/OutputHatchWrapper.java index d570780317..5c3d64f938 100644 --- a/src/main/java/gregtech/api/util/OutputHatchWrapper.java +++ b/src/main/java/gregtech/api/util/OutputHatchWrapper.java @@ -63,8 +63,7 @@ public class OutputHatchWrapper implements IFluidStore { return outputHatch.canStoreFluid(fluidStack) && filter.test(fluidStack); } - @Override - public int getAvailableSpace() { - return outputHatch.getAvailableSpace(); + public MTEHatchOutput unwrap() { + return outputHatch; } } diff --git a/src/main/java/gregtech/api/util/VoidProtectionHelper.java b/src/main/java/gregtech/api/util/VoidProtectionHelper.java index 227601113b..97728d14fd 100644 --- a/src/main/java/gregtech/api/util/VoidProtectionHelper.java +++ b/src/main/java/gregtech/api/util/VoidProtectionHelper.java @@ -17,6 +17,7 @@ import gregtech.api.interfaces.fluid.IFluidStore; 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. @@ -214,7 +215,7 @@ public class VoidProtectionHelper { return; } } - if (protectExcessFluid && fluidOutputs.length > 0) { + if (protectExcessFluid && fluidOutputs.length > 0 && !machine.canDumpFluidToME()) { maxParallel = Math.min(calculateMaxFluidParallels(), maxParallel); if (maxParallel <= 0) { isFluidFull = true; @@ -255,7 +256,14 @@ public class VoidProtectionHelper { } 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; @@ -289,7 +297,16 @@ public class VoidProtectionHelper { ParallelStackInfo 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); diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchOutputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchOutputME.java index b502ad54d3..7ddf136a72 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchOutputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchOutputME.java @@ -160,16 +160,6 @@ public class MTEHatchOutputME extends MTEHatchOutput implements IPowerChannelSta 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.) * diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java index bbba029449..93b64c16a8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDistillationTower.java @@ -47,6 +47,7 @@ import gregtech.api.recipe.RecipeMap; 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 implements ISurvivalConstructable { @@ -292,6 +293,15 @@ public class MTEDistillationTower extends MTEEnhancedMultiBlockBase 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); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java index 81a8c12573..46a8d8fe3d 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/MTEAdvDistillationTower.java @@ -53,6 +53,7 @@ import gregtech.api.recipe.RecipeMaps; 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; @@ -434,6 +435,15 @@ public class MTEAdvDistillationTower extends GTPPMultiBlockBase tLayerOutputHatches.stream() + .anyMatch(tHatch -> (tHatch instanceof MTEHatchOutputME tMEHatch) && (tMEHatch.canAcceptFluid()))); + } + @Override public void setItemNBT(NBTTagCompound aNBT) { if (mUpgraded) aNBT.setBoolean("mUpgraded", true); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTENuclearReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTENuclearReactor.java index 9e902d666a..5be5801097 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTENuclearReactor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTENuclearReactor.java @@ -47,7 +47,6 @@ import gregtech.api.util.GTRecipe; 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; @@ -260,8 +259,7 @@ public class MTENuclearReactor extends GTPPMultiBlockBase imp 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); -- cgit