From 68d6a0669f0fbd302309cdd053879862a8e7d31b Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:08:51 -0700 Subject: [PATCH] fix hard mui2 dep update to ceu 2.8.10 --- dependencies.gradle | 2 +- .../MetaTileEntityLargeDistillery.java | 124 +++++------------- 2 files changed, 37 insertions(+), 89 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index c5bdc02..9abf257 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -38,5 +38,5 @@ * For more details, see https://docs.gradle.org/8.4/userguide/java_library_plugin.html#sec:java_library_configurations_graph */ dependencies { - api("gregtech:gregtech:2.8.9-beta") + api("gregtech:gregtech:2.8.10-beta") } diff --git a/src/main/java/gregicality/multiblocks/common/metatileentities/multiblock/standard/MetaTileEntityLargeDistillery.java b/src/main/java/gregicality/multiblocks/common/metatileentities/multiblock/standard/MetaTileEntityLargeDistillery.java index 69094ad..1ea3ff7 100644 --- a/src/main/java/gregicality/multiblocks/common/metatileentities/multiblock/standard/MetaTileEntityLargeDistillery.java +++ b/src/main/java/gregicality/multiblocks/common/metatileentities/multiblock/standard/MetaTileEntityLargeDistillery.java @@ -4,8 +4,9 @@ import java.util.List; import java.util.function.Function; -import java.util.stream.Collectors; +import gregtech.api.capability.IDistillationTower; +import gregtech.api.capability.impl.DistillationTowerLogicHandler; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; @@ -13,19 +14,13 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidTank; -import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.NotNull; -import com.cleanroommc.modularui.utils.FluidTankHandler; - import gregtech.api.capability.IMultipleTankHandler; -import gregtech.api.capability.impl.FluidTankList; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.IMultiblockPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; @@ -59,21 +54,33 @@ * Requires an unfortunate amount of copy-pasted logic from * {@link gregtech.common.metatileentities.multi.electric.MetaTileEntityDistillationTower} */ -public class MetaTileEntityLargeDistillery extends GCYMRecipeMapMultiblockController { +public class MetaTileEntityLargeDistillery extends GCYMRecipeMapMultiblockController implements IDistillationTower { - protected int layerCount; - protected List orderedFluidOutputs; + protected DistillationTowerLogicHandler handler = null; public MetaTileEntityLargeDistillery(ResourceLocation metaTileEntityId) { + this(metaTileEntityId, false); + } + + public MetaTileEntityLargeDistillery(ResourceLocation metaTileEntityId, boolean useAdvHatchLogic) { super(metaTileEntityId, new RecipeMap[] { RecipeMaps.DISTILLATION_RECIPES, RecipeMaps.DISTILLERY_RECIPES }); this.recipeMapWorkable = new LargeDistilleryRecipeLogic(this); + if (useAdvHatchLogic) + this.handler = new DistillationTowerLogicHandler(this); } @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity metaTileEntityHolder) { - return new MetaTileEntityLargeDistillery(this.metaTileEntityId); + return new MetaTileEntityLargeDistillery(this.metaTileEntityId, usesAdvHatchLogic()); } + /** + * Used if MultiblockPart Abilities need to be sorted a certain way, like + * Distillation Tower and Assembly Line.
+ *
+ * There will be consequences if this is changed. Make sure to set the logic handler to one with + * a properly overriden {@link DistillationTowerLogicHandler#determineOrderedFluidOutputs()} + */ @Override protected Function multiblockPartSorter() { return RelativeDirection.UP.getSorter(getFrontFacing(), getUpwardsFacing(), isFlipped()); @@ -81,7 +88,9 @@ protected Function multiblockPartSorter() { /** * Whether this multi can be rotated or face upwards.
- * There will be consequences if this returns true. Go override {@link #determineOrderedFluidOutputs()} + *
+ * There will be consequences if this returns true. Make sure to set the logic handler to one with + * a properly overriden {@link DistillationTowerLogicHandler#determineOrderedFluidOutputs()} */ @Override public boolean allowsExtendedFacing() { @@ -108,72 +117,19 @@ protected void addDisplayText(List textList) { protected void formStructure(PatternMatchContext context) { super.formStructure(context); if (!usesAdvHatchLogic() || this.structurePattern == null) return; - this.layerCount = determineLayerCount(this.structurePattern); - this.orderedFluidOutputs = determineOrderedFluidOutputs(); + handler.determineLayerCount(this.structurePattern); + handler.determineOrderedFluidOutputs(); } protected boolean usesAdvHatchLogic() { - return getCurrentRecipeMap() == RecipeMaps.DISTILLATION_RECIPES; - } - - /** - * Needs to be overriden for multiblocks that have different assemblies than the standard distillation tower. - * - * @param structurePattern the structure pattern - * @return the number of layers that could hold output hatches - */ - protected int determineLayerCount(@NotNull BlockPattern structurePattern) { - return structurePattern.formedRepetitionCount[1] + 1; - } - - /** - * Needs to be overriden for multiblocks that have different assemblies than the standard distillation tower. - * - * @return the fluid hatches of the multiblock, in order, with null entries for layers that do not have hatches. - */ - protected List determineOrderedFluidOutputs() { - List fluidExportParts = this.getMultiblockParts().stream() - .filter(iMultiblockPart -> iMultiblockPart instanceof IMultiblockAbilityPartabilityPart && - abilityPart.getAbility() == MultiblockAbility.EXPORT_FLUIDS && - abilityPart instanceof MetaTileEntityMultiblockPart) - .map(iMultiblockPart -> (MetaTileEntityMultiblockPart) iMultiblockPart) - .collect(Collectors.toList()); - // the fluidExportParts should come sorted in smallest Y first, largest Y last. - List orderedHandlerList = new ObjectArrayList<>(); - int firstY = this.getPos().getY() + 1; - int exportIndex = 0; - for (int y = firstY; y < firstY + this.layerCount; y++) { - if (fluidExportParts.size() <= exportIndex) { - orderedHandlerList.add(null); - continue; - } - MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex); - if (part.getPos().getY() == y) { - List hatchTanks = new ObjectArrayList<>(); - // noinspection unchecked - ((IMultiblockAbilityPart) part).registerAbilities(hatchTanks); - if (hatchTanks.size() == 1) - orderedHandlerList.add(FluidTankHandler.getTankFluidHandler(hatchTanks.get(0))); - else orderedHandlerList.add(new FluidTankList(false, hatchTanks)); - exportIndex++; - } else if (part.getPos().getY() > y) { - orderedHandlerList.add(null); - } else { - GCYMLog.logger.error( - "The Distillation Tower at {} had a fluid export hatch with an unexpected Y position.", - this.getPos()); - this.invalidateStructure(); - return new ObjectArrayList<>(); - } - } - return orderedHandlerList; + return getCurrentRecipeMap() == RecipeMaps.DISTILLATION_RECIPES && this.handler != null; } @Override public void invalidateStructure() { super.invalidateStructure(); - this.layerCount = 0; - this.orderedFluidOutputs = null; + if (usesAdvHatchLogic()) + this.handler.invalidate(); } @Override @@ -211,7 +167,7 @@ public void invalidateStructure() { } @Override - protected boolean allowSameFluidFillForOutputs() { + public boolean allowSameFluidFillForOutputs() { return !usesAdvHatchLogic(); } @@ -240,7 +196,8 @@ public SoundEvent getBreakdownSound() { @Override public int getFluidOutputLimit() { - return this.layerCount; + if (usesAdvHatchLogic()) return this.handler.getLayerCount(); + else return super.getFluidOutputLimit(); } @Override @@ -259,25 +216,11 @@ public LargeDistilleryRecipeLogic(RecipeMapMultiblockController tileEntity) { super(tileEntity); } - protected boolean applyFluidToOutputs(@NotNull List fluids, boolean doFill) { - boolean valid = true; - for (int i = 0; i < fluids.size(); i++) { - IFluidHandler handler = orderedFluidOutputs.get(i); - // void if no hatch is found on that fluid's layer - // this is considered trimming and thus ignores canVoid - if (handler == null) continue; - int accepted = handler.fill(fluids.get(i), doFill); - if (accepted != fluids.get(i).amount) valid = false; - if (!doFill && !valid) break; - } - return valid; - } - @Override protected void outputRecipeOutputs() { if (usesAdvHatchLogic()) { GTTransferUtils.addItemsToItemHandler(getOutputInventory(), false, itemOutputs); - this.applyFluidToOutputs(fluidOutputs, true); + handler.applyFluidToOutputs(fluidOutputs, true); } else { super.outputRecipeOutputs(); } @@ -311,7 +254,7 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, // Perform layerwise fluid checks if (!metaTileEntity.canVoidRecipeFluidOutputs() && - !this.applyFluidToOutputs(recipe.getAllFluidOutputs(), false)) { + !handler.applyFluidToOutputs(recipe.getAllFluidOutputs(), false)) { this.isOutputsFull = true; return false; } @@ -323,5 +266,10 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, } return false; } + + @Override + protected IMultipleTankHandler getOutputTank() { + return handler.getFluidTanks(); + } } }