Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #356 & reformat DT classes #355

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,45 +2,37 @@

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 gregtech.client.utils.TooltipHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import supersymmetry.common.recipes.DistillationTowerRecipeLogic;

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

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 +44,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 Expand Up @@ -91,4 +82,11 @@ public int getFluidOutputLimit() {
public boolean allowsExtendedFacing() {
return false;
}

@Override
public void addInformation(ItemStack stack, @Nullable World world, @NotNull List<String> tooltip, boolean advanced) {
super.addInformation(stack, world, tooltip, advanced);
tooltip.add(I18n.format("gregtech.machine.ordered_dt.tooltip.1"));
tooltip.add(I18n.format("gregtech.machine.ordered_dt.tooltip.2"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package supersymmetry.common.metatileentities.multi.electric;

import gregtech.api.capability.impl.DistillationTowerLogicHandler;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
Expand All @@ -13,6 +14,8 @@
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.capability.impl.ExtendedDTLogicHandler;
import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT;
import supersymmetry.api.recipes.SuSyRecipeMaps;
import supersymmetry.client.renderer.textures.SusyTextures;
Expand All @@ -28,44 +31,55 @@ 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()))
.setMaxLayerLimited(4)))
.where('D', states(getCasingState()))
.where('#', air())
.build();
}

public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) {
return Textures.FROST_PROOF_CASING;
@Override
@NotNull
public DistillationTowerLogicHandler createHandler() {
return new ExtendedDTLogicHandler(this, 2, ignored -> 1);
}


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
Loading