Skip to content

Commit

Permalink
Revert "Fix ME Output Hatch void protection checks (#3585)"
Browse files Browse the repository at this point in the history
This reverts commit fd1becc.
  • Loading branch information
serenibyss committed Dec 2, 2024
1 parent 8380ef6 commit 48842f2
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 28 deletions.
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 @@ -2289,6 +2290,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: 0 additions & 5 deletions src/main/java/gregtech/api/util/OutputHatchWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,4 @@ public boolean isEmptyAndAcceptsAnyFluid() {
public boolean canStoreFluid(@NotNull FluidStack fluidStack) {
return outputHatch.canStoreFluid(fluidStack) && filter.test(fluidStack);
}

@Override
public int getAvailableSpace() {
return outputHatch.getAvailableSpace();
}
}
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/util/VoidProtectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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 +255,7 @@ private int calculateMaxFluidParallels() {
}

for (IFluidStore tHatch : hatches) {
int tSpaceLeft = tHatch.getAvailableSpace();
int tSpaceLeft = tHatch.getCapacity() - tHatch.getFluidAmount();

// check if hatch filled
if (tSpaceLeft <= 0) continue;
Expand Down Expand Up @@ -289,7 +289,7 @@ 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 = 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

0 comments on commit 48842f2

Please sign in to comment.