Skip to content

Commit

Permalink
fix hard mui2 dep
Browse files Browse the repository at this point in the history
update to ceu 2.8.10
  • Loading branch information
ghzdude committed Aug 2, 2024
1 parent bbeff1c commit 68d6a06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 89 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

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;
import net.minecraft.util.math.BlockPos;
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;
Expand Down Expand Up @@ -59,29 +54,43 @@
* 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<IFluidHandler> 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. <br>
* <br>
* There will be <i>consequences</i> if this is changed. Make sure to set the logic handler to one with
* a properly overriden {@link DistillationTowerLogicHandler#determineOrderedFluidOutputs()}
*/
@Override
protected Function<BlockPos, Integer> multiblockPartSorter() {
return RelativeDirection.UP.getSorter(getFrontFacing(), getUpwardsFacing(), isFlipped());
}

/**
* Whether this multi can be rotated or face upwards. <br>
* There will be <i>consequences</i> if this returns true. Go override {@link #determineOrderedFluidOutputs()}
* <br>
* There will be <i>consequences</i> if this returns true. Make sure to set the logic handler to one with
* a properly overriden {@link DistillationTowerLogicHandler#determineOrderedFluidOutputs()}
*/
@Override
public boolean allowsExtendedFacing() {
Expand All @@ -108,72 +117,19 @@ protected void addDisplayText(List<ITextComponent> 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 <b>could</b> 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<IFluidHandler> determineOrderedFluidOutputs() {
List<MetaTileEntityMultiblockPart> fluidExportParts = this.getMultiblockParts().stream()
.filter(iMultiblockPart -> iMultiblockPart instanceof IMultiblockAbilityPart<?>abilityPart &&
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<IFluidHandler> 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<IFluidTank> hatchTanks = new ObjectArrayList<>();
// noinspection unchecked
((IMultiblockAbilityPart<IFluidTank>) 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
Expand Down Expand Up @@ -211,7 +167,7 @@ public void invalidateStructure() {
}

@Override
protected boolean allowSameFluidFillForOutputs() {
public boolean allowSameFluidFillForOutputs() {
return !usesAdvHatchLogic();
}

Expand Down Expand Up @@ -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
Expand All @@ -259,25 +216,11 @@ public LargeDistilleryRecipeLogic(RecipeMapMultiblockController tileEntity) {
super(tileEntity);
}

protected boolean applyFluidToOutputs(@NotNull List<FluidStack> 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();
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -323,5 +266,10 @@ protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe,
}
return false;
}

@Override
protected IMultipleTankHandler getOutputTank() {
return handler.getFluidTanks();
}
}
}

0 comments on commit 68d6a06

Please sign in to comment.