From dbab3423566f64c354977acc362ccdd3335bb865 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Fri, 4 Mar 2022 20:21:11 +0100 Subject: StructureLib integration (#99) * Implement StructureLib to Mega Vacuum Freezer * Remove unused translation * EIC StructureLib integration Electric Implosion Compressor * Bacterial Vat StructureLib integration * Remove unused translations * Change air block to isAir * Block rotation of EIC * Add recipe map to MVF * Manual Trafo StructureLib integration * Windmill StructureLib integration * Block Windmill rotation Former-commit-id: 43331bd8d46203a87bdadd234295c2e75ac82621 --- .../tileentities/multis/GT_TileEntity_BioVat.java | 178 ++++++--- .../GT_TileEntity_ElectricImplosionCompressor.java | 220 +++++++---- .../multis/GT_TileEntity_ManualTrafo.java | 427 +++++++++------------ .../multis/GT_TileEntity_Windmill.java | 183 +++++---- .../mega/GT_TileEntity_MegaVacuumFreezer.java | 147 +++++-- .../bartimaeusnek/bartworks/util/BW_Util.java | 2 +- 6 files changed, 660 insertions(+), 497 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_BioVat.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_BioVat.java index 9d1a054cb0..993099521d 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_BioVat.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_BioVat.java @@ -30,22 +30,27 @@ import com.github.bartimaeusnek.bartworks.common.loaders.FluidLoader; import com.github.bartimaeusnek.bartworks.common.net.RendererPacket; import com.github.bartimaeusnek.bartworks.common.tileentities.tiered.GT_MetaTileEntity_RadioHatch; import com.github.bartimaeusnek.bartworks.util.*; +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.util.ForgeDirection; @@ -56,11 +61,16 @@ import net.minecraftforge.fluids.FluidStack; import java.util.*; import java.util.stream.Collectors; -public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_GLOW; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +public class GT_TileEntity_BioVat extends GT_MetaTileEntity_EnhancedMultiBlockBase { public static final HashMap staticColorMap = new HashMap<>(); - private static final byte MCASING_INDEX = 49; private static final byte TIMERDIVIDER = 20; private final HashSet playerMPHashSet = new HashSet<>(); @@ -74,6 +84,7 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { private byte mGlassTier; private int mSievert; private int mNeededSievert; + private int mCasing = 0; public GT_TileEntity_BioVat(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -83,6 +94,88 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { super(aName); } + private static final int CASING_INDEX = 49; + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"ccccc", "ccccc", "ccccc", "ccccc", "ccccc"}, + {"ggggg", "gaaag", "gaaag", "gaaag", "ggggg"}, + {"ggggg", "gaaag", "gaaag", "gaaag", "ggggg"}, + {"cc~cc", "ccccc", "ccccc", "ccccc", "ccccc"}, + })) + .addElement('c', ofChain( + ofHatchAdder(GT_TileEntity_BioVat::addMaintenanceToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_BioVat::addOutputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_BioVat::addInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_BioVat::addRadiationInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_BioVat::addEnergyInputToMachineList, CASING_INDEX, 1), + onElementPass(e -> e.mCasing++, ofBlock(GregTech_API.sBlockCasings4, 1)) + )) + .addElement('a', ofChain( + isAir(), + ofBlockAnyMeta(FluidLoader.bioFluidBlock) + )) + .addElement('g', new IStructureElement(){ + + @Override + public boolean check(GT_TileEntity_BioVat te, World world, int x, int y, int z) { + byte glasstier = BW_Util.calculateGlassTier(world.getBlock(x, y, z), (byte)world.getBlockMetadata(x, y, z)); + if(glasstier == 0) + return false; + if(te.mGlassTier == 0) + te.mGlassTier = glasstier; + return te.mGlassTier == glasstier; + } + + @Override + public boolean spawnHint(GT_TileEntity_BioVat te, World world, int x, int y, int z, ItemStack itemStack) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 1 /* aDots: 2 */); + return true; + } + + @Override + public boolean placeBlock(GT_TileEntity_BioVat te, World world, int x, int y, int z, ItemStack itemStack) { + world.setBlock(x, y, z, Blocks.glass, 0, 2); + return true; + } + }) + .build(); + + @Override + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && f.isNotFlipped(); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt. + addMachineType("Bacterial Vat"). + addInfo("Controller block for the Bacterial Vat"). + addInfo("For maximum efficiency boost keep the Output Hatch always half filled!"). + addSeparator(). + beginStructureBlock(5, 4, 5, false). + addController("Front bottom center"). + addCasingInfo("Clean Stainless Steel Casings", 19). + addOtherStructurePart("Glass", "Hollow two middle layers", 2). + addStructureInfo("The glass can be any glass, i.e. Tinkers Construct Clear Glass"). + addStructureInfo("Some Recipes need more advanced Glass Types"). + addMaintenanceHatch("Any casing", 1). + addOtherStructurePart("Radio Hatch", "Any casing", 1). + addInputBus("Any casing", 1). + addOutputBus("Any casing", 1). + addInputHatch("Any casing", 1). + addOutputHatch("Any casing", 1). + addEnergyHatch("Any casing", 1). + toolTipFinisher("Bartworks"); + return tt; + } + public static int[] specialValueUnpack(int aSpecialValue) { int[] ret = new int[4]; ret[0] = aSpecialValue & 0xF; // = glass tier @@ -259,7 +352,7 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { return this.mOutputHatches.stream().map(GT_MetaTileEntity_Hatch_Output::getFluid).filter(Objects::nonNull).collect(Collectors.toSet()); } - private boolean addRadiationInputToMachineList(IGregTechTileEntity aTileEntity) { + private boolean addRadiationInputToMachineList(IGregTechTileEntity aTileEntity, int CasingIndex) { if (aTileEntity == null) { return false; } else { @@ -267,7 +360,7 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { if (aMetaTileEntity == null) { return false; } else if (aMetaTileEntity instanceof GT_MetaTileEntity_RadioHatch) { - ((GT_MetaTileEntity_RadioHatch) aMetaTileEntity).updateTexture(GT_TileEntity_BioVat.MCASING_INDEX); + ((GT_MetaTileEntity_RadioHatch) aMetaTileEntity).updateTexture(CasingIndex); return this.mRadHatches.add((GT_MetaTileEntity_RadioHatch) aMetaTileEntity); } else { return false; @@ -277,49 +370,19 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; - int blockcounter = 0; this.mRadHatches.clear(); + this.mGlassTier = 0; + this.mCasing = 0; - for (int x = -2; x <= 2; x++) - for (int z = -2; z <= 2; z++) - for (int y = 0; y < 4; y++) { - IGregTechTileEntity tileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, y, zDir + z); - if (y == 0 || y == 3) { - //controller - if (y == 0 && xDir + x == 0 && zDir + z == 0) - continue; - if (!(this.addOutputToMachineList(tileEntity, GT_TileEntity_BioVat.MCASING_INDEX) || this.addRadiationInputToMachineList(tileEntity) || this.addInputToMachineList(tileEntity, GT_TileEntity_BioVat.MCASING_INDEX) || this.addMaintenanceToMachineList(tileEntity, GT_TileEntity_BioVat.MCASING_INDEX) || this.addEnergyInputToMachineList(tileEntity, GT_TileEntity_BioVat.MCASING_INDEX))) { - if (BW_Util.addBlockToMachine(x, y, z, 2, aBaseMetaTileEntity, GregTech_API.sBlockCasings4, 1)) { - ++blockcounter; - continue; - } - return false; - } - } else { - if (Math.abs(x) < 2 && Math.abs(z) != 2) { - if (!(BW_Util.addBlockToMachine(x, y, z, 2, aBaseMetaTileEntity, Blocks.air) || (BW_Util.addBlockToMachine(x, y, z, 2, aBaseMetaTileEntity, FluidLoader.bioFluidBlock)))) { - return false; - } - } else { - if (x == -2 && z == -2 && y == 1) - this.mGlassTier = BW_Util.calculateGlassTier(aBaseMetaTileEntity.getBlockOffset(xDir + -2, y, zDir + z), aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z)); - if (0 == this.mGlassTier || this.mGlassTier != BW_Util.calculateGlassTier(aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z), aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z))) { - return false; - } - } - } - } - - if (blockcounter > 18 && - this.mRadHatches.size() < 2 && - this.mOutputHatches.size() == 1 && - this.mMaintenanceHatches.size() == 1 && - this.mInputHatches.size() > 0) - return this.mEnergyHatches.size() > 0; + if(!checkPiece(STRUCTURE_PIECE_MAIN, 2, 3, 0)) + return false; - return false; + return this.mCasing >= 19 && + this.mRadHatches.size() <= 1 && + this.mOutputHatches.size() == 1 && + this.mMaintenanceHatches.size() == 1 && + this.mInputHatches.size() > 0 && + this.mEnergyHatches.size() > 0; } @Override @@ -567,18 +630,23 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_MultiBlockBase { } @Override - public String[] getDescription() { - String[] dsc = StatCollector.translateToLocal("tooltip.tile.bvat.0.name").split(";"); - String[] fdsc = new String[dsc.length + 1]; - for (int i = 0; i < dsc.length; i++) { - fdsc[i] = dsc[i]; - fdsc[dsc.length] = BW_Tooltip_Reference.ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS.get(); + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE_GLOW).extFacing().glow().build()}; + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_DISTILLATION_TOWER_GLOW).extFacing().glow().build()}; } - return fdsc; + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_INDEX)}; } @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return aSide == aFacing ? new ITexture[]{Textures.BlockIcons.getCasingTextureForId(GT_TileEntity_BioVat.MCASING_INDEX), TextureFactory.of(aActive ? TextureFactory.of(TextureFactory.of(Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE), TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE_GLOW).glow().build()) : TextureFactory.of(TextureFactory.of(Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER), TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_GLOW).glow().build()))} : new ITexture[]{Textures.BlockIcons.getCasingTextureForId(GT_TileEntity_BioVat.MCASING_INDEX)}; + public void construct(ItemStack itemStack, boolean b) { + buildPiece(STRUCTURE_PIECE_MAIN, itemStack, b, 2, 3, 0); } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java index f761543f56..b9c3d36c0e 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ElectricImplosionCompressor.java @@ -22,28 +22,39 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.multis; -import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; -import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ImplosionCompressor; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import java.util.ArrayList; import static com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry.BW_BLOCKS; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; -public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity_ImplosionCompressor { +public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity_EnhancedMultiBlockBase { public static GT_Recipe.GT_Recipe_Map eicMap; - private Boolean piston = null; + private Boolean piston = true; public GT_TileEntity_ElectricImplosionCompressor(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -53,6 +64,98 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity super(aName); } + private static final int CASING_INDEX = 16; + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {"ccc", "cec", "ccc"}, + {"ttt", "tft", "ttt"}, + {"ttt", "tft", "ttt"}, + {"nnn", "nnn", "nnn"}, + {"nNn", "NNN", "nNn"}, + {"nnn", "nnn", "nnn"}, + {"t~t", "tft", "ttt"}, + {"ttt", "tft", "ttt"}, + {"CCC", "CeC", "CCC"}, + })) + .addElement('c', ofChain( + ofBlock(GregTech_API.sBlockCasings2, 0), + ofBlock(GregTech_API.sBlockCasings3, 4) + )) + .addElement('t', ofBlock(BW_BLOCKS[2], 1)) + .addElement('f', ofBlock(BW_BLOCKS[2], 0)) + .addElement('n', ofBlock(GregTech_API.sBlockMetal5, 2)) + .addElement('C', ofChain( + ofHatchAdder(GT_TileEntity_ElectricImplosionCompressor::addInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_ElectricImplosionCompressor::addOutputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_ElectricImplosionCompressor::addMaintenanceToMachineList, CASING_INDEX, 1), + ofBlock(GregTech_API.sBlockCasings2, 0), + ofBlock(GregTech_API.sBlockCasings3, 4) + )) + .addElement('e', ofHatchAdder(GT_TileEntity_ElectricImplosionCompressor::addEnergyInputToMachineList, CASING_INDEX, 2)) + .addElement('N', new IStructureElement(){ + + @Override + public boolean check(GT_TileEntity_ElectricImplosionCompressor te, World world, int x, int y, int z) { + if(!te.piston && !world.isAirBlock(x, y, z)) + return false; + if(te.piston && !(world.getBlock(x, y, z) == GregTech_API.sBlockMetal5 && world.getBlockMetadata(x, y, z) == 2)) + return false; + return true; + } + + @Override + public boolean spawnHint(GT_TileEntity_ElectricImplosionCompressor te, World world, int x, int y, int z, ItemStack itemStack) { + if(te.piston) + StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockMetal5, 2); + return true; + } + + @Override + public boolean placeBlock(GT_TileEntity_ElectricImplosionCompressor te, World world, int x, int y, int z, ItemStack itemStack) { + if(te.piston) + world.setBlock(x, y, z, GregTech_API.sBlockMetal5, 2, 3); + else + world.setBlockToAir(x, y, z); + return true; + } + }) + .build(); + + @Override + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && f.isNotFlipped(); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt. + addMachineType("Implosion Compressor"). + addInfo("Explosions are fun"). + addInfo("Controller block for the Electric Implosion Compressor"). + addInfo("Uses electricity instead of Explosives"). + addSeparator(). + beginStructureBlock(3, 9, 3, false). + addController("Front 3rd layer center"). + addCasingInfo("Solid Steel Machine Casing", 8). + addStructureInfo("Casings can be replaced with Explosion Warning Signs"). + addOtherStructurePart("Transformer-Winding Blocks", "Outer layer 2,3,7,8"). + addOtherStructurePart("Nickel-Zinc-Ferrite Blocks", "Inner layer 2,3,7,8"). + addOtherStructurePart("Neutronium Blocks", "Layer 4,5,6"). + addMaintenanceHatch("Any bottom casing", 1). + addInputBus("Any bottom casing", 1). + addOutputBus("Any bottom casing", 1). + addEnergyHatch("Bottom and top middle", 2). + toolTipFinisher("Bartworks"); + return tt; + } + @Override public boolean checkRecipe(ItemStack aStack) { @@ -94,7 +197,7 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity return false; } - + @Override public boolean drainEnergyInput(long aEU) { if (aEU <= 0) return true; @@ -103,7 +206,7 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity if(!h1.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU/2, false) || !h2.getBaseMetaTileEntity().decreaseStoredEnergyUnits(aEU/2, false)) return false; return true; } - + @Override public boolean onRunningTick(ItemStack aStack) { if (this.mRuntime % 10 == 0) @@ -111,17 +214,16 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity return super.onRunningTick(aStack); } + @Override + public boolean isCorrectMachinePart(ItemStack itemStack) { + return true; + } + public void stopMachine() { this.resetPiston(); super.stopMachine(); } - @Override - public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - if (this.piston == null) - this.piston = true; - } - private void resetPiston() { if (this.getBaseMetaTileEntity().getWorld().isRemote) return; @@ -174,75 +276,27 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity @Override public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setBoolean("piston", this.piston); super.saveNBTData(aNBT); + aNBT.setBoolean("piston", this.piston); } @Override public void loadNBTData(NBTTagCompound aNBT) { - this.piston = aNBT.getBoolean("piston"); super.loadNBTData(aNBT); + this.piston = aNBT.getBoolean("piston"); } @Override - @SuppressWarnings("ALL") public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) { - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - - for (int x = -1; x <= 1; x++) { - for (int y = -2; y < 7; y++) { - for (int z = -1; z <= 1; z++) { - IGregTechTileEntity te = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, y, z + zDir); - if (y == -2 || y == 6) { - if (!(x == 0 && z == 0)) { - if (!this.addMaintenanceToMachineList(te, 16) && !this.addInputToMachineList(te, 16) && !this.addOutputToMachineList(te, 16)) { - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z); - if ((tBlock != GregTech_API.sBlockCasings2 || tMeta != 0) && (tBlock != GregTech_API.sBlockCasings3 || tMeta != 4)) { - return false; - } - } - } else if (x == 0 && z == 0) { - if (y == -2) - if (!this.addEnergyInputToMachineList(te, 16)) - return false; - if (y == 6) - if (!this.addEnergyInputToMachineList(te, 16)) - return false; - } - } else if ((y > -2 && y < 1) || (y > 3 && y < 6)) { - if (y == 0 && xDir + x == 0 && zDir + z == 0) - continue; - Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z); - byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z); - if (x == 0 && z == 0) { - if (tBlock != BW_BLOCKS[2] || tMeta != 0) - return false; - } else { - if (tBlock != BW_BLOCKS[2] || tMeta != 1) - return false; - } + if(!checkPiece(STRUCTURE_PIECE_MAIN, 1, 6, 0)) + return false; + return this.mMaintenanceHatches.size() == 1 && + this.mEnergyHatches.size() == 2; + } - } else if (y == 1) { - if (!GT_Utility.areStacksEqual(new ItemStack(aBaseMetaTileEntity.getBlockOffset(xDir + x, 1, zDir + z), 1, aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 1, zDir + z)), Materials.Neutronium.getBlocks(1))) - return false; - } else if (y == 2) { - if (!this.piston) { - if (Math.abs(x) == 1 && Math.abs(z) == 1) { - if (!GT_Utility.areStacksEqual(new ItemStack(aBaseMetaTileEntity.getBlockOffset(xDir + x, 2, zDir + z), 1, aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 2, zDir + z)), Materials.Neutronium.getBlocks(1))) - return false; - } - } else if (!GT_Utility.areStacksEqual(new ItemStack(aBaseMetaTileEntity.getBlockOffset(xDir + x, 2, zDir + z), 1, aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z)), Materials.Neutronium.getBlocks(1))) - return false; - } else if (y == 3) { - if (!GT_Utility.areStacksEqual(new ItemStack(aBaseMetaTileEntity.getBlockOffset(xDir + x, 3, zDir + z), 1, aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 3, zDir + z)), Materials.Neutronium.getBlocks(1))) - return false; - } - } - } - } - return true; + @Override + public int getMaxEfficiency(ItemStack itemStack) { + return 10000; } @@ -251,13 +305,31 @@ public class GT_TileEntity_ElectricImplosionCompressor extends GT_MetaTileEntity return 0; } + @Override + public int getDamageToComponent(ItemStack itemStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack itemStack) { + return false; + } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { return new GT_TileEntity_ElectricImplosionCompressor(this.mName); } + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + return aActive ? new ITexture[]{Textures.BlockIcons.casingTexturePages[0][16], TextureFactory.builder().addIcon(new IIconContainer[]{Textures.BlockIcons.OVERLAY_FRONT_IMPLOSION_COMPRESSOR_ACTIVE}).extFacing().build(), TextureFactory.builder().addIcon(new IIconContainer[]{Textures.BlockIcons.OVERLAY_FRONT_IMPLOSION_COMPRESSOR_ACTIVE_GLOW}).extFacing().glow().build()} : new ITexture[]{Textures.BlockIcons.casingTexturePages[0][16], TextureFactory.builder().addIcon(new IIconContainer[]{Textures.BlockIcons.OVERLAY_FRONT_IMPLOSION_COMPRESSOR}).extFacing().build(), TextureFactory.builder().addIcon(new IIconContainer[]{Textures.BlockIcons.OVERLAY_FRONT_IMPLOSION_COMPRESSOR_GLOW}).extFacing().glow().build()}; + } else { + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][16]}; + } + } + @Override - public String[] getDescription() { - return BW_Tooltip_Reference.getTranslatedBrandedTooltip("tooltip.tile.eic.0.name"); + public void construct(ItemStack itemStack, boolean b) { + buildPiece(STRUCTURE_PIECE_MAIN, itemStack, b, 1, 6, 0); } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ManualTrafo.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ManualTrafo.java index e3b3e64753..a4fab93440 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ManualTrafo.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_ManualTrafo.java @@ -22,34 +22,35 @@ package com.github.bartimaeusnek.bartworks.common.tileentities.multis; -import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry; -import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.metatileentity.implementations.*; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import static com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry.BW_BLOCKS; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; -public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_MultiBlockBase { +public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_EnhancedMultiBlockBase { - private static final byte SINGLE_UPSTEP = 0; - private static final byte SINGLE_DOWNSTEP = 1; - private static final byte MULTI_UPSTEP = 2; - private static final byte MULTI_DOWNSTEP = 3; private byte mode; - private byte texid = 2; - private long mCoilWicks; + private int mTiers; private boolean upstep = true; public GT_TileEntity_ManualTrafo(int aID, String aName, String aNameRegional) { @@ -60,6 +61,96 @@ public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_MultiBlockBase super(aName); } + private static final int CASING_INDEX = 2; + private static final String STRUCTURE_PIECE_BASE = "base"; + private static final String STRUCTURE_PIECE_LAYER = "layer"; + private static final String STRUCTURE_PIECE_TOP = "top"; + private static final String STRUCTURE_PIECE_TAP_LAYER = "taplayer"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ + {"b~b", "bbb", "bbb"} + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ + {"ttt", "tft", "ttt"} + })) + .addShape(STRUCTURE_PIECE_TOP, transpose(new String[][]{ + {"ooo", "ooo", "ooo"} + })) + .addShape(STRUCTURE_PIECE_TAP_LAYER, transpose(new String[][]{ + {" TTT ", "TtttT", "TtftT", "TtttT", " TTT "} + })) + .addElement('b', ofChain( + ofHatchAdder(GT_TileEntity_ManualTrafo::addEnergyInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GT_TileEntity_ManualTrafo::addMaintenanceToMachineList, CASING_INDEX, 1), + ofBlock(GregTech_API.sBlockCasings1, 2) + )) + .addElement('o', ofHatchAdderOptional(GT_TileEntity_ManualTrafo::addDynamoToMachineList, CASING_INDEX, 2, GregTech_API.sBlockCasings1, 2)) + .addElement('t', ofBlock(BW_BLOCKS[2], 1)) + .addElement('f', ofBlock(BW_BLOCKS[2], 0)) + .addElement('T', new IStructureElementNoPlacement() { + @Override + public boolean check(GT_TileEntity_ManualTrafo te, World world, int x, int y, int z) { + if(world.isAirBlock(x, y, z)) + return true; + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity == null) + return true; + if(!(tileEntity instanceof IGregTechTileEntity)) + return true; + IMetaTileEntity mte = ((IGregTechTileEntity) tileEntity).getMetaTileEntity(); + if(mte instanceof GT_MetaTileEntity_Hatch_Dynamo || mte instanceof GT_MetaTileEntity_Hatch_Energy) { + int intier = te.mEnergyHatches.get(0).mTier; + if(((GT_MetaTileEntity_TieredMachineBlock) mte).mTier == intier + (te.upstep ? te.mTiers : -te.mTiers)){ + te.addToMachineList((IGregTechTileEntity)tileEntity, CASING_INDEX); + return true; + } + else + return false; + } + return true; + } + + @Override + public boolean spawnHint(GT_TileEntity_ManualTrafo te, World world, int x, int y, int z, ItemStack itemStack) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 2 /* aDots: 3 */); + return true; + } + } + ) + .build(); + + @Override + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Transformer") + .addInfo("Controller block for the Manual Trafo") + .addInfo("Operates in 4 diffrent modes:") + .addInfo("Mode 1: Circuit 0 in controller: Direct-Upstep") + .addInfo("Mode 2: Circuit 1 in controller: Direct-Downstep") + .addInfo("Mode 3: Circuit 2 in controller: Tapped-Upstep (currently disabled)") + .addInfo("Mode 4: Circuit 2 in controller: Tapped-Downstep (currently disabled)") + .addSeparator() + .beginVariableStructureBlock(3, 3, 3, 10, 3, 3, false) + .addController("Front bottom center") + .addCasingInfo("MV Machine Casing", 0) + .addOtherStructurePart("Transformer-Winding Blocks", "1 Layer for each tier transformed") + .addOtherStructurePart("Nickel-Zinc-Ferrite Blocks", "Middle of Transformer-Winding Blocks") + .addMaintenanceHatch("Any bottom layer casing", 1) + .addEnergyHatch("Any bottom layer casing", 1) + .addDynamoHatch("Any top layer casing", 2) + .addStructureInfo("---------TAPPED MODE---------") + .addEnergyHatch("Touching Transformer-Winding Blocks", 3) + .addDynamoHatch("Touching Transformer-Winding Blocks", 3) + .addStructureInfo("Hatches touching Transformer-Winding Blocks must be tiered from bottom to top") + .toolTipFinisher("Bartworks"); + return tt; + } + @Override public boolean isCorrectMachinePart(ItemStack itemStack) { return true; @@ -88,8 +179,8 @@ public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_MultiBlockBase else this.mEfficiency = this.getMaxEfficiency(null); - if (this.mode > GT_TileEntity_ManualTrafo.SINGLE_DOWNSTEP) { - return this.onRunningTickTabbedMode(); + if (this.mode > 1) { + return false;//this.onRunningTickTabbedMode(); Tapped mode is disable } return this.drainEnergyInput(this.getInputTier() * 2 * this.mEnergyHatches.size()) && this.addEnergyOutput(this.getInputTier() * 2 * this.mEnergyHatches.size() * (long) this.mEfficiency / this.getMaxEfficiency(null)); @@ -135,215 +226,64 @@ public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_MultiBlockBase this.stopMachine(); return false; } - this.mode = this.mInventory[1] == null ? 0 : this.mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit") ? this.mInventory[1].getItemDamage() > 4 ? (byte) this.mInventory[1].getItemDamage() : 0 : 0; - this.upstep = (this.mode == 0 || this.mode == 2); + if(itemStack == null || !itemStack.getUnlocalizedName().startsWith("gt.integrated_circuit")) + this.mode = 0; + else + this.mode = (byte)Math.min(3, itemStack.getItemDamage()); + this.upstep = this.mode % 2 == 0; this.mProgresstime = 0; this.mMaxProgresstime = 1; this.mEfficiency = Math.max(this.mEfficiency, 100); - return this.upstep ? this.getOutputTier() - this.getInputTier() == this.mCoilWicks : this.getInputTier() - this.getOutputTier() == this.mCoilWicks; + return this.upstep ? this.getOutputTier() - this.getInputTier() == this.mTiers : this.getInputTier() - this.getOutputTier() == this.mTiers; } @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) { - this.mode = this.mInventory[1] == null ? 0 : this.mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit") ? this.mInventory[1].getItemDamage() > 4 ? (byte) this.mInventory[1].getItemDamage() : 0 : 0; - - if (this.mode <= 1) { - - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; - - //check height - int y = 1; - boolean stillcoil = true; - while (stillcoil) { - for (int x = -1; x <= 1; ++x) { - for (int z = -1; z <= 1; ++z) { - if (x != 0 || z != 0) { - stillcoil = aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z).equals(ItemRegistry.BW_BLOCKS[2]) && aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z) == 1; - if (stillcoil) { - ++this.mCoilWicks; - if (this.mCoilWicks % 8 == 0) { - ++y; - } - } else - break; - } - } - if (!stillcoil) - break; - } - } + if(itemStack == null || !itemStack.getUnlocalizedName().startsWith("gt.integrated_circuit")) + this.mode = 0; + else + this.mode = (byte)Math.min(3, itemStack.getItemDamage()); - if (this.mCoilWicks % 8 != 0) - return false; - - this.mCoilWicks = this.mCoilWicks / 8; - - //check interior (NiFeZn02 Core) - for (int i = 1; i <= this.mCoilWicks; ++i) { - if (!aBaseMetaTileEntity.getBlockOffset(xDir, i, zDir).equals(ItemRegistry.BW_BLOCKS[2]) && aBaseMetaTileEntity.getMetaIDOffset(xDir, i, zDir) == 0) { - return false; - } - } + this.upstep = this.mode % 2 == 0; + boolean tapmode = this.mode > 1; - //check Bottom - for (int x = -1; x <= 1; ++x) - for (int z = -1; z <= 1; ++z) - if (xDir + x != 0 || zDir + z != 0) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, 0, zDir + z); - if (!this.addMaintenanceToMachineList(tTileEntity, this.texid) && !this.addEnergyInputToMachineList(tTileEntity, this.texid)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 0, zDir + z) != GregTech_API.sBlockCasings1) { - return false; - } - /* - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 0, zDir + z) != 11) { - return false; - } - */ - } - } - - //check Top - for (int x = -1; x <= 1; ++x) - for (int z = -1; z <= 1; ++z) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, (int) this.mCoilWicks + 1, zDir + z); - if (!this.addMaintenanceToMachineList(tTileEntity, this.texid) && !this.addDynamoToMachineList(tTileEntity, this.texid)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + x, (int) this.mCoilWicks + 1, zDir + z) != GregTech_API.sBlockCasings1) { - return false; - } - /* - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 0, zDir + z) != 11) { - return false; - } - */ - } - } - - // check dynamos and energy hatches for the same tier - byte outtier = this.mDynamoHatches.get(0).mTier; - for (GT_MetaTileEntity_Hatch_Dynamo out : this.mDynamoHatches) { - if (out.mTier != outtier) - return false; - } + if(!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) + return false; - byte intier = this.mEnergyHatches.get(0).mTier; - for (GT_MetaTileEntity_Hatch_Energy in : this.mEnergyHatches) { - if (in.mTier != intier) - return false; - } - } else { - - int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; - int yDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetY * 2; - int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; - //check height - int y = 1; - boolean stillcoil = true; - while (stillcoil) { - for (int x = -1; x <= 1; ++x) { - for (int z = -1; z <= 1; ++z) { - if (x != 0 || z != 0) { - stillcoil = aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z).equals(ItemRegistry.BW_BLOCKS[2]) && aBaseMetaTileEntity.getMetaIDOffset(xDir + x, y, zDir + z) == 1; - if (stillcoil) { - ++this.mCoilWicks; - if (this.mCoilWicks % 8 == 0) { - ++y; - } - } else - break; - } - } - if (!stillcoil) - break; - } - } + if(this.mEnergyHatches.size() == 0) + return false; - if (this.mCoilWicks % 8 != 0) + byte intier = this.mEnergyHatches.get(0).mTier; + for (GT_MetaTileEntity_Hatch_Energy in : this.mEnergyHatches) + if (in.mTier != intier) return false; - this.mCoilWicks = this.mCoilWicks / 8; - - //check interior (NiFeZn02 Core) - for (int i = 1; i <= this.mCoilWicks; ++i) { - if (!aBaseMetaTileEntity.getBlockOffset(xDir, i, zDir).equals(ItemRegistry.BW_BLOCKS[2]) && aBaseMetaTileEntity.getMetaIDOffset(xDir, i, zDir) == 0) { - return false; - } + int mHeight; + for(mHeight = 1; mHeight <= 8; mHeight++) { + if(tapmode) + { + this.mTiers = mHeight; + if(!checkPiece(STRUCTURE_PIECE_TAP_LAYER, 2, mHeight, 1)) + break; } + else if (!checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0)) + break; + } + if (!checkPiece(STRUCTURE_PIECE_TOP, 1, mHeight, 0)) + return false; + this.mTiers = mHeight - 1; - //check Bottom - for (int x = -2; x <= 2; ++x) - for (int z = -2; z <= 2; ++z) - if (xDir + x != 0 || zDir + z != 0) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, 0, zDir + z); - if (!this.addMaintenanceToMachineList(tTileEntity, this.texid) && !this.addEnergyInputToMachineList(tTileEntity, this.texid)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 0, zDir + z) != GregTech_API.sBlockCasings1) { - return false; - } - /* - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 0, zDir + z) != 11) { - return false; - } - */ - } - } - - //check Top - for (int x = -2; x <= 2; ++x) - for (int z = -2; z <= 2; ++z) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, (int) this.mCoilWicks + 1, zDir + z); - if (!this.addMaintenanceToMachineList(tTileEntity, this.texid) && !this.addDynamoToMachineList(tTileEntity, this.texid)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + x, (int) this.mCoilWicks + 1, zDir + z) != GregTech_API.sBlockCasings1) { - return false; - } - /* - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + x, 0, zDir + z) != 11) { - return false; - } - */ - } - } + if (this.mDynamoHatches.size() == 0 || mMaintenanceHatches.size() != 1 || this.mTiers == 0) + return false; - if (this.mDynamoHatches.size() <= 0 || this.mEnergyHatches.size() <= 0) + byte outtier = this.mDynamoHatches.get(0).mTier; + for (GT_MetaTileEntity_Hatch_Dynamo out : this.mDynamoHatches) { + if (out.mTier != outtier) return false; - - byte outtier = this.mDynamoHatches.get(0).mTier; - for (GT_MetaTileEntity_Hatch_Dynamo out : this.mDynamoHatches) { - if (out.mTier != outtier) - return false; - } - - byte intier = this.mEnergyHatches.get(0).mTier; - for (GT_MetaTileEntity_Hatch_Energy in : this.mEnergyHatches) { - if (in.mTier != intier) - return false; - } - - - //check tap hull - for (int ty = 1; ty <= y; ++ty) { - - byte leveltier; - if (this.mInventory[1].getItemDamage() == 2) - leveltier = ((byte) (intier - ty)); - else if (this.mInventory[1].getItemDamage() == 3) - leveltier = ((byte) (intier + ty)); - else - return false; - - for (int x = -2; x <= 2; ++x) - for (int z = -2; z <= 2; ++z) - if (x == -2 || z == -2 || x == 2 || z == 2) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + x, ty, zDir + z); - if (!this.addMaintenanceToMachineList(tTileEntity, this.texid) && !this.addEnergyInputToMachineList(tTileEntity, this.texid, leveltier) && !this.addDynamoToMachineList(tTileEntity, this.texid, leveltier)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + x, ty, zDir + z) != GregTech_API.sBlockCasings1) { - return false; - } - } - } - } } - return !this.mDynamoHatches.isEmpty() && !this.mEnergyHatches.isEmpty(); + + return true; } @Override @@ -371,64 +311,53 @@ public class GT_TileEntity_ManualTrafo extends GT_MetaTileEntity_MultiBlockBase return new GT_TileEntity_ManualTrafo(this.mName); } - @Override - public String[] getDescription() { - return BW_Tooltip_Reference.getTranslatedBrandedTooltip("tooltip.tile.manualtravo.0.name"); - } - @Override public void saveNBTData(NBTTagCompound ntag) { - ntag.setLong("mCoilWicks", this.mCoilWicks); super.saveNBTData(ntag); + ntag.setInteger("mTiers", this.mTiers); + ntag.setByte("mMode", this.mode); + ntag.setBoolean("upstep", this.upstep); } @Override public void loadNBTData(NBTTagCompound ntag) { super.loadNBTData(ntag); - this.mCoilWicks = ntag.getLong("mCoilWicks"); + this.mTiers = ntag.getInteger("mTiers"); + this.mode = ntag.getByte("mMode"); + this.upstep = ntag.getBoolean("upstep"); } @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - return aSide == aFacing ? new ITexture[]{Textures.BlockIcons.getCasingTextureForId(this.texid), TextureFactory.of(aActive ? TextureFactory.of(TextureFactory.of(Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE), TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW).glow().build()) : TextureFactory.of(TextureFactory.of(Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE), TextureFactory.builder().addIcon(Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW).glow().build()))} : new ITexture[]{Textures.BlockIcons.getCasingTextureForId(this.texid)}; - } - - public boolean addEnergyInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex, short tier) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { - if (tier == ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mTier) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); - return this.mEnergyHatches.add((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity); - } - return false; - } else { - return false; - } + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW).extFacing().glow().build()}; + return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(CASING_INDEX), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE).extFacing().build(), + TextureFactory.builder().addIcon(OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW).extFacing().glow().build()}; } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(CASING_INDEX)}; } - public boolean addDynamoToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex, short tier) { - if (aTileEntity == null) { - return false; - } else { - IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity == null) { - return false; - } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { - if (tier == ((GT_MetaTileEntity_Hatch) aMetaTileEntity).mTier) { - ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); - return this.mDynamoHatches.add((GT_MetaTileEntity_Hatch_Dynamo) aMetaTileEntity); - } - return false; - } else { - return false; - } + @Override + public void construct(ItemStack itemStack, boolean b) { + if(this.mInventory[1] == null || !this.mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit")) + this.mode = 0; + else + this.mode = (byte)Math.min(3, this.mInventory[1].getItemDamage()); + int mHeight = Math.min(itemStack.stackSize, 8); + boolean tapmode = this.mode > 1; + buildPiece(STRUCTURE_PIECE_BASE, itemStack, b, 1, 0, 0); + for(int i = 0; i < mHeight; i++) { + if (tapmode) + buildPiece(STRUCTURE_PIECE_TAP_LAYER, itemStack, b, 2, i + 1, 1); + else + buildPiece(STRUCTURE_PIECE_LAYER, itemStack, b, 1, i + 1, 0); } + buildPiece(STRUCTURE_PIECE_TOP, itemStack, b, 1, mHeight + 1, 0); } - } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_Windmill.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_Windmill.java index bb7ac747ad..15deb54ac4 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_Windmill.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_Windmill.java @@ -26,8 +26,11 @@ import com.github.bartimaeusnek.bartworks.MainMod; import com.github.bartimaeusnek.bartworks.client.gui.BW_GUIContainer_Windmill; import com.github.bartimaeusnek.bartworks.common.tileentities.classic.BW_RotorBlock; import com.github.bartimaeusnek.bartworks.server.container.BW_Container_Windmill; -import com.github.bartimaeusnek.bartworks.util.BW_Tooltip_Reference; import com.github.bartimaeusnek.bartworks.util.BW_Util; +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -39,9 +42,10 @@ import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; import gregtech.api.objects.XSTR; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; @@ -55,15 +59,16 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityDispenser; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.util.ForgeDirection; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static gregtech.api.enums.GT_Values.V; -public class GT_TileEntity_Windmill extends GT_MetaTileEntity_MultiBlockBase { +public class GT_TileEntity_Windmill extends GT_MetaTileEntity_EnhancedMultiBlockBase { private static final IIcon[] iIcons = new IIcon[2]; private static final IIconContainer[] iIconContainers = new IIconContainer[2]; @@ -71,7 +76,8 @@ public class GT_TileEntity_Windmill extends GT_MetaTileEntity_MultiBlockBase { private static final XSTR localRandomInstance = new XSTR(); private BW_RotorBlock rotorBlock; - private byte hasDoor; + private int mDoor = 0; + private int mHardenedClay = 0; public GT_TileEntity_Windmill(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -81,6 +87,62 @@ public class GT_TileEntity_Windmill extends GT_MetaTileEntity_MultiBlockBase { super(aName); } + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{ + {" ", " ", " ", " p ", " ", " ", " "}, + {" ", " ", " ppp ", " p p ", " ppp ", " ", " "}, + {" ", " ppppp ", " p p ", " p p ", " p p ", " ppppp ", " "}, + {" ppppp ", "p p", "p p", "p p", "p p", "p p", " ppppp "}, + {" ppspp ", "p p", "p p", "p p", "p p", "p p", " ppppp "}, + {" ppppp ", "p p", "p p", "p p", "p p", "p p", " ppppp "}, + {" ", " ppppp ", " p p ", " p p ", " p p ", " ppppp ", " "}, + {" ", " ccc ", " c c ", " c c ", " c c ", " ccc ", " "}, + {" ", " ccc ", " c c ", " c c ", " c c ", " ccc ", " "}, + {" ", " ccc ", " c c ", " c c ", " c c ", " ccc ", " "}, + {" ", " ccc ", " c c ", " c c ", " c c ", " ccc ", " "}, + {" bb~bb ", "bbbbbbb", "bbbbbbb", "bbbbbbb", "bbbbbbb", "bbbbbbb", " bbbbb "}, + })) + .addElement('p', ofBlockAnyMeta(Blocks.planks)) + .addElement('c', ofChain( + onElementPass(t -> t.mHardenedClay++, ofBlock(Blocks.hardened_clay, 0)), + ofTileAdder(GT_TileEntity_Windmill::addDispenserToOutputSet, Blocks.hardened_clay, 0), + onElementPass(t -> t.mDoor++, ofBlock(Blocks.wooden_door, 0)) + )) + .addElement('b', ofBlock(Blocks.brick_block, 0)) + .addElement('s', ofTileAdder(GT_TileEntity_Windmill::setRotorBlock, StructureLibAPI.getBlockHint(), 0)) + .build(); + + @Override + public IStructureDefinition getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && f.isNotFlipped(); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt. + addMachineType("Windmill"). + addInfo("Controller block for the Windmill"). + addInfo("A primitive Grinder powered by Kinetic energy"). + addInfo("The structure is too complex!"). + addInfo("Follow the StructureLib hologram projector to build the main structure."). + addSeparator(). + beginStructureBlock(7, 12, 7, false). + addController("Front bottom center"). + addCasingInfo("Hardened Clay block", 40). + addOtherStructurePart("Dispenser", "Any Hardened Clay block"). + addOtherStructurePart("0-1 Wooden door", "Any Hardened Clay block"). + addStructureHint("Primitive Kinetic Shaftbox", 1). + toolTipFinisher("Bartworks"); + return tt; + } + @Override public boolean isCorrectMachinePart(ItemStack itemStack) { return true; @@ -368,6 +430,14 @@ public class GT_TileEntity_Windmill extends GT_MetaTileEntity_MultiBlockBase { return false; } + public boolean setRotorBlock(TileEntity aTileEntity){ + if (aTileEntity instanceof BW_RotorBlock) { + this.rotorBlock = (BW_RotorBlock) aTileEntity; +