Skip to content

Commit

Permalink
fix #1160 & reformat DT classes
Browse files Browse the repository at this point in the history
  • Loading branch information
MCTian-mi committed Dec 14, 2024
1 parent c5b13b1 commit be581ce
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package supersymmetry.api.capability.impl;

import gregtech.api.capability.IDistillationTower;
import gregtech.api.capability.impl.DistillationTowerLogicHandler;
import gregtech.api.capability.impl.FluidTankList;
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.util.GTLog;
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.fluids.capability.IFluidHandler;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;


public class ExtendedDTLogicHandler extends DistillationTowerLogicHandler {

// This have to be an anonymous class. Just blame ceu.
protected static final FakeTank BLACK_HOLE = new FakeTank() {
};

// Y offset from the controller to the first layer that output hatch can be placed on
// As a function since monsters like LP Cryo DT exist
protected final Function<Integer, Integer> offsetCounter;
// The index of the extendable aisle repetition
protected final int outputLayerIndex;

public ExtendedDTLogicHandler(IDistillationTower tower, int outputLayerIndex, Function<Integer, Integer> offsetCounter) {
super(tower);
this.outputLayerIndex = outputLayerIndex;
this.offsetCounter = offsetCounter;
}

@Override
public void determineLayerCount(@NotNull BlockPattern structurePattern) {
this.setLayerCount(structurePattern.formedRepetitionCount[outputLayerIndex]);
}

@Override
public void determineOrderedFluidOutputs() {
// noinspection SimplifyStreamApiCallChains
List<MetaTileEntityMultiblockPart> fluidExportParts = tower.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<>();
List<IFluidTank> tankList = new ObjectArrayList<>();

int firstY = tower.getPos().getY() + offsetCounter.apply(getLayerCount());
int exportIndex = 0;
for (int y = firstY; y < firstY + this.getLayerCount(); y++) {
if (fluidExportParts.size() <= exportIndex) {
orderedHandlerList.add(BLACK_HOLE);
tankList.add(BLACK_HOLE);
continue;
}
MetaTileEntityMultiblockPart part = fluidExportParts.get(exportIndex);
if (part.getPos().getY() == y) {
List<IFluidTank> hatchTanks = new ObjectArrayList<>();
// noinspection unchecked
((IMultiblockAbilityPart<IFluidTank>) part).registerAbilities(hatchTanks);
orderedHandlerList.add(new FluidTankList(false, hatchTanks));
tankList.addAll(hatchTanks);
exportIndex++;
} else if (part.getPos().getY() > y) {
orderedHandlerList.add(BLACK_HOLE);
tankList.add(BLACK_HOLE);
} else {
GTLog.logger.error(
"The Distillation Tower at {} had a fluid export hatch with an unexpected Y position.",
tower.getPos());
tower.invalidateStructure();
this.setOrderedFluidOutputs(new ObjectArrayList<>());
this.setFluidTanks(new FluidTankList(false));
}
}
this.setOrderedFluidOutputs(orderedHandlerList);
this.setFluidTanks(new FluidTankList(tower.allowSameFluidFillForOutputs(), tankList));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

import gregtech.api.capability.IDistillationTower;
import gregtech.api.capability.impl.DistillationTowerLogicHandler;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.recipes.RecipeMap;
import gregtech.client.renderer.ICubeRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,28 +14,19 @@

import static gregtech.api.util.RelativeDirection.UP;

public class MetaTileEntityOrderedDT extends RecipeMapMultiblockController implements IDistillationTower {
public abstract class MetaTileEntityOrderedDT extends RecipeMapMultiblockController implements IDistillationTower {

protected DistillationTowerLogicHandler handler;

public MetaTileEntityOrderedDT(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap) {
super(metaTileEntityId, recipeMap);
this.handler = new DistillationTowerLogicHandler(this);
this.handler = createHandler();
this.recipeMapWorkable = new DistillationTowerRecipeLogic(this);
}

@Override
protected @NotNull BlockPattern createStructurePattern() {
return null;
}

@Override
public ICubeRenderer getBaseTexture(IMultiblockPart iMultiblockPart) {
return null;
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity iGregTechTileEntity) {
return null;
@NotNull
public DistillationTowerLogicHandler createHandler() {
return new DistillationTowerLogicHandler(this);
}

@Override
Expand All @@ -52,7 +38,6 @@ public DistillationTowerLogicHandler getHandler() {
return handler;
}


/**
* Used if MultiblockPart Abilities need to be sorted a certain way, like
* Distillation Tower and Assembly Line. <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiFluidHatch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT;
import supersymmetry.api.recipes.SuSyRecipeMaps;
import supersymmetry.client.renderer.textures.SusyTextures;
Expand All @@ -28,44 +29,48 @@ public MetaTileEntityHighPressureCryogenicDistillationPlant(ResourceLocation met
super(metaTileEntityId, SuSyRecipeMaps.HIGH_PRESSURE_CRYOGENIC_DISTILLATION);
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntityHighPressureCryogenicDistillationPlant(this.metaTileEntityId);
}

@Override
@NotNull
protected BlockPattern createStructurePattern() {
return FactoryBlockPattern.start(RIGHT, FRONT, UP)
.aisle("CCC", "CCC", "CCC")
.aisle("CSC", "CFC", "CCC")
.aisle("XXX", "XFX", "XXX").setRepeatable(1,16)
.aisle("XXX", "XFX", "XXX").setRepeatable(1, 16)
.aisle("DDD", "DDD", "DDD")
.where('S', this.selfPredicate())
.where('C', states(this.getCasingState())
.where('C', states(getCasingState())
.or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3))
.or(abilities(MultiblockAbility.IMPORT_ITEMS).setMaxGlobalLimited(1))
.or(autoAbilities(false, true, false, false, false, false, false).setExactLimit(1)))
.where('F', states(SuSyBlocks.MULTIBLOCK_CASING.getState(BlockSuSyMultiblockCasing.CasingType.SIEVE_TRAY)))
.where('X', states(getCasingState())
.or(metaTileEntities(MultiblockAbility.REGISTRY.get(MultiblockAbility.EXPORT_FLUIDS).stream()
.filter(mte->!(mte instanceof MetaTileEntityMultiFluidHatch))
.filter(mte -> !(mte instanceof MetaTileEntityMultiFluidHatch))
.toArray(MetaTileEntity[]::new))
.setMaxLayerLimited(1))
.or(metaTileEntities(MultiblockAbility.REGISTRY.get(MultiblockAbility.IMPORT_FLUIDS).stream()
.filter(mte->!(mte instanceof MetaTileEntityMultiFluidHatch))
.filter(mte -> !(mte instanceof MetaTileEntityMultiFluidHatch))
.toArray(MetaTileEntity[]::new))
.setMaxLayerLimited(1)))
.where('D', states(this.getCasingState()))
.where('D', states(getCasingState()))
.where('#', air())
.build();
}

public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) {
return Textures.FROST_PROOF_CASING;
}

protected static IBlockState getCasingState() {
return MetaBlocks.METAL_CASING.getState(MetalCasingType.ALUMINIUM_FROSTPROOF);
}

@Override
public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) {
return Textures.FROST_PROOF_CASING;
}

@Nonnull
@Override
protected ICubeRenderer getFrontOverlay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.client.renderer.ICubeRenderer;
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiFluidHatch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT;
import supersymmetry.api.recipes.SuSyRecipeMaps;
import supersymmetry.client.renderer.textures.SusyTextures;
import supersymmetry.common.blocks.BlockSuSyMultiblockCasing;
import supersymmetry.common.blocks.SuSyBlocks;

import javax.annotation.Nonnull;
import java.util.function.Function;

import static gregtech.api.util.RelativeDirection.*;

Expand All @@ -35,11 +33,7 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
}

@Override
protected Function<BlockPos, Integer> multiblockPartSorter() {
return BlockPos::getY;
}

@Override
@NotNull
protected BlockPattern createStructurePattern() {
return FactoryBlockPattern.start(RIGHT, FRONT, UP)
.aisle("YSY", "YYY", "YYY")
Expand Down Expand Up @@ -80,9 +74,4 @@ protected ICubeRenderer getFrontOverlay() {
public int getFluidOutputLimit() {
return getOutputFluidInventory().getTanks();
}

@Override
public boolean allowsExtendedFacing() {
return false;
}
}
Loading

0 comments on commit be581ce

Please sign in to comment.