From 31f7fc89f41e430494bb6e03415f58049f85da51 Mon Sep 17 00:00:00 2001 From: Tec Date: Fri, 1 May 2020 10:47:04 +0200 Subject: Fix navigation, move handles to util --- .../mechanics/alignment/AlignmentUtility.java | 45 ++ .../constructable/ConstructableUtility.java | 114 +++++ .../mechanics/structure/IStructureDefinition.java | 5 +- .../mechanics/structure/StructureDefinition.java | 38 +- .../mechanics/structure/StructureUtility.java | 481 ++++++++++++--------- .../thing/item/ConstructableTriggerItem.java | 104 +---- .../technus/tectech/thing/item/EuMeterGT.java | 2 +- .../thing/item/FrontRotationTriggerItem.java | 36 +- 8 files changed, 468 insertions(+), 357 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/alignment/AlignmentUtility.java create mode 100644 src/main/java/com/github/technus/tectech/mechanics/constructable/ConstructableUtility.java diff --git a/src/main/java/com/github/technus/tectech/mechanics/alignment/AlignmentUtility.java b/src/main/java/com/github/technus/tectech/mechanics/alignment/AlignmentUtility.java new file mode 100644 index 0000000000..68e11b77af --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/alignment/AlignmentUtility.java @@ -0,0 +1,45 @@ +package com.github.technus.tectech.mechanics.alignment; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; + +public class AlignmentUtility { + private AlignmentUtility(){ + + } + + public static boolean handle(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ){ + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if(tTileEntity==null || aPlayer instanceof FakePlayer) { + return aPlayer instanceof EntityPlayerMP; + } + if (aPlayer instanceof EntityPlayerMP) { + if (tTileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); + if (metaTE instanceof IAlignmentProvider) { + IAlignment alignment = ((IAlignmentProvider) metaTE).getAlignment(); + if(aPlayer.isSneaking()){ + alignment.toolSetFlip(null); + }else { + alignment.toolSetRotation(null); + } + return true; + } + } else if (tTileEntity instanceof IAlignmentProvider) { + IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment(); + if(aPlayer.isSneaking()){ + alignment.toolSetFlip(null); + }else { + alignment.toolSetRotation(null); + } + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/constructable/ConstructableUtility.java b/src/main/java/com/github/technus/tectech/mechanics/constructable/ConstructableUtility.java new file mode 100644 index 0000000000..2dc74330f9 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/constructable/ConstructableUtility.java @@ -0,0 +1,114 @@ +package com.github.technus.tectech.mechanics.constructable; + +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.mechanics.alignment.IAlignment; +import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.ForgeDirection; + +public class ConstructableUtility { + private ConstructableUtility(){ + + } + + public static boolean handle(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if(tTileEntity==null || aPlayer instanceof FakePlayer) { + return aPlayer instanceof EntityPlayerMP; + } + if (aPlayer instanceof EntityPlayerMP) { + //struct gen + if (aPlayer.isSneaking() && aPlayer.capabilities.isCreativeMode) { + if (tTileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); + if (metaTE instanceof IConstructable) { + ((IConstructable) metaTE).construct(aStack, false); + } else if (IMultiblockInfoContainer.contains(metaTE.getClass())) { + IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(metaTE.getClass()); + if(metaTE instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, false, metaTE, ( + (IAlignment) metaTE).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, false, metaTE, + ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); + } + } + } else if (tTileEntity instanceof IConstructable) { + ((IConstructable) tTileEntity).construct(aStack, false); + } else if (IMultiblockInfoContainer.contains(tTileEntity.getClass())) { + IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(tTileEntity.getClass()); + 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; + }else if (TecTech.proxy.isThePlayer(aPlayer)){//particles and text client side + //if ((!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode)) { + if(tTileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); + if (metaTE instanceof IConstructable) { + ((IConstructable) metaTE).construct(aStack, true); + TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack)); + return false; + } else if(IMultiblockInfoContainer.contains(metaTE.getClass())){ + IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(metaTE.getClass()); + if(metaTE instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, true, metaTE, + ((IAlignment) metaTE).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, true, metaTE, + ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); + } + TecTech.proxy.printInchat(IMultiblockInfoContainer.get(metaTE.getClass()).getDescription(aStack)); + return false; + } + } else if(tTileEntity instanceof IConstructable){ + ((IConstructable) tTileEntity).construct(aStack,true); + TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack)); + return false; + } else if(IMultiblockInfoContainer.contains(tTileEntity.getClass())){ + IMultiblockInfoContainer iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass()); + if(tTileEntity instanceof IAlignment){ + iMultiblockInfoContainer.construct(aStack, true, tTileEntity, + ((IAlignment) tTileEntity).getExtendedFacing()); + }else { + iMultiblockInfoContainer.construct(aStack, true, tTileEntity, + ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); + } + TecTech.proxy.printInchat(IMultiblockInfoContainer.get(tTileEntity.getClass()).getDescription(aStack)); + return false; + } + //} else { + // if(tTileEntity instanceof IGregTechTileEntity) { + // IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); + // if (metaTE instanceof IConstructable) { + // TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack.stackSize)); + // return false; + // } else if(multiblockMap.containsKey(metaTE.getClass().getCanonicalName())){ + // TecTech.proxy.printInchat(multiblockMap.get(metaTE.getClass().getCanonicalName()).getDescription(aStack.stackSize)); + // return false; + // } + // } else if(tTileEntity instanceof IConstructable){ + // TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack.stackSize)); + // return false; + // } else if(multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())){ + // TecTech.proxy.printInchat(multiblockMap.get(tTileEntity.getClass().getCanonicalName()).getDescription(aStack.stackSize)); + // return false; + // } + //} + } + return false; + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java index 71305ebd92..542d13a7cd 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/IStructureDefinition.java @@ -115,9 +115,8 @@ public interface IStructureDefinition { xyz[1] += basePositionY; xyz[2] += basePositionZ; - if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger); - } + element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger); + abc[0]+=1; } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java index 9cc82699b9..29114647ac 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureDefinition.java @@ -1,5 +1,6 @@ package com.github.technus.tectech.mechanics.structure; +import com.github.technus.tectech.TecTech; import com.github.technus.tectech.util.Vec3Impl; import java.util.*; @@ -29,7 +30,7 @@ public class StructureDefinition implements IStructureDefinition { private static final char A='\uA000'; private static final char B='\uB000'; private static final char C='\uC000'; - private static final char D='\uD000'; + private char d ='\uD000'; private final Map navigates; private final Map> elements; private final Map shapes; @@ -61,8 +62,12 @@ public class StructureDefinition implements IStructureDefinition { StringBuilder builder = new StringBuilder(); if (structurePiece.length > 0) { for (String[] strings : structurePiece) { + + if (strings.length > 0) { for (String string : strings) { + + for (int i = 0; i < string.length(); i++) { char ch = string.charAt(i); if(ch<' '){ @@ -77,16 +82,29 @@ public class StructureDefinition implements IStructureDefinition { builder.append(ch); } } + + builder.append(B); } builder.setLength(builder.length() - 1); } + + builder.append(C); } builder.setLength(builder.length() - 1); } + if(DEBUG_MODE){ + Exception exception = new Exception(); + exception.getStackTrace(); + + TecTech.LOGGER.info("Structure shape normal:"); + + + TecTech.LOGGER.info("Structure shape transposed:"); + + } int a=0,b=0,c=0; - char d=D; for (int i = 0; i < builder.length(); i++) { char ch = builder.charAt(i); if(ch =='.'){ @@ -106,7 +124,7 @@ public class StructureDefinition implements IStructureDefinition { Vec3Impl vec3 = new Vec3Impl(a, b, c); Character navigate = navigates.get(vec3); if(navigate==null){ - navigate=d++; + navigate= d++; navigates.put(vec3,navigate); addElement(navigate,step(vec3)); } @@ -137,8 +155,8 @@ public class StructureDefinition implements IStructureDefinition { * rest needs to be defined * * next char is next block(a) - * next string is next line(a,b) - * next string[] is next slice(a,b,c) + * next string is next line(b) + * next string[] is next slice(c) * * char A000-FFFF range is reserved for generated skips * @param name unlocalized/code name @@ -160,7 +178,6 @@ public class StructureDefinition implements IStructureDefinition { builder.setLength(builder.length() - 1); } int a=0,b=0,c=0; - char d=D; for (int i = 0; i < builder.length(); i++) { char ch = builder.charAt(i); if(ch ==' ' || ch =='.'){ @@ -188,7 +205,6 @@ public class StructureDefinition implements IStructureDefinition { a=0; b=0; c=0; - d++; } } @@ -220,14 +236,14 @@ public class StructureDefinition implements IStructureDefinition { @SuppressWarnings("unchecked") private Map[]> compileElementSetMap() { - Set mising = new HashSet<>(); + Set missing = new HashSet<>(); shapes.values().stream().map(CharSequence::chars).forEach(intStream -> intStream.forEach(c -> { IStructureElement iStructureElement = elements.get((char) c); if (iStructureElement == null) { - mising.add(c); + missing.add(c); } })); - if (mising.isEmpty()) { + if (missing.isEmpty()) { Map[]> map = new HashMap<>(); shapes.forEach((key, value) -> { Set chars=new HashSet<>(); @@ -244,7 +260,7 @@ public class StructureDefinition implements IStructureDefinition { return map; } else { throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + - Arrays.toString(mising.toArray())); + Arrays.toString(missing.toArray())); } } diff --git a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java index 1f8beaa240..868bfec181 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java +++ b/src/main/java/com/github/technus/tectech/mechanics/structure/StructureUtility.java @@ -24,11 +24,11 @@ import java.util.function.Supplier; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sHintCasingsTT; public class StructureUtility { - private static final String NICE_CHARS ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_=|[]{};:'<>,./?"; + private static final String NICE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_=|[]{};:'<>,./?"; @SuppressWarnings("rawtypes") - private static final Map STEP = new HashMap<>(); + private static final Map STEP = new HashMap<>(); @SuppressWarnings("rawtypes") - private static final IStructureElement AIR= new IStructureElement() { + private static final IStructureElement AIR = new IStructureElement() { @Override public boolean check(Object t, World world, int x, int y, int z) { return world.getBlock(x, y, z).getMaterial() == Material.air; @@ -36,18 +36,18 @@ public class StructureUtility { @Override public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,13); + TecTech.proxy.hint_particle(world, x, y, z, sHintCasingsTT, 13); return true; } @Override public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,Blocks.air,0,2); + world.setBlock(x, y, z, Blocks.air, 0, 2); return false; } }; @SuppressWarnings("rawtypes") - private static final IStructureElement NOT_AIR= new IStructureElement() { + private static final IStructureElement NOT_AIR = new IStructureElement() { @Override public boolean check(Object t, World world, int x, int y, int z) { return world.getBlock(x, y, z).getMaterial() != Material.air; @@ -55,18 +55,18 @@ public class StructureUtility { @Override public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,14); + TecTech.proxy.hint_particle(world, x, y, z, sHintCasingsTT, 14); return true; } @Override public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,sHintCasingsTT,14,2); + world.setBlock(x, y, z, sHintCasingsTT, 14, 2); return true; } }; @SuppressWarnings("rawtypes") - private static final IStructureElement ERROR= new IStructureElement() { + private static final IStructureElement ERROR = new IStructureElement() { @Override public boolean check(Object t, World world, int x, int y, int z) { return false; @@ -74,7 +74,7 @@ public class StructureUtility { @Override public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,sHintCasingsTT,15); + TecTech.proxy.hint_particle(world, x, y, z, sHintCasingsTT, 15); return true; } @@ -84,17 +84,17 @@ public class StructureUtility { } }; - private StructureUtility(){ + private StructureUtility() { } @SuppressWarnings("unchecked") - public static IStructureElement isAir(){ + public static IStructureElement isAir() { return AIR; } @SuppressWarnings("unchecked") - public static IStructureElement notAir(){ + public static IStructureElement notAir() { return NOT_AIR; } @@ -102,22 +102,24 @@ public class StructureUtility { * Check returns false. * Placement is always handled by this and does nothing. * Makes little to no use it in fallback chain. + * * @param * @return */ @SuppressWarnings("unchecked") - public static IStructureElement error(){ + public static IStructureElement error() { return ERROR; } /** * Check always returns: true. + * * @param dots * @param * @return */ - public static IStructureElementNoPlacement ofHint(int dots){ - int meta=dots-1; + public static IStructureElementNoPlacement ofHint(int dots) { + int meta = dots - 1; return new IStructureElementNoPlacement() { @Override public boolean check(T t, World world, int x, int y, int z) { @@ -135,8 +137,8 @@ public class StructureUtility { /** * Does not allow Block duplicates (with different meta) */ - public static IStructureElementNoPlacement ofBlocksFlatHint(Map blocsMap, Block hintBlock, int hintMeta){ - if(blocsMap==null || blocsMap.isEmpty() || hintBlock==null){ + public static IStructureElementNoPlacement ofBlocksFlatHint(Map blocsMap, Block hintBlock, int hintMeta) { + if (blocsMap == null || blocsMap.isEmpty() || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @@ -147,7 +149,7 @@ public class StructureUtility { @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; @@ -156,12 +158,12 @@ public class StructureUtility { /** * Allows block duplicates (with different meta) */ - public static IStructureElementNoPlacement ofBlocksMapHint(Map> blocsMap, Block hintBlock, int hintMeta){ - if(blocsMap==null || blocsMap.isEmpty() || hintBlock==null){ + public static IStructureElementNoPlacement ofBlocksMapHint(Map> blocsMap, Block hintBlock, int hintMeta) { + if (blocsMap == null || blocsMap.isEmpty() || hintBlock == null) { throw new IllegalArgumentException(); } for (Set value : blocsMap.values()) { - if(value.isEmpty()){ + if (value.isEmpty()) { throw new IllegalArgumentException(); } } @@ -173,14 +175,14 @@ public class StructureUtility { @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; } - public static IStructureElementNoPlacement ofBlockHint(Block block, int meta,Block hintBlock,int hintMeta){ - if(block==null || hintBlock==null){ + public static IStructureElementNoPlacement ofBlockHint(Block block, int meta, Block hintBlock, int hintMeta) { + if (block == null || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @@ -191,29 +193,29 @@ public class StructureUtility { @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; } - public static IStructureElementNoPlacement ofBlockHint(Block block, int meta){ - return ofBlockHint(block, meta,block,meta); + public static IStructureElementNoPlacement ofBlockHint(Block block, int meta) { + return ofBlockHint(block, meta, block, meta); } - public static IStructureElementNoPlacement ofBlockAdderHint(IBlockAdder iBlockAdder, Block hintBlock, int hintMeta){ - if(iBlockAdder==null ||hintBlock==null){ + public static IStructureElementNoPlacement ofBlockAdderHint(IBlockAdder iBlockAdder, Block hintBlock, int hintMeta) { + if (iBlockAdder == null || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @Override public boolean check(T t, World world, int x, int y, int z) { - return iBlockAdder.apply(t,world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + return iBlockAdder.apply(t, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; @@ -222,8 +224,8 @@ public class StructureUtility { /** * Does not allow Block duplicates (with different meta) */ - public static IStructureElement ofBlocksFlat(Map blocsMap,Block defaultBlock,int defaultMeta){ - if(blocsMap==null || blocsMap.isEmpty() || defaultBlock==null){ + public static IStructureElement ofBlocksFlat(Map blocsMap, Block defaultBlock, int defaultMeta) { + if (blocsMap == null || blocsMap.isEmpty() || defaultBlock == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @@ -234,13 +236,13 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,defaultBlock,defaultMeta,2); + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,defaultBlock,defaultMeta); + TecTech.proxy.hint_particle(world, x, y, z, defaultBlock, defaultMeta); return true; } }; @@ -249,12 +251,12 @@ public class StructureUtility { /** * Allows block duplicates (with different meta) */ - public static IStructureElement ofBlocksMap(Map> blocsMap, Block defaultBlock, int defaultMeta){ - if(blocsMap==null || blocsMap.isEmpty() || defaultBlock==null){ + public static IStructureElement ofBlocksMap(Map> blocsMap, Block defaultBlock, int defaultMeta) { + if (blocsMap == null || blocsMap.isEmpty() || defaultBlock == null) { throw new IllegalArgumentException(); } for (Set value : blocsMap.values()) { - if(value.isEmpty()){ + if (value.isEmpty()) { throw new IllegalArgumentException(); } } @@ -266,20 +268,20 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,defaultBlock,defaultMeta,2); + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,defaultBlock,defaultMeta); + TecTech.proxy.hint_particle(world, x, y, z, defaultBlock, defaultMeta); return true; } }; } - public static IStructureElement ofBlock(Block block, int meta,Block defaultBlock,int defaultMeta){ - if(block==null || defaultBlock==null){ + public static IStructureElement ofBlock(Block block, int meta, Block defaultBlock, int defaultMeta) { + if (block == null || defaultBlock == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @@ -290,98 +292,98 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,defaultBlock,defaultMeta,2); + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,defaultBlock,defaultMeta); + TecTech.proxy.hint_particle(world, x, y, z, defaultBlock, defaultMeta); return true; } }; } - public static IStructureElement ofBlock(Block block, int meta){ - return ofBlock(block, meta,block,meta); + public static IStructureElement ofBlock(Block block, int meta) { + return ofBlock(block, meta, block, meta); } - public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder,Block defaultBlock,int defaultMeta){ - if(iBlockAdder==null ||defaultBlock==null){ + public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, Block defaultBlock, int defaultMeta) { + if (iBlockAdder == null || defaultBlock == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @Override public boolean check(T t, World world, int x, int y, int z) { - return iBlockAdder.apply(t,world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + return iBlockAdder.apply(t, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,defaultBlock,defaultMeta,2); + world.setBlock(x, y, z, defaultBlock, defaultMeta, 2); return true; } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,defaultBlock,defaultMeta); + TecTech.proxy.hint_particle(world, x, y, z, defaultBlock, defaultMeta); return true; } }; } - public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder,int dots){ - return ofBlockAdder(iBlockAdder,sHintCasingsTT,dots-1); + public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, int dots) { + return ofBlockAdder(iBlockAdder, sHintCasingsTT, dots - 1); } - public static IStructureElementNoPlacement ofTileAdder(ITileAdder iTileAdder, Block hintBlock, int hintMeta){ - if(iTileAdder==null ||hintBlock==null){ + public static IStructureElementNoPlacement ofTileAdder(ITileAdder iTileAdder, Block hintBlock, int hintMeta) { + if (iTileAdder == null || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iTileAdder.apply(t,tileEntity); + return tileEntity instanceof IGregTechTileEntity && iTileAdder.apply(t, tileEntity); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; } - public static IStructureElementNoPlacement ofHatchAdder(IHatchAdder iHatchAdder, int textureIndex, int dots){ - return ofHatchAdder(iHatchAdder, textureIndex,sHintCasingsTT, dots-1); + public static IStructureElementNoPlacement ofHatchAdder(IHatchAdder iHatchAdder, int textureIndex, int dots) { + return ofHatchAdder(iHatchAdder, textureIndex, sHintCasingsTT, dots - 1); } - public static IStructureElementNoPlacement ofHatchAdder(IHatchAdder iHatchAdder, int textureIndex, Block hintBlock, int hintMeta){ - if(iHatchAdder==null ||hintBlock==null){ + public static IStructureElementNoPlacement ofHatchAdder(IHatchAdder iHatchAdder, int textureIndex, Block hintBlock, int hintMeta) { + if (iHatchAdder == null || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElementNoPlacement() { @Override public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); - return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex); + return tileEntity instanceof IGregTechTileEntity && iHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } }; } - public static IStructureElement ofHatchAdderOptional(IHatchAdder iHatchAdder, int textureIndex, int dots, Block placeCasing,int placeCasingMeta){ - return ofHatchAdderOptional(iHatchAdder, textureIndex, sHintCasingsTT, dots-1, placeCasing, placeCasingMeta); + public static IStructureElement ofHatchAdderOptional(IHatchAdder iHatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { + return ofHatchAdderOptional(iHatchAdder, textureIndex, sHintCasingsTT, dots - 1, placeCasing, placeCasingMeta); } - public static IStructureElement ofHatchAdderOptional(IHatchAdder iHatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing,int placeCasingMeta){ - if(iHatchAdder==null ||hintBlock==null){ + public static IStructureElement ofHatchAdderOptional(IHatchAdder iHatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { + if (iHatchAdder == null || hintBlock == null) { throw new IllegalArgumentException(); } return new IStructureElement() { @@ -389,30 +391,30 @@ public class StructureUtility { public boolean check(T t, World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); return tileEntity instanceof IGregTechTileEntity && - (iHatchAdder.apply(t,(IGregTechTileEntity) tileEntity, (short)textureIndex) || - (world.getBlock(x,y,z)==placeCasing&&world.getBlockMetadata(x,y,z)==placeCasingMeta)); + (iHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex) || + (world.getBlock(x, y, z) == placeCasing && world.getBlockMetadata(x, y, z) == placeCasingMeta)); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - TecTech.proxy.hint_particle(world,x,y,z,hintBlock,hintMeta); + TecTech.proxy.hint_particle(world, x, y, z, hintBlock, hintMeta); return true; } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x,y,z,placeCasing,placeCasingMeta,2); + world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); return true; } }; } - public static ,T> IStructureElement onElementPass(Consumer onCheckPass, B element){ + public static , T> IStructureElement onElementPass(Consumer onCheckPass, B element) { return new IStructureElement() { @Override public boolean check(T t, World world, int x, int y, int z) { boolean check = element.check(t, world, x, y, z); - if(check){ + if (check) { onCheckPass.accept(t); } return check; @@ -430,12 +432,12 @@ public class StructureUtility { }; } - public static ,T> IStructureElement onElementFail(Consumer onFail, B element){ + public static , T> IStructureElement onElementFail(Consumer onFail, B element) { return new IStructureElement() { @Override public boolean check(T t, World world, int x, int y, int z) { boolean check = element.check(t, world, x, y, z); - if(!check){ + if (!check) { onFail.accept(t); } return check; @@ -457,17 +459,18 @@ public class StructureUtility { /** * Take care while chaining, as it will try to call every structure element until it returns true. * If none does it will finally return false. + * * @param elementChain * @param * @return */ @SafeVarargs - public static IStructureElementChain ofChain(IStructureElement... elementChain){ - if(elementChain==null || elementChain.length==0){ + public static IStructureElementChain ofChain(IStructureElement... elementChain) { + if (elementChain == null || elementChain.length == 0) { throw new IllegalArgumentException(); } for (IStructureElement iStructureElement : elementChain) { - if(iStructureElement==null){ + if (iStructureElement == null) { throw new IllegalArgumentException(); } } @@ -477,17 +480,18 @@ public class StructureUtility { /** * Take care while chaining, as it will try to call every structure element until it returns true. * If none does it will finally return false. + * * @param elementChain * @param * @return */ @SuppressWarnings("unchecked") - public static IStructureElementChain ofChain(List> elementChain){ + public static IStructureElementChain ofChain(List> elementChain) { return ofChain(elementChain.toArray(new IStructureElement[0])); } - public static IStructureElementDeferred defer(Supplier> to){ - if(to==null){ + public static IStructureElementDeferred defer(Supplier> to) { + if (to == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -508,8 +512,8 @@ public class StructureUtility { }; } - public static IStructureElementDeferred defer(Function> to){ - if(to==null){ + public static IStructureElementDeferred defer(Function> to) { + if (to == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -530,8 +534,8 @@ public class StructureUtility { }; } - public static IStructureElementDeferred defer(Function keyExtractor,Map> map){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(Function keyExtractor, Map> map) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -552,31 +556,31 @@ public class StructureUtility { }; } - public static IStructureElementDeferred defer(Function keyExtractor,Map> map,IStructureElement defaultElem){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(Function keyExtractor, Map> map, IStructureElement defaultElem) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return map.getOrDefault(keyExtractor.apply(t),defaultElem).check(t, world, x, y, z); + return map.getOrDefault(keyExtractor.apply(t), defaultElem).check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t),defaultElem).placeBlock(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t), defaultElem).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t),defaultElem).spawnHint(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t), defaultElem).spawnHint(t, world, x, y, z, trigger); } }; } @SafeVarargs - public static IStructureElementDeferred defer(Function keyExtractor, IStructureElement... array){ - if(keyExtractor==null||array==null){ + public static IStructureElementDeferred defer(Function keyExtractor, IStructureElement... array) { + if (keyExtractor == null || array == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -598,106 +602,106 @@ public class StructureUtility { } @SuppressWarnings("unchecked") - public static IStructureElementDeferred defer(Function keyExtractor,List> array){ + public static IStructureElementDeferred defer(Function keyExtractor, List> array) { return defer(keyExtractor, array.toArray(new IStructureElement[0])); } - public static IStructureElementDeferred defer(BiFunction> to){ - if(to==null){ + public static IStructureElementDeferred defer(BiFunction> to) { + if (to == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return to.apply(t,null).check(t, world, x, y, z); + return to.apply(t, null).check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return to.apply(t,trigger).placeBlock(t, world, x, y, z, trigger); + return to.apply(t, trigger).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return to.apply(t,trigger).spawnHint(t, world, x, y, z, trigger); + return to.apply(t, trigger).spawnHint(t, world, x, y, z, trigger); } }; } - public static IStructureElementDeferred defer(BiFunction keyExtractor,Map> map){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(BiFunction keyExtractor, Map> map) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return map.get(keyExtractor.apply(t,null)).check(t, world, x, y, z); + return map.get(keyExtractor.apply(t, null)).check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.get(keyExtractor.apply(t,trigger)).placeBlock(t, world, x, y, z, trigger); + return map.get(keyExtractor.apply(t, trigger)).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.get(keyExtractor.apply(t,trigger)).spawnHint(t, world, x, y, z, trigger); + return map.get(keyExtractor.apply(t, trigger)).spawnHint(t, world, x, y, z, trigger); } }; } - public static IStructureElementDeferred defer(BiFunction keyExtractor,Map> map,IStructureElement defaultElem){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(BiFunction keyExtractor, Map> map, IStructureElement defaultElem) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return map.getOrDefault(keyExtractor.apply(t,null),defaultElem).check(t, world, x, y, z); + return map.getOrDefault(keyExtractor.apply(t, null), defaultElem).check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t,trigger),defaultElem).placeBlock(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t, trigger), defaultElem).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t,trigger),defaultElem).spawnHint(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t, trigger), defaultElem).spawnHint(t, world, x, y, z, trigger); } }; } @SafeVarargs - public static IStructureElementDeferred defer(BiFunction keyExtractor, IStructureElement... array){ - if(keyExtractor==null||array==null){ + public static IStructureElementDeferred defer(BiFunction keyExtractor, IStructureElement... array) { + if (keyExtractor == null || array == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return array[keyExtractor.apply(t,null)].check(t, world, x, y, z); + return array[keyExtractor.apply(t, null)].check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return array[keyExtractor.apply(t,trigger)].placeBlock(t, world, x, y, z, trigger); + return array[keyExtractor.apply(t, trigger)].placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return array[keyExtractor.apply(t,trigger)].spawnHint(t, world, x, y, z, trigger); + return array[keyExtractor.apply(t, trigger)].spawnHint(t, world, x, y, z, trigger); } }; } @SuppressWarnings("unchecked") - public static IStructureElementDeferred defer(BiFunction keyExtractor, List> array){ + public static IStructureElementDeferred defer(BiFunction keyExtractor, List> array) { return defer(keyExtractor, array.toArray(new IStructureElement[0])); } - public static IStructureElementDeferred defer(Function> toCheck, BiFunction> to){ - if(to==null){ + public static IStructureElementDeferred defer(Function> toCheck, BiFunction> to) { + if (to == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -708,18 +712,18 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return to.apply(t,trigger).placeBlock(t, world, x, y, z, trigger); + return to.apply(t, trigger).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return to.apply(t,trigger).spawnHint(t, world, x, y, z, trigger); + return to.apply(t, trigger).spawnHint(t, world, x, y, z, trigger); } }; } - public static IStructureElementDeferred defer(Function keyExtractorCheck,BiFunction keyExtractor,Map> map){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, Map> map) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -730,41 +734,41 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.get(keyExtractor.apply(t,trigger)).placeBlock(t, world, x, y, z, trigger); + return map.get(keyExtractor.apply(t, trigger)).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.get(keyExtractor.apply(t,trigger)).spawnHint(t, world, x, y, z, trigger); + return map.get(keyExtractor.apply(t, trigger)).spawnHint(t, world, x, y, z, trigger); } }; } - public static IStructureElementDeferred defer(Function keyExtractorCheck,BiFunction keyExtractor,Map> map,IStructureElement defaultElem){ - if(keyExtractor==null||map==null){ + public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, Map> map, IStructureElement defaultElem) { + if (keyExtractor == null || map == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @Override public boolean check(T t, World world, int x, int y, int z) { - return map.getOrDefault(keyExtractorCheck.apply(t),defaultElem).check(t, world, x, y, z); + return map.getOrDefault(keyExtractorCheck.apply(t), defaultElem).check(t, world, x, y, z); } @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t,trigger),defaultElem).placeBlock(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t, trigger), defaultElem).placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return map.getOrDefault(keyExtractor.apply(t,trigger),defaultElem).spawnHint(t, world, x, y, z, trigger); + return map.getOrDefault(keyExtractor.apply(t, trigger), defaultElem).spawnHint(t, world, x, y, z, trigger); } }; } @SafeVarargs - public static IStructureElementDeferred defer(Function keyExtractorCheck,BiFunction keyExtractor, IStructureElement... array){ - if(keyExtractor==null||array==null){ + public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, IStructureElement... array) { + if (keyExtractor == null || array == null) { throw new IllegalArgumentException(); } return new IStructureElementDeferred() { @@ -775,42 +779,42 @@ public class StructureUtility { @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return array[keyExtractor.apply(t,trigger)].placeBlock(t, world, x, y, z, trigger); + return array[keyExtractor.apply(t, trigger)].placeBlock(t, world, x, y, z, trigger); } @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return array[keyExtractor.apply(t,trigger)].spawnHint(t, world, x, y, z, trigger); + return array[keyExtractor.apply(t, trigger)].spawnHint(t, world, x, y, z, trigger); } }; } @SuppressWarnings("unchecked") - public static IStructureElementDeferred defer(Function keyExtractorCheck,BiFunction keyExtractor, List> array){ + public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, List> array) { return defer(keyExtractorCheck, keyExtractor, array.toArray(new IStructureElement[0])); } - public static IStructureNavigate step(int a,int b, int c){ - return step(new Vec3Impl(a,b,c)); + public static IStructureNavigate step(int a, int b, int c) { + return step(new Vec3Impl(a, b, c)); } @SuppressWarnings("unchecked") - public static IStructureNavigate step(Vec3Impl step){ - if(step==null || step.get0()<0 || step.get1()<0 || step.get2()<0){ + public static IStructureNavigate step(Vec3Impl step) { + if (step == null || step.get0() < 0 || step.get1() < 0 || step.get2() < 0) { throw new IllegalArgumentException(); } return STEP.computeIfAbsent(step, vec3 -> { - if(vec3.get2()>0){ + if (vec3.get2() > 0) { return stepC(vec3.get0(), vec3.get1(), vec3.get2()); - }else if(vec3.get1()>0){ + } else if (vec3.get1() > 0) { return stepB(vec3.get0(), vec3.get1(), vec3.get2()); - }else { + } else { return stepA(vec3.get0(), vec3.get1(), vec3.get2()); } }); } - private static IStructureNavigate stepA(int a,int b, int c){ + private static IStructureNavigate stepA(int a, int b, int c) { return new IStructureNavigate() { @Override public int getStepA() { @@ -829,7 +833,7 @@ public class StructureUtility { }; } - private static IStructureNavigate stepB(int a,int b, int c){ + private static IStructureNavigate stepB(int a, int b, int c) { return new IStructureNavigate() { @Override public int getStepA() { @@ -853,7 +857,7 @@ public class StructureUtility { }; } - private static IStructureNavigate stepC(int a,int b, int c){ + private static IStructureNavigate stepC(int a, int b, int c) { return new IStructureNavigate() { @Override public int getStepA() { @@ -884,13 +888,14 @@ public class StructureUtility { /** * Used only to get pseudo code in structure writer... + * * @param world * @return */ public static String getPseudoJavaCode(World world, ExtendedFacing extendedFacing, int basePositionX, int basePositionY, int basePositionZ, int basePositionA, int basePositionB, int basePositionC, - int sizeA,int sizeB, int sizeC) { + int sizeA, int sizeB, int sizeC, boolean transpose) { Map> blocks = new TreeMap<>(Comparator.comparing(Block::getUnlocalizedName)); Set> tiles = new TreeSet<>(Comparator.comparing(Class::getCanonicalName)); Set> gtTiles = new TreeSet<>(Comparator.comparing(Class::getCanonicalName)); @@ -934,7 +939,7 @@ public class StructureUtility { Set set = entry.getValue(); for (Integer meta : set) { c = NICE_CHARS.charAt(i++); - if(i>NICE_CHARS.length()){ + if (i > NICE_CHARS.length()) { return "Too complicated for nice chars"; } map.put(block.getUnlocalizedName() + '\0' + meta, c); @@ -945,7 +950,7 @@ public class StructureUtility { builder.append("\nTiles:\n"); for (Class tile : tiles) { c = NICE_CHARS.charAt(i++); - if(i>NICE_CHARS.length()){ + if (i > NICE_CHARS.length()) { return "Too complicated for nice chars"; } map.put(tile.getCanonicalName(), c); @@ -955,7 +960,7 @@ public class StructureUtility { builder.append("\nMeta:\n"); for (Class gtTile : gtTiles) { c = NICE_CHARS.charAt(i++); - if(i>NICE_CHARS.length()){ + if (i > NICE_CHARS.length()) { return "Too complicated for nice chars"; } map.put(gtTile.getCanonicalName(), c); @@ -965,61 +970,97 @@ public class StructureUtility { } builder.append("\nOffsets:\n") .append(basePositionA).append(' ').append(basePositionB).append(' ').append(basePositionC).append('\n'); - builder.append("\nScan:\n") - .append("new String[][]{{\n") - .append(" \""); - - iterate(world, extendedFacing, basePositionX, basePositionY, basePositionZ, - basePositionA, basePositionB, basePositionC, - sizeA, sizeB, sizeC, ((w, x, y, z) -> { - TileEntity tileEntity = w.getTileEntity(x, y, z); - if (tileEntity == null) { - Block block = w.getBlock(x, y, z); - if (block != null && block != Blocks.air) { - builder.append(map.get(block.getUnlocalizedName() + '\0' + world.getBlockMetadata(x, y, z))); - }else { - builder.append(' '); - } - } else { - if (tileEntity instanceof IGregTechTileEntity) { - IMetaTileEntity meta = ((IGregTechTileEntity) tileEntity).getMetaTileEntity(); - if (meta != null) { - builder.append(map.get(meta.getClass().getCanonicalName())); + if (transpose) { + builder.append("\nTransposed Scan:\n") + .append("new String[][]{\n") + .append(" {\""); + iterate(world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, true, + sizeA, sizeB, sizeC, ((w, x, y, z) -> { + TileEntity tileEntity = w.getTileEntity(x, y, z); + if (tileEntity == null) { + Block block = w.getBlock(x, y, z); + if (block != null && block != Blocks.air) { + builder.append(map.get(block.getUnlocalizedName() + '\0' + world.getBlockMetadata(x, y, z))); + } else { + builder.append(' '); + } + } else { + if (tileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity meta = ((IGregTechTileEntity) tileEntity).getMetaTileEntity(); + if (meta != null) { + builder.append(map.get(meta.getClass().getCanonicalName())); + } else { + builder.append(map.get(tileEntity.getClass().getCanonicalName())); + } } else { builder.append(map.get(tileEntity.getClass().getCanonicalName())); } + } + }), + () -> builder.append("\",\""), + () -> { + builder.setLength(builder.length() - 2); + builder.append("},\n {\""); + }); + builder.setLength(builder.length() - 8); + builder.append("\n}\n\n"); + } else { + builder.append("\nNormal Scan:\n") + .append("new String[][]{{\n") + .append(" \""); + iterate(world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, false, + sizeA, sizeB, sizeC, ((w, x, y, z) -> { + TileEntity tileEntity = w.getTileEntity(x, y, z); + if (tileEntity == null) { + Block block = w.getBlock(x, y, z); + if (block != null && block != Blocks.air) { + builder.append(map.get(block.getUnlocalizedName() + '\0' + world.getBlockMetadata(x, y, z))); + } else { + builder.append(' '); + } } else { - builder.append(map.get(tileEntity.getClass().getCanonicalName())); + if (tileEntity instanceof IGregTechTileEntity) { + IMetaTileEntity meta = ((IGregTechTileEntity) tileEntity).getMetaTileEntity(); + if (meta != null) { + builder.append(map.get(meta.getClass().getCanonicalName())); + } else { + builder.append(map.get(tileEntity.getClass().getCanonicalName())); + } + } else { + builder.append(map.get(tileEntity.getClass().getCanonicalName())); + } } - } - }), - () -> builder.append("\",\n").append(" \""), - () -> { - builder.setLength(builder.length()-7); - builder.append("\n").append("},{\n").append(" \""); - }); - builder.setLength(builder.length()-8); - builder.append("};\n\n"); - return(builder.toString().replaceAll("\"\"","E")); + }), + () -> builder.append("\",\n").append(" \""), + () -> { + builder.setLength(builder.length() - 7); + builder.append("\n").append("},{\n").append(" \""); + }); + builder.setLength(builder.length() - 8); + builder.append("}\n\n"); + } + return (builder.toString().replaceAll("\"\"", "E")); } public static void iterate(World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - int sizeA,int sizeB, int sizeC, - IBlockPosConsumer iBlockPosConsumer){ - sizeA-=basePositionA; - sizeB-=basePositionB; - sizeC-=basePositionC; + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + int sizeA, int sizeB, int sizeC, + IBlockPosConsumer iBlockPosConsumer) { + sizeA -= basePositionA; + sizeB -= basePositionB; + sizeC -= basePositionC; int[] abc = new int[3]; int[] xyz = new int[3]; - for (abc[2]=-basePositionC ; abc[2] < sizeC; abc[2]++) { - for (abc[1]=-basePositionB; abc[1] < sizeB; abc[1]++) { - for (abc[0]=-basePositionA ; abc[0] < sizeA; abc[0]++) { + for (abc[2] = -basePositionC; abc[2] < sizeC; abc[2]++) { + for (abc[1] = -basePositionB; abc[1] < sizeB; abc[1]++) { + for (abc[0] = -basePositionA; abc[0] < sizeA; abc[0]++) { extendedFacing.getWorldOffset(abc, xyz); - iBlockPosConsumer.consume(world, xyz[0]+basePositionX,xyz[1]+basePositionY,xyz[2]+basePositionZ); + iBlockPosConsumer.consume(world, xyz[0] + basePositionX, xyz[1] + basePositionY, xyz[2] + basePositionZ); } } @@ -1027,28 +1068,56 @@ public class StructureUtility { } public static void iterate(World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - int sizeA, int sizeB, int sizeC, - IBlockPosConsumer iBlockPosConsumer, - Runnable nextB, - Runnable nextC){ - sizeA-=basePositionA; - sizeB-=basePositionB; - sizeC-=basePositionC; + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + boolean transpose, int sizeA, int sizeB, int sizeC, + IBlockPosConsumer iBlockPosConsumer, + Runnable nextB, + Runnable nextC) { + sizeA -= basePositionA; + sizeB -= basePositionB; + sizeC -= basePositionC; int[] abc = new int[3]; int[] xyz = new int[3]; - - for (abc[2]=-basePositionC ; abc[2] < sizeC; abc[2]++) { - for (abc[1]=-basePositionB; abc[1] < sizeB; abc[1]++) { - for (abc[0]=-basePositionA ; abc[0] < sizeA; abc[0]++) { - extendedFacing.getWorldOffset(abc, xyz); - iBlockPosConsumer.consume(world, xyz[0]+basePositionX,xyz[1]+basePositionY,xyz[2]+basePositionZ); + if (transpose) { + for (abc[1] = -basePositionB; abc[1] < sizeB; abc[1]++) { + for (abc[2] = -basePositionC; abc[2] < sizeC; abc[2]++) { + for (abc[0] = -basePositionA; abc[0] < sizeA; abc[0]++) { + extendedFacing.getWorldOffset(abc, xyz); + iBlockPosConsumer.consume(world, xyz[0] + basePositionX, xyz[1] + basePositionY, xyz[2] + basePositionZ); + } + nextB.run(); + } + nextC.run(); + } + } else { + for (abc[2] = -basePositionC; abc[2] < sizeC; abc[2]++) { + for (abc[1] = -basePositionB; abc[1] < sizeB; abc[1]++) { + for (abc[0] = -basePositionA; abc[0] < sizeA; abc[0]++) { + extendedFacing.getWorldOffset(abc, xyz); + iBlockPosConsumer.consume(world, xyz[0] + basePositionX, xyz[1] + basePositionY, xyz[2] + basePositionZ); + } + nextB.run(); } - nextB.run(); + nextC.run(); + } + } + } + + /** + * Transposes shape (swaps B and C axis, can be used to un-transpose transposed shape) + * WARNING! Do not use on old api... + * @param structurePiece shape (transposed shape) + * @return transposed shape (untransposed shape) + */ + public static String[][] transpose(String[][] structurePiece){ + String[][] shape=new String[structurePiece[0].length][structurePiece.length]; + for (int i = 0; i < structurePiece.length; i++) { + for (int j = 0; j < structurePiece[i].length; j++) { + shape[j][i]=structurePiece[i][j]; } - nextC.run(); } + return shape; } } 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 c24b35f8d5..752f2d1bcc 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,23 +1,13 @@ package com.github.technus.tectech.thing.item; -import com.github.technus.tectech.TecTech; -import com.github.technus.tectech.mechanics.alignment.IAlignment; -import com.github.technus.tectech.mechanics.alignment.enumerable.ExtendedFacing; -import com.github.technus.tectech.mechanics.constructable.IConstructable; -import com.github.technus.tectech.mechanics.constructable.IMultiblockInfoContainer; +import com.github.technus.tectech.mechanics.constructable.ConstructableUtility; import com.github.technus.tectech.util.CommonValues; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -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.List; @@ -39,97 +29,7 @@ public final class ConstructableTriggerItem extends Item { @Override public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) { - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if(tTileEntity==null || aPlayer instanceof FakePlayer) { - return aPlayer instanceof EntityPlayerMP; - } - if (aPlayer instanceof EntityPlayerMP) { - //struct gen - if (aPlayer.isSneaking() && aPlayer.capabilities.isCreativeMode) { - if (tTileEntity instanceof IGregTechTileEntity) { - IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (metaTE instanceof IConstructable) { - ((IConstructable) metaTE).construct(aStack, false); - } else if (IMultiblockInfoContainer.contains(metaTE.getClass())) { - IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(metaTE.getClass()); - if(metaTE instanceof IAlignment){ - iMultiblockInfoContainer.construct(aStack, false, metaTE, ( - (IAlignment) metaTE).getExtendedFacing()); - }else { - iMultiblockInfoContainer.construct(aStack, false, metaTE, - ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); - } - } - } else if (tTileEntity instanceof IConstructable) { - ((IConstructable) tTileEntity).construct(aStack, false); - } else if (IMultiblockInfoContainer.contains(tTileEntity.getClass())) { - IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(tTileEntity.getClass()); - 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; - }else if (TecTech.proxy.isThePlayer(aPlayer)){//particles and text client side - //if ((!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode)) { - if(tTileEntity instanceof IGregTechTileEntity) { - IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (metaTE instanceof IConstructable) { - ((IConstructable) metaTE).construct(aStack, true); - TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack)); - return false; - } else if(IMultiblockInfoContainer.contains(metaTE.getClass())){ - IMultiblockInfoContainer iMultiblockInfoContainer =IMultiblockInfoContainer.get(metaTE.getClass()); - if(metaTE instanceof IAlignment){ - iMultiblockInfoContainer.construct(aStack, true, metaTE, - ((IAlignment) metaTE).getExtendedFacing()); - }else { - iMultiblockInfoContainer.construct(aStack, true, metaTE, - ExtendedFacing.of(ForgeDirection.getOrientation(((IGregTechTileEntity) tTileEntity).getFrontFacing()))); - } - TecTech.proxy.printInchat(IMultiblockInfoContainer.get(metaTE.getClass()).getDescription(aStack)); - return false; - } - } else if(tTileEntity instanceof IConstructable){ - ((IConstructable) tTileEntity).construct(aStack,true); - TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack)); - return false; - } else if(IMultiblockInfoContainer.contains(tTileEntity.getClass())){ - IMultiblockInfoContainer iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass()); - if(tTileEntity instanceof IAlignment){ - iMultiblockInfoContainer.construct(aStack, true, tTileEntity, - ((IAlignment) tTileEntity).getExtendedFacing()); - }else { - iMultiblockInfoContainer.construct(aStack, true, tTileEntity, - ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); - } - TecTech.proxy.printInchat(IMultiblockInfoContainer.get(tTileEntity.getClass()).getDescription(aStack)); - return false; - } - //} else { - // if(tTileEntity instanceof IGregTechTileEntity) { - // IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - // if (metaTE instanceof IConstructable) { - // TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack.stackSize)); - // return false; - // } else if(multiblockMap.containsKey(metaTE.getClass().getCanonicalName())){ - // TecTech.proxy.printInchat(multiblockMap.get(metaTE.getClass().getCanonicalName()).getDescription(aStack.stackSize)); - // return false; - // } - // } else if(tTileEntity instanceof IConstructable){ - // TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack.stackSize)); - // return false; - // } else if(multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())){ - // TecTech.proxy.printInchat(multiblockMap.get(tTileEntity.getClass().getCanonicalName()).getDescription(aStack.stackSize)); - // return false; - // } - //} - } - return false; + return ConstructableUtility.handle(aStack, aPlayer, aWorld, aX, aY, aZ, aSide); } @Override diff --git a/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java b/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java index 8e3d770da1..f4531a248b 100644 --- a/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java +++ b/src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java @@ -73,7 +73,7 @@ public class EuMeterGT extends Item { } } if (!(aPlayer instanceof EntityPlayerMP)) { - GT_Utility.doSoundAtClient(Reference.MODID + ":fx_scan", 1, 1.0F, (double) aX, (double) aY, (double) aZ); + GT_Utility.doSoundAtClient(Reference.MODID + ":fx_scan", 1, 1.0F, aX, aY, aZ); } return false; } 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 5edc238a91..d71abb34b7 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,19 +1,13 @@ 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.mechanics.alignment.AlignmentUtility; import com.github.technus.tectech.util.CommonValues; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; import java.util.List; @@ -36,33 +30,7 @@ public final class FrontRotationTriggerItem extends Item { @Override public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) { - TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - if(tTileEntity==null || aPlayer instanceof FakePlayer) { - return aPlayer instanceof EntityPlayerMP; - } - if (aPlayer instanceof EntityPlayerMP) { - if (tTileEntity instanceof IGregTechTileEntity) { - IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (metaTE instanceof IAlignmentProvider) { - IAlignment alignment = ((IAlignmentProvider) metaTE).getAlignment(); - if(aPlayer.isSneaking()){ - alignment.toolSetFlip(null); - }else { - alignment.toolSetRotation(null); - } - return true; - } - } else if (tTileEntity instanceof IAlignmentProvider) { - IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment(); - if(aPlayer.isSneaking()){ - alignment.toolSetFlip(null); - }else { - alignment.toolSetRotation(null); - } - return true; - } - } - return false; + return AlignmentUtility.handle(aPlayer,aWorld,aX,aY,aZ); } @Override -- cgit