diff --git a/src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java b/src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java index 47364b7fd..06fa31aac 100644 --- a/src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java +++ b/src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java @@ -508,6 +508,10 @@ public class SuSyRecipeMaps { new PrimitiveRecipeBuilder(), false) .setSound(GTSoundEvents.FURNACE); + public static final RecipeMap GREENHOUSE_TEST = new RecipeMap<>("greenhouse_test", 2, 4, 3, 1, + new SimpleRecipeBuilder(), false) + .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL); + static { GCYMRecipeMaps.ALLOY_BLAST_RECIPES.onRecipeBuild(recipeBuilder -> ADVANCED_ARC_FURNACE.recipeBuilder() .fluidInputs(SusyMaterials.RefractoryGunningMixture.getFluid(50 * diff --git a/src/main/java/supersymmetry/common/metatileentities/SuSyMetaTileEntities.java b/src/main/java/supersymmetry/common/metatileentities/SuSyMetaTileEntities.java index b78a22b25..f30846b86 100644 --- a/src/main/java/supersymmetry/common/metatileentities/SuSyMetaTileEntities.java +++ b/src/main/java/supersymmetry/common/metatileentities/SuSyMetaTileEntities.java @@ -190,6 +190,7 @@ public class SuSyMetaTileEntities { public static MetaTileEntityPrimitiveItemBus PRIMITIVE_ITEM_EXPORT; public static MetaTileEntityCupolaFurnace CUPOLA_FURNACE; + public static MetaTileEntityGreenhouse GREENHOUSE; // Space multis public static MetaTileEntityLandingPad LANDING_PAD; @@ -416,6 +417,7 @@ public static void init() { susyId("eccentric_roll_crusher"), SuSyRecipeMaps.ECCENTRIC_ROLL_CRUSHER)); BALL_MILL = registerMetaTileEntity(14742, new MetaTileEntityBallMill(susyId("ball_mill"), SuSyRecipeMaps.BALL_MILL)); + GREENHOUSE = registerMetaTileEntity(14743, new MetaTileEntityGreenhouse(susyId("greenhouse"))); // 14800 Pyrotech Integration: Primitive Smelter PRIMITIVE_ITEM_IMPORT = registerMetaTileEntity(14801, diff --git a/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityGreenhouse.java b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityGreenhouse.java new file mode 100644 index 000000000..9547c0b72 --- /dev/null +++ b/src/main/java/supersymmetry/common/metatileentities/multi/electric/MetaTileEntityGreenhouse.java @@ -0,0 +1,146 @@ +package supersymmetry.common.metatileentities.multi.electric; + +import static gregtech.api.util.RelativeDirection.*; + +import javax.annotation.Nonnull; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import org.jetbrains.annotations.NotNull; + +import gregtech.api.capability.GregtechDataCodes; +import gregtech.api.capability.impl.MultiblockRecipeLogic; +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.FactoryBlockPattern; +import gregtech.api.pattern.TraceabilityPredicate; +import gregtech.api.unification.material.Materials; +import gregtech.client.renderer.ICubeRenderer; +import gregtech.client.renderer.texture.Textures; +import gregtech.common.blocks.BlockMetalCasing; +import gregtech.common.blocks.MetaBlocks; +import gregtechfoodoption.block.GTFOGlassCasing; +import gregtechfoodoption.block.GTFOMetaBlocks; +import supersymmetry.api.recipes.SuSyRecipeMaps; + +public class MetaTileEntityGreenhouse extends RecipeMapMultiblockController { + + public static final int MAX_LENGTH = 25; + private int cellCount; + private int length; + + public MetaTileEntityGreenhouse(ResourceLocation metaTileEntityId) { + super(metaTileEntityId, SuSyRecipeMaps.GREENHOUSE_TEST); + this.recipeMapWorkable = new GreenhouseRecipeLogic(this); + } + + protected boolean updateStructureDimensions() { + World world = getWorld(); + EnumFacing back = getFrontFacing().getOpposite(); + BlockPos.MutableBlockPos bPos = new BlockPos.MutableBlockPos(getPos()); + + int length = 0; + + for (int i = 1; i <= MAX_LENGTH; i++) { + if (isBlockEdge(world, bPos, back)) { + length = i; + } else { + break; + } + } + + if (length < 5 || ((length - 1) % 4) != 0) { + invalidateStructure(); + } + + if (!this.getWorld().isRemote) { + writeCustomData(GregtechDataCodes.UPDATE_STRUCTURE_SIZE, buf -> { + buf.writeInt(this.length); + }); + } + + this.length = length; + this.cellCount = (length / 4) - 1; + return true; + } + + @Override + public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { + return new MetaTileEntityGreenhouse(metaTileEntityId); + } + + @Override + protected @NotNull BlockPattern createStructurePattern() { + if (getWorld() != null) { + updateStructureDimensions(); + } + if (cellCount < 1) { + cellCount = 1; + } + return createStructurePattern(this.cellCount); + }; + + protected @NotNull BlockPattern createStructurePattern(int cells) { + TraceabilityPredicate casingPredicate = states(getCasingState()); + + var builder = FactoryBlockPattern.start(RIGHT, UP, FRONT); + + builder.aisle("CCCCS", "FGGGF", "FGGGF", " FFF "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + + for (int i = 1; i <= cells; i++) { + builder.aisle("CDDDC", "F###F", "F###F", " FFF "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + builder.aisle("CDDDC", "G###G", "G###G", " GGG "); + } + return builder + .aisle("CCCCC", "FGGGF", "FGGGF", " FFF ") + .where('S', selfPredicate()) + .where('C', states(this.getCasingState()).or(this.autoAbilities())) + .where('D', states(Blocks.DIRT.getDefaultState(), Blocks.GRASS.getDefaultState())) + .where('G', states(getGlassState())) + .where('F', frames(Materials.Steel)) + .where(' ', any()) + .where('#', air()) + .build(); + } + + public ICubeRenderer getBaseTexture(IMultiblockPart sourcePart) { + return Textures.SOLID_STEEL_CASING; + } + + protected static IBlockState getGlassState() { + return GTFOMetaBlocks.GTFO_GLASS_CASING.getState(GTFOGlassCasing.CasingType.GREENHOUSE_GLASS); + } + + protected static IBlockState getCasingState() { + return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); + } + + private class GreenhouseRecipeLogic extends MultiblockRecipeLogic { + + public GreenhouseRecipeLogic(RecipeMapMultiblockController tileEntity) { + super(tileEntity); + } + } + + public boolean isBlockEdge(@Nonnull World world, @Nonnull BlockPos.MutableBlockPos pos, + @Nonnull EnumFacing direction) { + return world.getBlockState(pos.move(direction)) == getSecondaryCasingState(); + } + + public IBlockState getSecondaryCasingState() { + return MetaBlocks.METAL_CASING.getState(BlockMetalCasing.MetalCasingType.STEEL_SOLID); + } +}