diff --git a/src/main/java/supersymmetry/api/metatileentity/multiblock/MetaTileEntityOrderedDT.java b/src/main/java/supersymmetry/api/metatileentity/multiblock/MetaTileEntityOrderedDT.java new file mode 100644 index 000000000..33e402735 --- /dev/null +++ b/src/main/java/supersymmetry/api/metatileentity/multiblock/MetaTileEntityOrderedDT.java @@ -0,0 +1,94 @@ +package supersymmetry.api.metatileentity.multiblock; + +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; +import supersymmetry.common.recipes.DistillationTowerRecipeLogic; + +import java.util.function.Function; + +import static gregtech.api.util.RelativeDirection.UP; + +public class MetaTileEntityOrderedDT extends RecipeMapMultiblockController implements IDistillationTower { + protected DistillationTowerLogicHandler handler; + + public MetaTileEntityOrderedDT(ResourceLocation metaTileEntityId, RecipeMap recipeMap) { + super(metaTileEntityId, recipeMap); + this.handler = new DistillationTowerLogicHandler(this); + 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; + } + + @Override + public boolean allowSameFluidFillForOutputs() { + return false; + } + + public DistillationTowerLogicHandler getHandler() { + return handler; + } + + + /** + * 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 UP.getSorter(getFrontFacing(), getUpwardsFacing(), isFlipped()); + } + + @Override + protected void formStructure(PatternMatchContext context) { + super.formStructure(context); + if (this.handler == null || this.structurePattern == null) return; + handler.determineLayerCount(this.structurePattern); + handler.determineOrderedFluidOutputs(); + } + + + @Override + public void invalidateStructure() { + super.invalidateStructure(); + if (this.handler != null) handler.invalidate(); + } + + + @Override + public int getFluidOutputLimit() { + if (this.handler != null) return this.handler.getLayerCount(); + else return super.getFluidOutputLimit(); + } + + @Override + public boolean allowsExtendedFacing() { + return false; + } +} diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighPressureCryogenicDistillationPlant.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighPressureCryogenicDistillationPlant.java index 349f1850e..cc7f81086 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighPressureCryogenicDistillationPlant.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighPressureCryogenicDistillationPlant.java @@ -15,6 +15,7 @@ import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiFluidHatch; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.api.recipes.SuSyRecipeMaps; import supersymmetry.client.renderer.textures.SusyTextures; import supersymmetry.common.blocks.BlockSuSyMultiblockCasing; @@ -24,10 +25,9 @@ import static gregtech.api.util.RelativeDirection.*; -public class MetaTileEntityHighPressureCryogenicDistillationPlant extends RecipeMapMultiblockController { +public class MetaTileEntityHighPressureCryogenicDistillationPlant extends MetaTileEntityOrderedDT { public MetaTileEntityHighPressureCryogenicDistillationPlant(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SuSyRecipeMaps.HIGH_PRESSURE_CRYOGENIC_DISTILLATION); - this.recipeMapWorkable = new MultiblockRecipeLogic(this, false); } public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighTemperatureDistillationTower.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighTemperatureDistillationTower.java index 749e594c7..c26c72081 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighTemperatureDistillationTower.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityHighTemperatureDistillationTower.java @@ -12,6 +12,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.api.recipes.SuSyRecipeMaps; import supersymmetry.client.renderer.textures.SusyTextures; import supersymmetry.common.blocks.BlockSuSyMultiblockCasing; @@ -22,7 +23,7 @@ import static gregtech.api.util.RelativeDirection.*; -public class MetaTileEntityHighTemperatureDistillationTower extends RecipeMapMultiblockController { +public class MetaTileEntityHighTemperatureDistillationTower extends MetaTileEntityOrderedDT { public MetaTileEntityHighTemperatureDistillationTower(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SuSyRecipeMaps.HIGH_TEMPERATURE_DISTILLATION); @@ -60,11 +61,6 @@ protected BlockPattern createStructurePattern() { .build(); } - @Override - protected boolean allowSameFluidFillForOutputs() { - return false; - } - @Override public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { return SusyTextures.SILICON_CARBIDE_CASING; diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityLowPressureCryogenicDistillationPlant.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityLowPressureCryogenicDistillationPlant.java index 5fd9cdb59..926196881 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityLowPressureCryogenicDistillationPlant.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityLowPressureCryogenicDistillationPlant.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; import supersymmetry.api.metatileentity.multiblock.ICryogenicProvider; import supersymmetry.api.metatileentity.multiblock.ICryogenicReceiver; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.api.recipes.SuSyRecipeMaps; import supersymmetry.client.renderer.textures.SusyTextures; import supersymmetry.common.blocks.BlockSuSyMultiblockCasing; @@ -28,13 +29,12 @@ import static gregtech.api.util.RelativeDirection.*; -public class MetaTileEntityLowPressureCryogenicDistillationPlant extends RecipeMapMultiblockController implements ICryogenicProvider { +public class MetaTileEntityLowPressureCryogenicDistillationPlant extends MetaTileEntityOrderedDT implements ICryogenicProvider { private @Nullable ICryogenicReceiver receiver; public MetaTileEntityLowPressureCryogenicDistillationPlant(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SuSyRecipeMaps.LOW_PRESSURE_CRYOGENIC_DISTILLATION); - this.recipeMapWorkable = new MultiblockRecipeLogic(this, false); } public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySieveDistillationTower.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySieveDistillationTower.java index 1fbb9c3f2..f87ea0c52 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySieveDistillationTower.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySieveDistillationTower.java @@ -32,8 +32,10 @@ import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandlerModifiable; import org.jetbrains.annotations.NotNull; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.common.blocks.BlockSuSyMultiblockCasing; import supersymmetry.common.blocks.SuSyBlocks; +import supersymmetry.common.recipes.DistillationTowerRecipeLogic; import java.util.List; import java.util.function.Function; @@ -41,12 +43,11 @@ import static gregtech.api.util.RelativeDirection.*; import static supersymmetry.api.recipes.SuSyRecipeMaps.SIEVE_DISTILLATION_RECIPES; -public class MetaTileEntitySieveDistillationTower extends RecipeMapMultiblockController implements IDistillationTower { +public class MetaTileEntitySieveDistillationTower extends MetaTileEntityOrderedDT implements IDistillationTower { protected DistillationTowerLogicHandler handler; public MetaTileEntitySieveDistillationTower(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SIEVE_DISTILLATION_RECIPES); - this.recipeMapWorkable = new SieveDistillationTowerRecipeLogic(this); this.handler = new DistillationTowerLogicHandler(this); } @@ -54,29 +55,6 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { return new MetaTileEntitySieveDistillationTower(this.metaTileEntityId); } - /** - * 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 UP.getSorter(getFrontFacing(), getUpwardsFacing(), isFlipped()); - } - - /** - * Whether this multi can be rotated or face upwards.
- *
- * 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() { - return false; - } - @Override protected void addDisplayText(List textList) { if (isStructureFormed()) { @@ -93,19 +71,6 @@ protected void addDisplayText(List textList) { super.addDisplayText(textList); } - @Override - protected void formStructure(PatternMatchContext context) { - super.formStructure(context); - if (this.handler == null || this.structurePattern == null) return; - handler.determineLayerCount(this.structurePattern); - handler.determineOrderedFluidOutputs(); - } - - @Override - public void invalidateStructure() { - super.invalidateStructure(); - if (this.handler != null) handler.invalidate(); - } @Override protected @NotNull BlockPattern createStructurePattern() { @@ -125,11 +90,6 @@ public void invalidateStructure() { .build(); } - @Override - public boolean allowSameFluidFillForOutputs() { - return false; - } - @SideOnly(Side.CLIENT) @Override public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { @@ -156,64 +116,4 @@ protected ICubeRenderer getFrontOverlay() { return Textures.DISTILLATION_TOWER_OVERLAY; } - @Override - public int getFluidOutputLimit() { - if (this.handler != null) return this.handler.getLayerCount(); - else return super.getFluidOutputLimit(); - } - - protected class SieveDistillationTowerRecipeLogic extends MultiblockRecipeLogic { - - public SieveDistillationTowerRecipeLogic(MetaTileEntitySieveDistillationTower tileEntity) { - super(tileEntity); - } - - @Override - protected void outputRecipeOutputs() { - GTTransferUtils.addItemsToItemHandler(getOutputInventory(), false, itemOutputs); - handler.applyFluidToOutputs(fluidOutputs, true); - } - - @Override - protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, - @NotNull IItemHandlerModifiable importInventory, - @NotNull IMultipleTankHandler importFluids) { - this.overclockResults = calculateOverclock(recipe); - - modifyOverclockPost(overclockResults, recipe.getRecipePropertyStorage()); - - if (!hasEnoughPower(overclockResults)) { - return false; - } - - IItemHandlerModifiable exportInventory = getOutputInventory(); - - // We have already trimmed outputs and chanced outputs at this time - // Attempt to merge all outputs + chanced outputs into the output bus, to prevent voiding chanced outputs - if (!metaTileEntity.canVoidRecipeItemOutputs() && - !GTTransferUtils.addItemsToItemHandler(exportInventory, true, recipe.getAllItemOutputs())) { - this.isOutputsFull = true; - return false; - } - - // We have already trimmed fluid outputs at this time - if (!metaTileEntity.canVoidRecipeFluidOutputs() && - !handler.applyFluidToOutputs(recipe.getAllFluidOutputs(), false)) { - this.isOutputsFull = true; - return false; - } - - this.isOutputsFull = false; - if (recipe.matches(true, importInventory, importFluids)) { - this.metaTileEntity.addNotifiedInput(importInventory); - return true; - } - return false; - } - - @Override - protected IMultipleTankHandler getOutputTank() { - return handler.getFluidTanks(); - } - } } diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySingleColumnCryogenicDistillationPlant.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySingleColumnCryogenicDistillationPlant.java index 74d9b98b3..e10077e79 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySingleColumnCryogenicDistillationPlant.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntitySingleColumnCryogenicDistillationPlant.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; import supersymmetry.api.metatileentity.multiblock.ICryogenicProvider; import supersymmetry.api.metatileentity.multiblock.ICryogenicReceiver; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.api.recipes.SuSyRecipeMaps; import supersymmetry.common.blocks.BlockSuSyMultiblockCasing; import supersymmetry.common.blocks.SuSyBlocks; @@ -27,13 +28,12 @@ import static gregtech.api.util.RelativeDirection.*; -public class MetaTileEntitySingleColumnCryogenicDistillationPlant extends RecipeMapMultiblockController implements ICryogenicProvider { +public class MetaTileEntitySingleColumnCryogenicDistillationPlant extends MetaTileEntityOrderedDT implements ICryogenicProvider { private @Nullable ICryogenicReceiver receiver; public MetaTileEntitySingleColumnCryogenicDistillationPlant(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SuSyRecipeMaps.SINGLE_COLUMN_CRYOGENIC_DISTILLATION); - this.recipeMapWorkable = new MultiblockRecipeLogic(this, false); } public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityVacuumDistillationTower.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityVacuumDistillationTower.java index c61446e6d..13fa8ab8e 100644 --- a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityVacuumDistillationTower.java +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityVacuumDistillationTower.java @@ -1,5 +1,7 @@ package supersymmetry.common.metatileentities.multi.electric; +import gregtech.api.capability.IDistillationTower; +import gregtech.api.capability.impl.DistillationTowerLogicHandler; import gregtech.api.capability.impl.MultiblockRecipeLogic; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; @@ -22,6 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; import supersymmetry.api.recipes.SuSyRecipeMaps; import supersymmetry.client.renderer.textures.SusyTextures; @@ -31,10 +34,10 @@ import static gregtech.api.util.RelativeDirection.*; -public class MetaTileEntityVacuumDistillationTower extends RecipeMapMultiblockController { +public class MetaTileEntityVacuumDistillationTower extends MetaTileEntityOrderedDT { + public MetaTileEntityVacuumDistillationTower(ResourceLocation metaTileEntityId) { super(metaTileEntityId, SuSyRecipeMaps.VACUUM_DISTILLATION_RECIPES); - this.recipeMapWorkable = new MultiblockRecipeLogic(this, true); } public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { @@ -46,7 +49,7 @@ protected BlockPattern createStructurePattern() { .aisle(" CSC ", "CCCCCC", "CCCCCC", "CCCCCC", " CCC ") .aisle(" CGC ", "C#F#CC", "IFFF#P", "C#F#CC", " CCC ") .aisle(" CCC ", "C#F#CC", "CFFFCC", "C#F#CC", " CCC ") - .aisle(" XXX ", "X#F#D ", "XFFFD ", "X#F#D ", " XXX ").setRepeatable(1,12) + .aisle(" XXX ", "X#F#D ", "XFFFD ", "X#F#D ", " XXX ").setRepeatable(1, 12) .aisle(" DDD ", "DDDDD ", "DDDDD ", "DDDDD ", " DDD ") .where('S', this.selfPredicate()) .where('G', states(this.getGlassState())) @@ -54,19 +57,20 @@ protected BlockPattern createStructurePattern() { .where('F', frames(Materials.Steel)) .where('C', states(this.getCasingState()) .or(abilities(MultiblockAbility.INPUT_ENERGY).setMinGlobalLimited(1).setMaxGlobalLimited(3)) - .or(abilities(MultiblockAbility.IMPORT_FLUIDS).setMaxGlobalLimited(1)) + .or(abilities(MultiblockAbility.IMPORT_FLUIDS).setMaxGlobalLimited(2)) .or(abilities(MultiblockAbility.IMPORT_ITEMS).setMaxGlobalLimited(1))) .where('I', abilities(MultiblockAbility.EXPORT_ITEMS).setMaxGlobalLimited(1)) .where('D', states(this.getCasingState())) .where('X', states(getCasingState()) .or(metaTileEntities(MultiblockAbility.REGISTRY.get(MultiblockAbility.EXPORT_FLUIDS).stream() - .filter(mte->!(mte instanceof MetaTileEntityMultiFluidHatch)) - .toArray(MetaTileEntity[]::new)) - .setMinLayerLimited(1).setMaxLayerLimited(1)) - .or(autoAbilities(true, false))) + .filter(mte -> !(mte instanceof MetaTileEntityMultiFluidHatch)) + .toArray(MetaTileEntity[]::new)) + .setMaxLayerLimited(1)) + ) .where('#', air()) .build(); } + public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { return Textures.SOLID_STEEL_CASING; } @@ -74,9 +78,11 @@ public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { protected static IBlockState getGlassState() { return MetaBlocks.TRANSPARENT_CASING.getState(BlockGlassCasing.CasingType.TEMPERED_GLASS); } + protected static IBlockState getCasingState() { return MetaBlocks.METAL_CASING.getState(MetalCasingType.STEEL_SOLID); } + protected static IBlockState getPipeCasingState() { return MetaBlocks.BOILER_CASING.getState(BoilerCasingType.STEEL_PIPE); } @@ -91,9 +97,4 @@ public void addInformation(ItemStack stack, @Nullable World player, List protected ICubeRenderer getFrontOverlay() { return SusyTextures.VDT_OVERLAY; } - - @Override - public boolean allowsExtendedFacing() { - return false; - } } diff --git a/src/main/java/supersymmetry/common/recipes/DistillationTowerRecipeLogic.java b/src/main/java/supersymmetry/common/recipes/DistillationTowerRecipeLogic.java new file mode 100644 index 000000000..433e2a806 --- /dev/null +++ b/src/main/java/supersymmetry/common/recipes/DistillationTowerRecipeLogic.java @@ -0,0 +1,70 @@ +package supersymmetry.common.recipes; + +import gregtech.api.capability.IMultipleTankHandler; +import gregtech.api.capability.impl.MultiblockRecipeLogic; +import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; +import gregtech.api.recipes.Recipe; +import gregtech.api.util.GTTransferUtils; +import net.minecraftforge.items.IItemHandlerModifiable; +import org.jetbrains.annotations.NotNull; +import supersymmetry.api.metatileentity.multiblock.MetaTileEntityOrderedDT; + +public class DistillationTowerRecipeLogic extends MultiblockRecipeLogic { + public DistillationTowerRecipeLogic(RecipeMapMultiblockController tileEntity) { + super(tileEntity); + } + + @Override + protected void outputRecipeOutputs() { + GTTransferUtils.addItemsToItemHandler(getOutputInventory(), false, itemOutputs); + if (metaTileEntity instanceof MetaTileEntityOrderedDT tower) + tower.getHandler().applyFluidToOutputs(fluidOutputs, true); + } + + @Override + protected boolean setupAndConsumeRecipeInputs(@NotNull Recipe recipe, + @NotNull IItemHandlerModifiable importInventory, + @NotNull IMultipleTankHandler importFluids) { + this.overclockResults = calculateOverclock(recipe); + + modifyOverclockPost(overclockResults, recipe.getRecipePropertyStorage()); + + if (!hasEnoughPower(overclockResults)) { + return false; + } + + IItemHandlerModifiable exportInventory = getOutputInventory(); + + // We have already trimmed outputs and chanced outputs at this time + // Attempt to merge all outputs + chanced outputs into the output bus, to prevent voiding chanced outputs + if (!metaTileEntity.canVoidRecipeItemOutputs() && + !GTTransferUtils.addItemsToItemHandler(exportInventory, true, recipe.getAllItemOutputs())) { + this.isOutputsFull = true; + return false; + } + + if (metaTileEntity instanceof MetaTileEntityOrderedDT tower) { + // We have already trimmed fluid outputs at this time + if (!metaTileEntity.canVoidRecipeFluidOutputs() && + !tower.getHandler().applyFluidToOutputs(recipe.getAllFluidOutputs(), false)) { + this.isOutputsFull = true; + return false; + } + } + + this.isOutputsFull = false; + if (recipe.matches(true, importInventory, importFluids)) { + this.metaTileEntity.addNotifiedInput(importInventory); + return true; + } + return false; + } + + @Override + protected IMultipleTankHandler getOutputTank() { + if (metaTileEntity instanceof MetaTileEntityOrderedDT tower) + return tower.getHandler().getFluidTanks(); + return super.getOutputTank(); + } + +}