From 5d3a02a84779d1381620bc27dc3807726ffcf46d Mon Sep 17 00:00:00 2001 From: Tec Date: Sun, 19 Apr 2020 23:16:28 +0200 Subject: Idk why but ok --- .../tectech/mechanics/alignment/IntegerAxisSwap.java | 17 +++++++++++++++++ .../mechanics/alignment/enumerable/ExtendedFacing.java | 7 +++++++ 2 files changed, 24 insertions(+) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/mechanics/alignment/IntegerAxisSwap.java b/src/main/java/com/github/technus/tectech/mechanics/alignment/IntegerAxisSwap.java index 40cb6c3220..1c44164731 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/alignment/IntegerAxisSwap.java +++ b/src/main/java/com/github/technus/tectech/mechanics/alignment/IntegerAxisSwap.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.mechanics.alignment; import com.github.technus.tectech.util.Vec3Impl; +import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import static com.github.technus.tectech.mechanics.alignment.enumerable.Direction.getAxisVector; @@ -40,6 +41,22 @@ public class IntegerAxisSwap { forFirstAxis.get2()*point.get0()+forSecondAxis.get2()*point.get1()+forThirdAxis.get2()*point.get2() ); } + + public Vec3 translate(Vec3 point){ + return Vec3.createVectorHelper( + forFirstAxis.get0()*point.xCoord +forFirstAxis.get1()*point.yCoord +forFirstAxis.get2()*point.zCoord, + forSecondAxis.get0()*point.xCoord+forSecondAxis.get1()*point.yCoord+forSecondAxis.get2()*point.zCoord, + forThirdAxis.get0()*point.xCoord +forThirdAxis.get1()*point.yCoord +forThirdAxis.get2()*point.zCoord + ); + } + + public Vec3 inverseTranslate(Vec3 point){ + return Vec3.createVectorHelper( + forFirstAxis.get0()*point.xCoord+forSecondAxis.get0()*point.yCoord+forThirdAxis.get0()*point.zCoord, + forFirstAxis.get1()*point.xCoord+forSecondAxis.get1()*point.yCoord+forThirdAxis.get1()*point.zCoord, + forFirstAxis.get2()*point.xCoord+forSecondAxis.get2()*point.yCoord+forThirdAxis.get2()*point.zCoord + ); + } public void translate(int[] point,int[] out){ out[0]=forFirstAxis.get0()*point[0] +forFirstAxis.get1()*point[1] +forFirstAxis.get2()*point[2]; diff --git a/src/main/java/com/github/technus/tectech/mechanics/alignment/enumerable/ExtendedFacing.java b/src/main/java/com/github/technus/tectech/mechanics/alignment/enumerable/ExtendedFacing.java index 68cc50a5ee..5c8c902484 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/alignment/enumerable/ExtendedFacing.java +++ b/src/main/java/com/github/technus/tectech/mechanics/alignment/enumerable/ExtendedFacing.java @@ -3,6 +3,7 @@ package com.github.technus.tectech.mechanics.alignment.enumerable; import com.github.technus.tectech.mechanics.alignment.IAlignment; import com.github.technus.tectech.mechanics.alignment.IntegerAxisSwap; import com.github.technus.tectech.util.Vec3Impl; +import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; import java.util.*; @@ -292,6 +293,9 @@ public enum ExtendedFacing { * @param abcOffset A,B,C offset (facing relative L-->R,U-->D,F-->B) * @return X,Y,Z offset in world */ + public Vec3 getWorldOffset(Vec3 abcOffset) { + return integerAxisSwap.inverseTranslate(abcOffset); + } public Vec3Impl getWorldOffset(Vec3Impl abcOffset) { return integerAxisSwap.inverseTranslate(abcOffset); } @@ -308,6 +312,9 @@ public enum ExtendedFacing { * @param xyzOffset X,Y,Z offset in world * @return A,B,C offset (facing relative L-->R,U-->D,F-->B) */ + public Vec3 getOffsetABC(Vec3 xyzOffset){ + return integerAxisSwap.translate(xyzOffset); + } public Vec3Impl getOffsetABC(Vec3Impl xyzOffset){ return integerAxisSwap.translate(xyzOffset); } -- cgit From 1fbd3db52ce5e81ffdf563f4c498001b49ba2cbc Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 20 Apr 2020 06:53:12 +0200 Subject: Refactor to provider and add another helper method for compatiblility --- .../tectech/mechanics/alignment/IAlignment.java | 32 ++++++++++++++++------ .../mechanics/alignment/IAlignmentProvider.java | 5 ++++ .../thing/item/FrontRotationTriggerItem.java | 15 ++++++---- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 3 +- .../render/TT_RenderedExtendedFacingTexture.java | 8 ++++-- 5 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignmentProvider.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignment.java b/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignment.java index d7b48f8865..a2a6301070 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignment.java +++ b/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignment.java @@ -8,12 +8,25 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.Arrays; -public interface IAlignment extends IAlignmentLimits { +public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { int DIRECTIONS_COUNT= Direction.VALUES.length; int ROTATIONS_COUNT= Rotation.VALUES.length; int FLIPS_COUNT= Flip.VALUES.length; int STATES_COUNT = ExtendedFacing.VALUES.length; + ExtendedFacing getExtendedFacing(); + + void setExtendedFacing(ExtendedFacing alignment); + + IAlignmentLimits getAlignmentLimits(); + + void setAlignmentLimits(IAlignmentLimits limits); + + @Override + default IAlignment getAlignment(){ + return this; + } + static int getAlignmentIndex(ForgeDirection direction, Rotation rotation, Flip flip){ return (direction.ordinal()*ROTATIONS_COUNT+rotation.getIndex())*FLIPS_COUNT+flip.getIndex(); } @@ -42,14 +55,6 @@ public interface IAlignment extends IAlignmentLimits { setExtendedFacing(getExtendedFacing().with(flip)); } - ExtendedFacing getExtendedFacing(); - - void setExtendedFacing(ExtendedFacing alignment); - - IAlignmentLimits getAlignmentLimits(); - - void setAlignmentLimits(IAlignmentLimits limits); - default boolean toolSetDirection(ForgeDirection direction){ if(direction==null || direction==ForgeDirection.UNKNOWN){ for (int i = 0,j=getDirection().ordinal()+1, valuesLength = Direction.VALUES.length; i < valuesLength; i++) { @@ -75,6 +80,15 @@ public interface IAlignment extends IAlignmentLimits { return false; } + default boolean canSetToDirectionAny(ForgeDirection direction){ + for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) { + if(isNewExtendedFacingValid(extendedFacing)){ + return true; + } + } + return false; + } + default boolean toolSetRotation(Rotation rotation) { if(rotation==null){ int flips = Flip.VALUES.length; diff --git a/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignmentProvider.java b/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignmentProvider.java new file mode 100644 index 0000000000..07dc972aac --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/alignment/IAlignmentProvider.java @@ -0,0 +1,5 @@ +package com.github.technus.tectech.mechanics.alignment; + +public interface IAlignmentProvider { + IAlignment getAlignment(); +} \ No newline at end of file diff --git a/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java b/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java index efcfcfb7a3..5edc238a91 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java +++ b/src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.item; import com.github.technus.tectech.mechanics.alignment.IAlignment; +import com.github.technus.tectech.mechanics.alignment.IAlignmentProvider; import com.github.technus.tectech.util.CommonValues; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -42,19 +43,21 @@ public final class FrontRotationTriggerItem extends Item { if (aPlayer instanceof EntityPlayerMP) { if (tTileEntity instanceof IGregTechTileEntity) { IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (metaTE instanceof IAlignment) { + if (metaTE instanceof IAlignmentProvider) { + IAlignment alignment = ((IAlignmentProvider) metaTE).getAlignment(); if(aPlayer.isSneaking()){ - ((IAlignment) metaTE).toolSetFlip(null); + alignment.toolSetFlip(null); }else { - ((IAlignment) metaTE).toolSetRotation(null); + alignment.toolSetRotation(null); } return true; } - } else if (tTileEntity instanceof IAlignment) { + } else if (tTileEntity instanceof IAlignmentProvider) { + IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment(); if(aPlayer.isSneaking()){ - ((IAlignment) tTileEntity).toolSetFlip(null); + alignment.toolSetFlip(null); }else { - ((IAlignment) tTileEntity).toolSetRotation(null); + alignment.toolSetRotation(null); } return true; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index 52bdd3574f..50e2aa575b 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -183,8 +183,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt @Override public boolean isFacingValid(byte aFacing) { - return getAlignmentLimits() - .isNewExtendedFacingValid(getExtendedFacing().with(ForgeDirection.getOrientation(aFacing))); + return canSetToDirectionAny(ForgeDirection.getOrientation(aFacing)); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/render/TT_RenderedExtendedFacingTexture.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/render/TT_RenderedExtendedFacingTexture.java index 4ecea706cc..44fa12ebb8 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/render/TT_RenderedExtendedFacingTexture.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/render/TT_RenderedExtendedFacingTexture.java @@ -1,6 +1,6 @@ package com.github.technus.tectech.thing.metaTileEntity.multi.base.render; -import com.github.technus.tectech.mechanics.alignment.IAlignment; +import com.github.technus.tectech.mechanics.alignment.IAlignmentProvider; import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; import gregtech.api.enums.Dyes; import gregtech.api.interfaces.IColorModulationContainer; @@ -881,11 +881,13 @@ public class TT_RenderedExtendedFacingTexture implements ITexture,IColorModulati TileEntity te = w.getTileEntity(x, y, z); if (te instanceof IGregTechTileEntity) { IMetaTileEntity meta = ((IGregTechTileEntity) te).getMetaTileEntity(); - if (meta instanceof IAlignment) { - return ((IAlignment) meta).getExtendedFacing(); + if (meta instanceof IAlignmentProvider) { + return ((IAlignmentProvider) meta).getAlignment().getExtendedFacing(); }else{ return ExtendedFacing.of(ForgeDirection.getOrientation(meta.getBaseMetaTileEntity().getFrontFacing())); } + } else if (te instanceof IAlignmentProvider) { + return ((IAlignmentProvider) te).getAlignment().getExtendedFacing(); } } return ExtendedFacing.DEFAULT; -- cgit From 1c8a7217e61057acb29279a987eff4cafb1a5d78 Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 20 Apr 2020 06:58:16 +0200 Subject: Cleanup util --- src/main/java/com/github/technus/tectech/util/Util.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/util/Util.java b/src/main/java/com/github/technus/tectech/util/Util.java index cd055528b1..7e6e177e77 100644 --- a/src/main/java/com/github/technus/tectech/util/Util.java +++ b/src/main/java/com/github/technus/tectech/util/Util.java @@ -40,6 +40,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -190,10 +191,9 @@ public final class Util { } IGregTechTileEntity igt; - IMetaTileEntity imt = aBaseMetaTileEntity.getMetaTileEntity(); - int xyz[]=new int[3]; - int abc[]=new int[3]; + int[] xyz =new int[3]; + int[] abc =new int[3]; int pointer; int baseX = aBaseMetaTileEntity.getXCoord(), baseZ = aBaseMetaTileEntity.getZCoord(), @@ -336,10 +336,8 @@ public final class Util { } //TE Rotation - - - int xyz[]=new int[3]; - int abc[]=new int[3]; + int[] xyz =new int[3]; + int[] abc =new int[3]; int pointer; int baseX = tileEntity.xCoord, @@ -1045,7 +1043,7 @@ public final class Util { String id1=player.getUniqueID().toString(); write(new File(dir, id1 + "."+extension),data); write(new File(dir, id1 + "."+extension+"_bak"),data); - String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8"))).toString(); + String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(StandardCharsets.UTF_8)).toString(); write(new File(dir, id2 + "."+extension),data); write(new File(dir, id2 + "."+extension+"_bak"),data); } -- cgit From 9360d6afe97e029001f411d819f6d80dafdc95a3 Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 20 Apr 2020 17:19:19 +0200 Subject: Revoctor Structure util to new package, fix typo --- .../GT_MetaTileEntity_EM_essentiaDequantizer.java | 8 +- .../GT_MetaTileEntity_EM_essentiaQuantizer.java | 8 +- .../tectech/loader/ConstructableLoader.java | 47 ++ .../mechanics/constructable/IConstructable.java | 16 + .../constructable/IMultiblockInfoContainer.java | 30 ++ .../tectech/mechanics/constructable/Structure.java | 526 +++++++++++++++++++++ .../mechanics/constructible/IConstructable.java | 15 - .../thing/item/ConstructableTriggerItem.java | 115 ++--- .../multi/GT_MetaTileEntity_EM_annihilation.java | 8 +- .../multi/GT_MetaTileEntity_EM_bhg.java | 12 +- .../multi/GT_MetaTileEntity_EM_collider.java | 12 +- .../multi/GT_MetaTileEntity_EM_computer.java | 18 +- .../multi/GT_MetaTileEntity_EM_crafting.java | 8 +- .../multi/GT_MetaTileEntity_EM_dataBank.java | 8 +- .../multi/GT_MetaTileEntity_EM_decay.java | 8 +- .../multi/GT_MetaTileEntity_EM_dequantizer.java | 8 +- .../multi/GT_MetaTileEntity_EM_infuser.java | 8 +- .../multi/GT_MetaTileEntity_EM_junction.java | 8 +- .../multi/GT_MetaTileEntity_EM_quantizer.java | 8 +- .../multi/GT_MetaTileEntity_EM_research.java | 8 +- .../multi/GT_MetaTileEntity_EM_scanner.java | 8 +- .../multi/GT_MetaTileEntity_EM_stabilizer.java | 8 +- .../multi/GT_MetaTileEntity_EM_switch.java | 8 +- .../multi/GT_MetaTileEntity_EM_transformer.java | 8 +- .../multi/GT_MetaTileEntity_EM_wormhole.java | 8 +- .../multi/GT_MetaTileEntity_TM_microwave.java | 8 +- .../GT_MetaTileEntity_TM_proccessingStack.java | 4 +- .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 7 +- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 4 +- .../em_machine/GT_MetaTileEntity_EM_machine.java | 8 +- .../GT_MetaTileEntity_DebugStructureWriter.java | 6 +- .../java/com/github/technus/tectech/util/Util.java | 522 -------------------- 32 files changed, 772 insertions(+), 706 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/constructable/IConstructable.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/constructable/IMultiblockInfoContainer.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/constructable/Structure.java delete mode 100644 src/main/java/com/github/technus/tectech/mechanics/constructible/IConstructable.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java index ab6b723e09..eb9b97deee 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaDequantizer.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi; +import com.github.technus.tectech.mechanics.constructable.Structure; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.ePrimalAspectDefinition; @@ -7,7 +8,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInsta import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.casing.TT_Container_Casings; -import com.github.technus.tectech.mechanics.constructible.IConstructable; +import com.github.technus.tectech.mechanics.constructable.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_quantizer; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.IHatchAdder; @@ -24,7 +25,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; import static com.github.technus.tectech.util.CommonValues.V; -import static com.github.technus.tectech.util.Util.StructureBuilderExtreme; import static com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi.EssentiaCompat.essentiaContainerCompat; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; @@ -123,7 +123,7 @@ public class GT_MetaTileEntity_EM_essentiaDequantizer extends GT_MetaTileEntity_ } @Override - public void construct(int stackSize, boolean hintsOnly) { + public void construct(ItemStack stackSize, boolean hintsOnly) { IGregTechTileEntity iGregTechTileEntity = getBaseMetaTileEntity(); int xDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetX; int yDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetY; @@ -139,7 +139,7 @@ public class GT_MetaTileEntity_EM_essentiaDequantizer extends GT_MetaTileEntity_ iGregTechTileEntity.getWorld().setBlock(iGregTechTileEntity.getXCoord() + xDir, iGregTechTileEntity.getYCoord() + yDir, iGregTechTileEntity.getZCoord() + zDir, TT_Container_Casings.sHintCasingsTT, 12, 2); } } - StructureBuilderExtreme(shape, blockType, blockMeta, 1, 1, 0, iGregTechTileEntity, getExtendedFacing(), hintsOnly); + Structure.builder(shape, blockType, blockMeta, 1, 1, 0, iGregTechTileEntity, getExtendedFacing(), hintsOnly); } @Override diff --git a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java index 309d029b8e..0259aec7a7 100644 --- a/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java +++ b/src/main/java/com/github/technus/tectech/compatibility/thaumcraft/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_essentiaQuantizer.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi; +import com.github.technus.tectech.mechanics.constructable.Structure; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.compatibility.thaumcraft.elementalMatter.definitions.ePrimalAspectDefinition; @@ -7,7 +8,7 @@ import com.github.technus.tectech.mechanics.elementalMatter.core.cElementalInsta import com.github.technus.tectech.mechanics.elementalMatter.core.stacks.cElementalInstanceStack; import com.github.technus.tectech.thing.block.QuantumGlassBlock; import com.github.technus.tectech.thing.casing.TT_Container_Casings; -import com.github.technus.tectech.mechanics.constructible.IConstructable; +import com.github.technus.tectech.mechanics.constructable.IConstructable; import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_quantizer; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import com.github.technus.tectech.thing.metaTileEntity.multi.base.IHatchAdder; @@ -24,7 +25,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; import static com.github.technus.tectech.util.CommonValues.V; -import static com.github.technus.tectech.util.Util.StructureBuilderExtreme; import static com.github.technus.tectech.compatibility.thaumcraft.thing.metaTileEntity.multi.EssentiaCompat.essentiaContainerCompat; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; @@ -127,7 +127,7 @@ public class GT_MetaTileEntity_EM_essentiaQuantizer extends GT_MetaTileEntity_Mu } @Override - public void construct(int stackSize, boolean hintsOnly) { + public void construct(ItemStack stackSize, boolean hintsOnly) { IGregTechTileEntity iGregTechTileEntity = getBaseMetaTileEntity(); int xDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetX; int yDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetY; @@ -143,7 +143,7 @@ public class GT_MetaTileEntity_EM_essentiaQuantizer extends GT_MetaTileEntity_Mu iGregTechTileEntity.getWorld().setBlock(iGregTechTileEntity.getXCoord() + xDir, iGregTechTileEntity.getYCoord() + yDir, iGregTechTileEntity.getZCoord() + zDir, TT_Container_Casings.sHintCasingsTT, 12, 2); } } - StructureBuilderExtreme(shape, blockType, blockMeta, 1, 1, 0, iGregTechTileEntity, getExtendedFacing(), hintsOnly); + Structure.builder(shape, blockType, blockMeta, 1, 1, 0, iGregTechTileEntity, getExtendedFacing(), hintsOnly); } @Override diff --git a/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java b/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java new file mode 100644 index 0000000000..2dc56754f8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/loader/ConstructableLoader.java @@ -0,0 +1,47 @@ +package com.github.technus.tectech.loader; + +import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer; +import com.github.technus.tectech.mechanics.constructable.Structure; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; + +import static com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer.*; +import static gregtech.api.GregTech_API.sBlockCasings1; + +public class ConstructableLoader implements Runnable { + + @Override + public void run() { + registerMetaClass(GT_MetaTileEntity_ElectricBlastFurnace .class, new IMultiblockInfoContainer() { + //region Structure + private final String[][] shape = new String[][]{ + {"000","\"\"\"","\"\"\""," . ",}, + {"0!0","\"A\"","\"A\""," ",}, + {"000","\"\"\"","\"\"\""," ",}, + }; + private final Block[] blockType = new Block[]{sBlockCasings1}; + private final byte[] blockMeta = new byte[]{11}; + private final String[] desc=new String[]{ + EnumChatFormatting.AQUA+"Hint Details:", + "1 - Classic Hatches or Heat Proof Casing", + "2 - Muffler Hatch", + "3 - Coil blocks" + }; + //endregion + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly, TileEntity tileEntity, ExtendedFacing aSide) { + Structure.builder(shape, blockType, blockMeta, 1, 3, 0, tileEntity, aSide, hintsOnly); + } + + @Override + public String[] getDescription(int stackSize) { + return desc; + } + }); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/constructable/IConstructable.java b/src/main/java/com/github/technus/tectech/mechanics/constructable/IConstructable.java new file mode 100644 index 0000000000..d7c3c86098 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/constructable/IConstructable.java @@ -0,0 +1,16 @@ +package com.github.technus.tectech.mechanics.constructable; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.item.ItemStack; + +/** + * Created by Tec on 24.03.2017. + */ +public interface IConstructable { + void construct(ItemStack stackSize, boolean hintsOnly); + + @SideOnly(Side.CLIENT) + String[] getStructureDescription(int stackSize); +} + diff --git a/src/main/java/com/github/technus/tectech/mechanics/constructable/IMultiblockInfoContainer.java b/src/main/java/com/github/technus/tectech/mechanics/constructable/IMultiblockInfoContainer.java new file mode 100644 index 0000000000..29769fafb8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/constructable/IMultiblockInfoContainer.java @@ -0,0 +1,30 @@ +package com.github.technus.tectech.mechanics.constructable; + +import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import java.util.HashMap; + +/** + * To implement IConstructable on not own TileEntities + */ +public interface IMultiblockInfoContainer { + HashMap MULTIBLOCK_MAP = new HashMap<>(); + + static void registerTileClass(Class clazz, IMultiblockInfoContainer info){ + MULTIBLOCK_MAP.put(clazz.getCanonicalName(),info); + } + + static void registerMetaClass(Class clazz, IMultiblockInfoContainer info){ + MULTIBLOCK_MAP.put(clazz.getCanonicalName(),info); + } + + void construct(ItemStack stackSize, boolean hintsOnly, TileEntity tileEntity, ExtendedFacing aSide); + + @SideOnly(Side.CLIENT) + String[] getDescription(int stackSize); +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/constructable/Structure.java b/src/main/java/com/github/technus/tectech/mechanics/constructable/Structure.java new file mode 100644 index 0000000000..00ffb32525 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/constructable/Structure.java @@ -0,0 +1,526 @@ +package com.github.technus.tectech.mechanics.constructable; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import com.github.technus.tectech.thing.casing.TT_Container_Casings; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.IHatchAdder; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; +import static gregtech.api.enums.GT_Values.E; + +public class Structure { + private static final Pattern matchE_ = Pattern.compile("(E,(E,)+)"); + + private Structure(){} + + //Check Machine Structure based on string[][] (effectively char[][][]), ond offset of the controller + //This only checks for REGULAR BLOCKS! + public static boolean checker( + String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR-1 blocks + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + IHatchAdder[] addingMethods, + short[] casingTextures, + Block[] blockTypeFallback,//use numbers 0-9 for casing types + byte[] blockMetaFallback,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset, + IGregTechTileEntity aBaseMetaTileEntity, + ExtendedFacing extendedFacing, + boolean forceCheck) { + World world = aBaseMetaTileEntity.getWorld(); + if (world.isRemote) { + return false; + } + //TE Rotation + if(extendedFacing==null){ + extendedFacing=ExtendedFacing.of(ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing())); + } + + IGregTechTileEntity igt; + + int[] xyz =new int[3]; + int[] abc =new int[3]; + int pointer; + int baseX = aBaseMetaTileEntity.getXCoord(), + baseZ = aBaseMetaTileEntity.getZCoord(), + baseY = aBaseMetaTileEntity.getYCoord(); + //a,b,c - relative to block face! + //x,y,z - relative to block position on map! + //yPos - absolute height of checked block + + //perform your duties + abc[2] = -depthOffset; + for (String[] _structure : structure) {//front to back + abc[1] = verticalOffset; + for (String __structure : _structure) {//top to bottom + abc[0] = -horizontalOffset; + for (char block : __structure.toCharArray()) {//left to right + if (block < ' ') {//Control chars allow skipping + abc[1] -= block; + break; + } else if (block > '@') {//characters allow to skip check A-1 skip, B-2 skips etc. + abc[0] += block - '@'; + }//else if (block < '+')//used to mark THINGS + // a++; + else if (block == '.') { + abc[0]++; + } else { + //get x y z from rotation + extendedFacing.getWorldOffset(abc,xyz); + xyz[0]+=baseX; + xyz[1]+=baseY; + xyz[2]+=baseZ; + + //that must be here since in some cases other axis (b,c) controls y + if (xyz[1] < 0 || xyz[1] >= 256) { + return false; + } + + //Check block + if (world.blockExists(xyz[0], xyz[1], xyz[2])) {//this actually checks if the chunk is loaded at this pos + switch (block) { + case '-'://must be air + if (world.getBlock(xyz[0], xyz[1], xyz[2]).getMaterial() != Material.air) { + return false; + } + break; + case '+'://must not be air + if (world.getBlock(xyz[0], xyz[1], xyz[2]).getMaterial() == Material.air) { + return false; + } + break; + default://check for block (countable) + if ((pointer = block - '0') >= 0) { + //countable air -> net.minecraft.block.BlockAir + if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockType[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlock(xyz[0], xyz[1], xyz[2]).getUnlocalizedName() + ' ' + blockType[pointer].getUnlocalizedName()); + } + return false; + } + if (world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMeta[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) + ' ' + blockMeta[pointer]); + } + return false; + } + } else //noinspection ConstantConditions + if ((pointer = block - ' ') >= 0) { + igt = aBaseMetaTileEntity.getIGregTechTileEntity(xyz[0], xyz[1], xyz[2]); + if (igt == null || !addingMethods[pointer].apply(igt, casingTextures[pointer])) { + if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockTypeFallback[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Fallback-struct-block-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlock(xyz[0], xyz[1], xyz[2]).getUnlocalizedName() + ' ' + (blockTypeFallback[pointer] == null ? "null" : blockTypeFallback[pointer].getUnlocalizedName())); + } + return false; + } + if (world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMetaFallback[pointer]) { + if (DEBUG_MODE) { + TecTech.LOGGER.info("Fallback-Struct-meta-id-error " + xyz[0] + ' ' + xyz[1] + ' ' + xyz[2] + " / " + abc[0] + ' ' + abc[1] + ' ' + abc[2] + " / " + world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) + ' ' + blockMetaFallback[pointer]); + } + return false; + } + } + } + } + } else if (forceCheck) { + return false; + } + abc[0]++;//block in horizontal layer + } + } + abc[1]--;//horizontal layer + } + abc[2]++;//depth + } + return true; + } + + public static boolean builder(String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR+1 blocks + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset, + IGregTechTileEntity tileEntity, ExtendedFacing extendedFacing, boolean hintsOnly) { + return builder(structure, blockType, blockMeta, horizontalOffset, verticalOffset, depthOffset, + tileEntity.getWorld(),tileEntity.getXCoord(),tileEntity.getYCoord(),tileEntity.getZCoord(), + extendedFacing, hintsOnly); + } + + public static boolean builder(String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR+1 blocks + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset, + TileEntity tileEntity, ExtendedFacing extendedFacing, boolean hintsOnly) { + return builder(structure, blockType, blockMeta, horizontalOffset, verticalOffset, depthOffset, + tileEntity.getWorldObj(),tileEntity.xCoord,tileEntity.yCoord,tileEntity.zCoord, + extendedFacing, hintsOnly); + } + + public static boolean builder(String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR+1 blocks + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset, + World world,int baseX,int baseZ,int baseY, ExtendedFacing extendedFacing, boolean hintsOnly) { + if (world==null || (!world.isRemote && hintsOnly)) { + return false; + } + + //TE Rotation + int[] xyz =new int[3]; + int[] abc =new int[3]; + int pointer; + + //a,b,c - relative to block face! + //x,y,z - relative to block position on map! + + //perform your duties + abc[2] = -depthOffset; + for (String[] _structure : structure) {//front to back + abc[1] = verticalOffset; + for (String __structure : _structure) {//top to bottom + abc[0] = -horizontalOffset; + for (char block : __structure.toCharArray()) {//left to right + if (block < ' ') {//Control chars allow skipping + abc[1] -= block; + break; + } + if (block > '@')//characters allow to skip check a-1 skip, b-2 skips etc. + { + abc[0] += block - '@'; + }//else if (block < '+')//used to mark THINGS + // a++; + else if (block == '.')// this TE + { + abc[0]++; + } else { + //get x y z from rotation + extendedFacing.getWorldOffset(abc,xyz); + xyz[0]+=baseX; + xyz[1]+=baseY; + xyz[2]+=baseZ; + + //that must be here since in some cases other axis (b,c) controls y + if (xyz[1] < 0 || xyz[1] >= 256) { + return false; + } + + //Check block + if (world.blockExists(xyz[0], xyz[1], xyz[2])) {//this actually checks if the chunk is loaded + if (hintsOnly) { + switch (block) { + case '-'://must be air + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, 13); + break; + case '+'://must not be air + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, 14); + break; + default: //check for block + if ((pointer = block - '0') >= 0) { + if (world.getBlock(xyz[0], xyz[1], xyz[2]) != blockType[pointer] || world.getBlockMetadata(xyz[0], xyz[1], xyz[2]) != blockMeta[pointer]) { + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], blockType[pointer], blockMeta[pointer]); + } + } else if ((pointer = block - ' ') >= 0) { + if (pointer >= 0 && pointer < 12) { + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, pointer); + } else { + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, 12); + } + } else { + TecTech.proxy.hint_particle(world, xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, 15); + } + } + } else { + switch (block) { + case '-'://must be air + world.setBlock(xyz[0], xyz[1], xyz[2], Blocks.air, 0, 2); + break; + case '+'://must not be air + world.setBlock(xyz[0], xyz[1], xyz[2], TT_Container_Casings.sBlockCasingsTT, 14, 2); + break; + default: //check for block + if ((pointer = block - '0') >= 0) { + world.setBlock(xyz[0], xyz[1], xyz[2], blockType[pointer], blockMeta[pointer], 2); + } else if (block - ' ' < 0) { + world.setBlock(xyz[0], xyz[1], xyz[2], TT_Container_Casings.sHintCasingsTT, 15, 2); + } //else { + //switch(pointer){ + // case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: + // world.setBlock(x, y, z, TT_Container_Casings.sHintCasingsTT, pointer, 2); break; + // default:world.setBlock(x, y, z, TT_Container_Casings.sHintCasingsTT, 12, 2); + //} + //} + } + } + } + abc[0]++;//block in horizontal layer + } + } + abc[1]--;//horizontal layer + } + abc[2]++;//depth + } + return true; + } + + + public static String[] writer(IGregTechTileEntity aBaseMetaTileEntity, + int horizontalOffset, int verticalOffset, int depthOffset, + int horizontalSize, int verticalSize, int depthSize, boolean ignoreAir) { + //TE Rotation + byte facing = aBaseMetaTileEntity.getFrontFacing(); + World world = aBaseMetaTileEntity.getWorld(); + if (world.isRemote) { + return new String[]{"Not at Client m8"}; + } + + ItemStack[] array = new ItemStack[10]; + + int x, y, z, a, b, c; + int + baseX = aBaseMetaTileEntity.getXCoord(), + baseZ = aBaseMetaTileEntity.getZCoord(), + baseY = aBaseMetaTileEntity.getYCoord(); + //a,b,c - relative to block face! + //x,y,z - relative to block position on map! + //yPos - absolute height of checked block + + //perform your duties - #1 - count block types + c = -depthOffset; + for (int cz = 0; cz < depthSize; cz++) {//front to back + b = verticalOffset; + for (int by = 0; by < verticalSize; by++) {//top to bottom + a = -horizontalOffset; + for (int az = 0; az < horizontalSize; az++) {//left to right + //get x y z from rotation + switch (facing) {//translation + case 4: + x = baseX + c; + z = baseZ + a; + y = baseY + b; + break; + case 3: + x = baseX + a; + z = baseZ - c; + y = baseY + b; + break; + case 5: + x = baseX - c; + z = baseZ - a; + y = baseY + b; + break; + case 2: + x = baseX - a; + z = baseZ + c; + y = baseY + b; + break; + //Things get odd if the block faces up or down... + case 1: + x = baseX + a; + z = baseZ + b; + y = baseY - c; + break;//similar to 3 + case 0: + x = baseX - a; + z = baseZ - b; + y = baseY + c; + break;//similar to 2 + default: + return new String[]{"Invalid rotation"}; + } + + //that must be here since in some cases other axis (b,c) controls y + if (y < 0 || y >= 256) { + return new String[]{"Invalid position"}; + } + + //Check block + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if (!block.hasTileEntity(meta) && block.getMaterial() != Material.air) { + boolean err = true; + ItemStack is = new ItemStack(block, 1, meta); + for (int i = 0; i < array.length; i++) { + if (array[i] == null) { + array[i] = is; + err = false; + break; + } else if (is.getItem() == array[i].getItem() && is.getItemDamage() == array[i].getItemDamage()) { + err = false; + break; + } + } + if (err) { + return new String[]{"Too much different blocks"}; + } + } + + a++;//block in horizontal layer + } + b--;//horizontal layer + } + c++;//depth + } + + List output = new ArrayList<>(); + + output.add("Offsets: " + horizontalOffset + ' ' + verticalOffset + ' ' + depthOffset); + output.add("Sizes: " + horizontalSize + ' ' + verticalSize + ' ' + depthSize); + output.add(""); + + output.add("ID[]: Name[]"); + output.add(""); + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + output.add(i + ": " + array[i].getDisplayName()); + } + } + output.add(""); + output.add("ID[]: Block[] BlockMetaID[]"); + output.add(""); + for (int i = 0; i < array.length; i++) { + if (array[i] != null) { + output.add(i + ": " + array[i].getItem().getUnlocalizedName() + ' ' + array[i].getItemDamage()); + } + } + output.add(""); + output.add("String[][]"); + //perform your duties - #2 - write strings + output.add("{"); + c = -depthOffset; + for (int cz = 0; cz < depthSize; cz++) {//front to back + b = verticalOffset; + StringBuilder addMe = new StringBuilder().append('{'); + for (int by = 0; by < verticalSize; by++) {//top to bottom + a = -horizontalOffset; + StringBuilder line = new StringBuilder(); + for (int az = 0; az < horizontalSize; az++) {//left to right + //get x y z from rotation + switch (facing) {//translation + case 4: + x = baseX + c; + z = baseZ + a; + y = baseY + b; + break; + case 3: + x = baseX + a; + z = baseZ - c; + y = baseY + b; + break; + case 5: + x = baseX - c; + z = baseZ - a; + y = baseY + b; + break; + case 2: + x = baseX - a; + z = baseZ + c; + y = baseY + b; + break; + //Things get odd if the block faces up or down... + case 1: + x = baseX + a; + z = baseZ + b; + y = baseY - c; + break;//similar to 3 + case 0: + x = baseX - a; + z = baseZ - b; + y = baseY + c; + break;//similar to 2 + default: + return new String[]{"Invalid rotation"}; + } + + //Check block + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if (a == 0 && b == 0 && c == 0) { + line.append('.'); + } else if (block.getMaterial() == Material.air) { + line.append('-'); + } else if (block.hasTileEntity(meta)) { + line.append('*'); + } else { + ItemStack stack = new ItemStack(block, 1, meta); + String str = "?";//OH YEAH NPEs + for (int i = 0; i < array.length; i++) { + if (array[i] != null && stack.getItem() == array[i].getItem() && stack.getItemDamage() == array[i].getItemDamage()) { + str = Integer.toString(i); + break; + } + } + line.append(str); + } + a++;//block in horizontal layer + } + if (ignoreAir) { + StringBuilder builder = new StringBuilder(); + char temp = '@'; + for (char ch : line.toString().toCharArray()) { + if (ch == '-') { + temp += 1; + if (temp == '~') { + builder.append('~'); + temp = '@'; + } + } else { + if (temp > '@') { + builder.append(temp); + temp = '@'; + } + builder.append(ch); + } + } + while (builder.length() > 0 && builder.charAt(builder.length() - 1) == '~') { + builder.deleteCharAt(builder.length() - 1); + } + if (builder.length() == 0) { + builder.append("E,"); + } else { + builder.insert(0, '"'); + builder.append('"').append(','); + } + addMe.append(builder); + } else { + if (line.length() == 0) { + line.append("E,"); + } else { + line.insert(0, '"'); + line.append('"').append(','); + } + addMe.append(line); + } + b--;//horizontal layer + } + //region less verbose + addMe.append('}').append(','); + String builtStr = addMe.toString().replaceAll("(E,)+(?=})", E/*Remove Empty strings at end*/); + Matcher matcher = matchE_.matcher(builtStr); + while (matcher.find()) { + byte lenEE = (byte) (matcher.group(1).length() >> 1); + builtStr = builtStr.replaceFirst("E,(E,)+", "\"\\\\u00" + String.format("%02X", lenEE - 1) + "\","); + //builtStr=builtStr.replaceFirst("E,(E,)+\"","\"\\\\u00"+String.format("%02X", lenEE)); + } + //endregion + output.add(builtStr); + c++;//depth + } + output.add("}"); + return output.toArray(new String[0]); + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/constructible/IConstructable.java b/src/main/java/com/github/technus/tectech/mechanics/constructible/IConstructable.java deleted file mode 100644 index fdfa2904fb..0000000000 --- a/src/main/java/com/github/technus/tectech/mechanics/constructible/IConstructable.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.technus.tectech.mechanics.constructible; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -/** - * Created by Tec on 24.03.2017. - */ -public interface IConstructable { - void construct(int stackSize, boolean hintsOnly); - - @SideOnly(Side.CLIENT) - String[] getStructureDescription(int stackSize); -} - diff --git a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java index 4af6b53658..7b7d1983fa 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java +++ b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java @@ -1,15 +1,15 @@ package com.github.technus.tectech.thing.item; +import com.github.technus.tectech.mechanics.alignment.IAlignment; +import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer; import com.github.technus.tectech.util.CommonValues; import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.mechanics.constructible.IConstructable; +import com.github.technus.tectech.mechanics.constructable.IConstructable; import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace; -import net.minecraft.block.Block; +import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; @@ -18,14 +18,13 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.ForgeDirection; -import java.util.HashMap; import java.util.List; import static com.github.technus.tectech.Reference.MODID; -import static com.github.technus.tectech.util.Util.StructureBuilder; import static com.github.technus.tectech.loader.gui.CreativeTabTecTech.creativeTabTecTech; -import static gregtech.api.GregTech_API.sBlockCasings1; +import static com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer.MULTIBLOCK_MAP; import static net.minecraft.util.StatCollector.translateToLocal; /** @@ -34,8 +33,6 @@ import static net.minecraft.util.StatCollector.translateToLocal; public final class ConstructableTriggerItem extends Item { public static ConstructableTriggerItem INSTANCE; - private static HashMap multiblockMap= new HashMap<>(); - private ConstructableTriggerItem() { setUnlocalizedName("em.constructable"); setTextureName(MODID + ":itemConstructable"); @@ -54,14 +51,28 @@ public final class ConstructableTriggerItem extends Item { if (tTileEntity instanceof IGregTechTileEntity) { IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); if (metaTE instanceof IConstructable) { - ((IConstructable) metaTE).construct(aStack.stackSize, false); - } else if (multiblockMap.containsKey(metaTE.getClass().getCanonicalName())) { - multiblockMap.get(metaTE.getClass().getCanonicalName()).construct(aStack.stackSize, false, tTileEntity, ((IGregTechTileEntity) tTileEntity).getFrontFacing()); + ((IConstructable) metaTE).construct(aStack, false); + } else if (MULTIBLOCK_MAP.containsKey(metaTE.getClass().getCanonicalName())) { + IMultiblockInfoContainer iMultiblockInfoContainer = MULTIBLOCK_MAP.get(metaTE.getClass().getCanonicalName()); + if(metaTE instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, false, tTileEntity, ( + (IAlignment) metaTE).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, false, tTileEntity, + ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); + } } } else if (tTileEntity instanceof IConstructable) { - ((IConstructable) tTileEntity).construct(aStack.stackSize, false); - } else if (multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())) { - multiblockMap.get(tTileEntity.getClass().getCanonicalName()).construct(aStack.stackSize, false, tTileEntity, aSide); + ((IConstructable) tTileEntity).construct(aStack, false); + } else if (MULTIBLOCK_MAP.containsKey(tTileEntity.getClass().getCanonicalName())) { + IMultiblockInfoContainer iMultiblockInfoContainer = MULTIBLOCK_MAP.get(tTileEntity.getClass().getCanonicalName()); + if(tTileEntity instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, false, tTileEntity, + ((IAlignment) tTileEntity).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, false, tTileEntity, + ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); + } } } return true; @@ -70,21 +81,35 @@ public final class ConstructableTriggerItem extends Item { if(tTileEntity instanceof IGregTechTileEntity) { IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); if (metaTE instanceof IConstructable) { - ((IConstructable) metaTE).construct(aStack.stackSize, true); + ((IConstructable) metaTE).construct(aStack, true); TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack.stackSize)); return false; - } else if(multiblockMap.containsKey(metaTE.getClass().getCanonicalName())){ - multiblockMap.get(metaTE.getClass().getCanonicalName()).construct(aStack.stackSize,true,tTileEntity,((IGregTechTileEntity) tTileEntity).getFrontFacing()); - TecTech.proxy.printInchat(multiblockMap.get(metaTE.getClass().getCanonicalName()).getDescription(aStack.stackSize)); + } else if(MULTIBLOCK_MAP.containsKey(metaTE.getClass().getCanonicalName())){ + IMultiblockInfoContainer iMultiblockInfoContainer = MULTIBLOCK_MAP.get(metaTE.getClass().getCanonicalName()); + if(metaTE instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, true, tTileEntity, ( + (IAlignment) metaTE).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, true, tTileEntity, + ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); + } + TecTech.proxy.printInchat(MULTIBLOCK_MAP.get(metaTE.getClass(