diff --git a/src/main/java/com/gtnewhorizon/structurelib/GuiModConfig.java b/src/main/java/com/gtnewhorizon/structurelib/GuiModConfig.java index 8e81af68..b586039d 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/GuiModConfig.java +++ b/src/main/java/com/gtnewhorizon/structurelib/GuiModConfig.java @@ -18,8 +18,8 @@ public class GuiModConfig extends GuiConfig { private static List getConfigElements() { final Configuration config = ConfigurationHandler.INSTANCE.getConfig(); return config.getCategoryNames().stream() - .filter(name -> name.indexOf('.') == -1) - .map(name -> new ConfigElement(config.getCategory(name))) - .collect(Collectors.toList()); + .filter(name -> name.indexOf('.') == -1) + .map(name -> new ConfigElement(config.getCategory(name))) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java index 7b3d75ab..6de73dc0 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java +++ b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java @@ -28,51 +28,51 @@ import org.apache.logging.log4j.Logger; */ @Mod(modid = StructureLibAPI.MOD_ID, name = "StructureLib", version = "GRADLETOKEN_VERSION", acceptableRemoteVersions = "*", guiFactory = "com.gtnewhorizon.structurelib.GuiFactory") public class StructureLib { - public static boolean DEBUG_MODE = Boolean.getBoolean("structurelib.debug"); - public static Logger LOGGER = LogManager.getLogger("StructureLib"); + public static boolean DEBUG_MODE = Boolean.getBoolean("structurelib.debug"); + public static Logger LOGGER = LogManager.getLogger("StructureLib"); - @SidedProxy(serverSide = "com.gtnewhorizon.structurelib.proxy.CommonProxy", clientSide = "com.gtnewhorizon.structurelib.proxy.ClientProxy") - static CommonProxy proxy; - static SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID); + @SidedProxy(serverSide = "com.gtnewhorizon.structurelib.proxy.CommonProxy", clientSide = "com.gtnewhorizon.structurelib.proxy.ClientProxy") + static CommonProxy proxy; + static SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID); - static { - net.registerMessage(AlignmentMessage.ServerHandler.class, AlignmentMessage.AlignmentQuery.class, 0, Side.SERVER); - net.registerMessage(AlignmentMessage.ClientHandler.class, AlignmentMessage.AlignmentData.class, 1, Side.CLIENT); - } + static { + net.registerMessage(AlignmentMessage.ServerHandler.class, AlignmentMessage.AlignmentQuery.class, 0, Side.SERVER); + net.registerMessage(AlignmentMessage.ClientHandler.class, AlignmentMessage.AlignmentData.class, 1, Side.CLIENT); + } - public static final XSTR RANDOM = new XSTR(); + public static final XSTR RANDOM = new XSTR(); - static Block blockHint; - static Item itemBlockHint; - static Item itemFrontRotationTool; - static Item itemConstructableTrigger; - public static final CreativeTabs creativeTab = new CreativeTabs("structurelib") { - @Override - @SideOnly(Side.CLIENT) - public Item getTabIconItem() { - return StructureLibAPI.getItemBlockHint(); - } - }; + static Block blockHint; + static Item itemBlockHint; + static Item itemFrontRotationTool; + static Item itemConstructableTrigger; + public static final CreativeTabs creativeTab = new CreativeTabs("structurelib") { + @Override + @SideOnly(Side.CLIENT) + public Item getTabIconItem() { + return StructureLibAPI.getItemBlockHint(); + } + }; - @Mod.EventHandler - public void preInit(FMLPreInitializationEvent e) { - ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile()); - GameRegistry.registerBlock(blockHint = new BlockHint(), ItemBlockHint.class, "blockhint"); - itemBlockHint = ItemBlock.getItemFromBlock(StructureLibAPI.getBlockHint()); - GameRegistry.registerItem(itemFrontRotationTool = new ItemFrontRotationTool(), itemFrontRotationTool.getUnlocalizedName()); - GameRegistry.registerItem(itemConstructableTrigger = new ItemConstructableTrigger(), itemConstructableTrigger.getUnlocalizedName()); - proxy.preInit(e); - } + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent e) { + ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile()); + GameRegistry.registerBlock(blockHint = new BlockHint(), ItemBlockHint.class, "blockhint"); + itemBlockHint = ItemBlock.getItemFromBlock(StructureLibAPI.getBlockHint()); + GameRegistry.registerItem(itemFrontRotationTool = new ItemFrontRotationTool(), itemFrontRotationTool.getUnlocalizedName()); + GameRegistry.registerItem(itemConstructableTrigger = new ItemConstructableTrigger(), itemConstructableTrigger.getUnlocalizedName()); + proxy.preInit(e); + } - public static void addClientSideChatMessages(String... messages) { - proxy.addClientSideChatMessages(messages); - } + public static void addClientSideChatMessages(String... messages) { + proxy.addClientSideChatMessages(messages); + } - public static EntityPlayer getCurrentPlayer() { - return proxy.getCurrentPlayer(); - } + public static EntityPlayer getCurrentPlayer() { + return proxy.getCurrentPlayer(); + } - public static boolean isCurrentPlayer(EntityPlayer player) { - return proxy.isCurrentPlayer(player); - } + public static boolean isCurrentPlayer(EntityPlayer player) { + return proxy.isCurrentPlayer(player); + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/StructureLibAPI.java b/src/main/java/com/gtnewhorizon/structurelib/StructureLibAPI.java index ad5b5e51..70f89bd7 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/StructureLibAPI.java +++ b/src/main/java/com/gtnewhorizon/structurelib/StructureLibAPI.java @@ -18,114 +18,119 @@ import static com.gtnewhorizon.structurelib.StructureLib.proxy; * A stable interface into the structure lib's internals. Backwards compatibility is maintained to the maximum extend possible. */ public class StructureLibAPI { - public static final String MOD_ID = "structurelib"; - public static final int HINT_BLOCK_META_GENERIC_0 = 0; - public static final int HINT_BLOCK_META_GENERIC_1 = 1; - public static final int HINT_BLOCK_META_GENERIC_2 = 2; - public static final int HINT_BLOCK_META_GENERIC_3 = 3; - public static final int HINT_BLOCK_META_GENERIC_4 = 4; - public static final int HINT_BLOCK_META_GENERIC_5 = 5; - public static final int HINT_BLOCK_META_GENERIC_6 = 6; - public static final int HINT_BLOCK_META_GENERIC_7 = 7; - public static final int HINT_BLOCK_META_GENERIC_8 = 8; - public static final int HINT_BLOCK_META_GENERIC_9 = 9; - public static final int HINT_BLOCK_META_GENERIC_10 = 10; - public static final int HINT_BLOCK_META_GENERIC_11 = 11; - public static final int HINT_BLOCK_META_DEFAULT = 12; - public static final int HINT_BLOCK_META_AIR = 13; - public static final int HINT_BLOCK_META_NOT_AIR = 14; - public static final int HINT_BLOCK_META_ERROR = 15; + public static final String MOD_ID = "structurelib"; + public static final int HINT_BLOCK_META_GENERIC_0 = 0; + public static final int HINT_BLOCK_META_GENERIC_1 = 1; + public static final int HINT_BLOCK_META_GENERIC_2 = 2; + public static final int HINT_BLOCK_META_GENERIC_3 = 3; + public static final int HINT_BLOCK_META_GENERIC_4 = 4; + public static final int HINT_BLOCK_META_GENERIC_5 = 5; + public static final int HINT_BLOCK_META_GENERIC_6 = 6; + public static final int HINT_BLOCK_META_GENERIC_7 = 7; + public static final int HINT_BLOCK_META_GENERIC_8 = 8; + public static final int HINT_BLOCK_META_GENERIC_9 = 9; + public static final int HINT_BLOCK_META_GENERIC_10 = 10; + public static final int HINT_BLOCK_META_GENERIC_11 = 11; + public static final int HINT_BLOCK_META_DEFAULT = 12; + public static final int HINT_BLOCK_META_AIR = 13; + public static final int HINT_BLOCK_META_NOT_AIR = 14; + public static final int HINT_BLOCK_META_ERROR = 15; - /** - * Start a batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram. - * - * You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)} - */ - public static void startHinting(World w) { - proxy.startHinting(w); - } + /** + * Start a batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram. + *

+ * You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)} + */ + public static void startHinting(World w) { + proxy.startHinting(w); + } - /** - * Start current batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram. - * - * You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)} - */ - public static void endHinting(World w) { - proxy.endHinting(w); - } + /** + * Start current batch of hinting. All hints particles generated during one batch will be considered to belong to one hologram. + *

+ * You don't need to call this unless your constructable tool didn't call {@link com.gtnewhorizon.structurelib.alignment.constructable.ConstructableUtility#handle(ItemStack, EntityPlayer, World, int, int, int, int)} + */ + public static void endHinting(World w) { + proxy.endHinting(w); + } - public static void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) { - proxy.hintParticleTinted(w, x, y, z, icons, RGBa); - } + public static void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) { + proxy.hintParticleTinted(w, x, y, z, icons, RGBa); + } - public static void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) { - proxy.hintParticleTinted(w, x, y, z, block, meta, RGBa); - } + public static void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) { + proxy.hintParticleTinted(w, x, y, z, block, meta, RGBa); + } - public static void hintParticle(World w, int x, int y, int z, IIcon[] icons) { - proxy.hintParticle(w, x, y, z, icons); - } + public static void hintParticle(World w, int x, int y, int z, IIcon[] icons) { + proxy.hintParticle(w, x, y, z, icons); + } - public static void hintParticle(World w, int x, int y, int z, Block block, int meta) { - proxy.hintParticle(w, x, y, z, block, meta); - } + public static void hintParticle(World w, int x, int y, int z, Block block, int meta) { + proxy.hintParticle(w, x, y, z, block, meta); + } - /** - * Query the ExtendedFacing of this tile entity. - * The ExtendedFacing will later be set onto given tile entity via {@link com.gtnewhorizon.structurelib.alignment.IAlignment#setExtendedFacing(ExtendedFacing)} - * upon arrival of server reply. - * @throws IllegalArgumentException if is not tile entity or provided a null alignment - */ - public static void queryAlignment(IAlignmentProvider provider) { - StructureLib.net.sendToServer(new AlignmentMessage.AlignmentQuery(provider)); - } + /** + * Query the ExtendedFacing of this tile entity. + * The ExtendedFacing will later be set onto given tile entity via {@link com.gtnewhorizon.structurelib.alignment.IAlignment#setExtendedFacing(ExtendedFacing)} + * upon arrival of server reply. + * + * @throws IllegalArgumentException if is not tile entity or provided a null alignment + */ + public static void queryAlignment(IAlignmentProvider provider) { + StructureLib.net.sendToServer(new AlignmentMessage.AlignmentQuery(provider)); + } - /** - * Send the ExtendedFacing of this Tile Entity to all players. Can be called on server side only. - * @throws IllegalArgumentException if is not tile entity or provided a null alignment - */ - public static void sendAlignment(IAlignmentProvider provider) { - StructureLib.net.sendToAll(new AlignmentMessage.AlignmentData(provider)); - } + /** + * Send the ExtendedFacing of this Tile Entity to all players. Can be called on server side only. + * + * @throws IllegalArgumentException if is not tile entity or provided a null alignment + */ + public static void sendAlignment(IAlignmentProvider provider) { + StructureLib.net.sendToAll(new AlignmentMessage.AlignmentData(provider)); + } - /** - * Send the ExtendedFacing of this Tile Entity to given player. Can be called on server side only. - * @throws IllegalArgumentException if is not tile entity or provided a null alignment - */ - public static void sendAlignment(IAlignmentProvider provider, EntityPlayerMP player) { - StructureLib.net.sendTo(new AlignmentMessage.AlignmentData(provider), player); - } + /** + * Send the ExtendedFacing of this Tile Entity to given player. Can be called on server side only. + * + * @throws IllegalArgumentException if is not tile entity or provided a null alignment + */ + public static void sendAlignment(IAlignmentProvider provider, EntityPlayerMP player) { + StructureLib.net.sendTo(new AlignmentMessage.AlignmentData(provider), player); + } - /** - * Send the ExtendedFacing of this Tile Entity to all players around target point. Can be called on server side only. - * @throws IllegalArgumentException if is not tile entity or provided a null alignment - */ - public static void sendAlignment(IAlignmentProvider provider, NetworkRegistry.TargetPoint targetPoint) { - StructureLib.net.sendToAllAround(new AlignmentMessage.AlignmentData(provider), targetPoint); - } + /** + * Send the ExtendedFacing of this Tile Entity to all players around target point. Can be called on server side only. + * + * @throws IllegalArgumentException if is not tile entity or provided a null alignment + */ + public static void sendAlignment(IAlignmentProvider provider, NetworkRegistry.TargetPoint targetPoint) { + StructureLib.net.sendToAllAround(new AlignmentMessage.AlignmentData(provider), targetPoint); + } - /** - * Send the ExtendedFacing of this Tile Entity to all players in that dimension. Can be called on server side only. - * @throws IllegalArgumentException if is not tile entity or provided a null alignment - */ - public static void sendAlignment(IAlignmentProvider provider, World dimension) { - StructureLib.net.sendToDimension(new AlignmentMessage.AlignmentData(provider), dimension.provider.dimensionId); - } + /** + * Send the ExtendedFacing of this Tile Entity to all players in that dimension. Can be called on server side only. + * + * @throws IllegalArgumentException if is not tile entity or provided a null alignment + */ + public static void sendAlignment(IAlignmentProvider provider, World dimension) { + StructureLib.net.sendToDimension(new AlignmentMessage.AlignmentData(provider), dimension.provider.dimensionId); + } - public static Block getBlockHint() { - return StructureLib.blockHint; - } + public static Block getBlockHint() { + return StructureLib.blockHint; + } - public static Item getItemBlockHint() { - return StructureLib.itemBlockHint; - } + public static Item getItemBlockHint() { + return StructureLib.itemBlockHint; + } - public static boolean isDebugEnabled() { - return StructureLib.DEBUG_MODE; - } + public static boolean isDebugEnabled() { + return StructureLib.DEBUG_MODE; + } - public static void setDebugEnabled(boolean enabled) { - StructureLib.DEBUG_MODE = enabled; - } + public static void setDebugEnabled(boolean enabled) { + StructureLib.DEBUG_MODE = enabled; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/AlignmentUtility.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/AlignmentUtility.java index a9059192..20d23484 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/AlignmentUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/AlignmentUtility.java @@ -7,10 +7,10 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; public class AlignmentUtility { - private AlignmentUtility(){ + private AlignmentUtility() { } - public static boolean handle(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ){ + 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; diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignment.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignment.java index f95816c8..bbe33927 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignment.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignment.java @@ -6,10 +6,10 @@ import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; import net.minecraftforge.common.util.ForgeDirection; -public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { - int DIRECTIONS_COUNT= Direction.VALUES.length; - int ROTATIONS_COUNT= Rotation.VALUES.length; - int FLIPS_COUNT= Flip.VALUES.length; +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.STATES_COUNT; ExtendedFacing getExtendedFacing(); @@ -23,48 +23,48 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { IAlignmentLimits getAlignmentLimits(); @Override - default IAlignment getAlignment(){ + 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(); + static int getAlignmentIndex(ForgeDirection direction, Rotation rotation, Flip flip) { + return (direction.ordinal() * ROTATIONS_COUNT + rotation.getIndex()) * FLIPS_COUNT + flip.getIndex(); } - default ForgeDirection getDirection(){ + default ForgeDirection getDirection() { return getExtendedFacing().getDirection(); } - default void setDirection(ForgeDirection direction){ + default void setDirection(ForgeDirection direction) { setExtendedFacing(getExtendedFacing().with(direction)); } - default Rotation getRotation(){ + default Rotation getRotation() { return getExtendedFacing().getRotation(); } - default void setRotation(Rotation rotation){ + default void setRotation(Rotation rotation) { setExtendedFacing(getExtendedFacing().with(rotation)); } - default Flip getFlip(){ + default Flip getFlip() { return getExtendedFacing().getFlip(); } - default void setFlip(Flip flip){ + default void setFlip(Flip flip) { setExtendedFacing(getExtendedFacing().with(flip)); } - 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++) { + 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++) { if (toolSetDirection(Direction.VALUES[(j + i) % valuesLength].getForgeDirection())) { return true; } } - }else { + } else { for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) { - if(checkedSetExtendedFacing(extendedFacing)){ + if (checkedSetExtendedFacing(extendedFacing)) { return true; } } @@ -72,17 +72,17 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { return false; } - default boolean checkedSetDirection(ForgeDirection direction){ - if (isNewDirectionValid(direction)){ + default boolean checkedSetDirection(ForgeDirection direction) { + if (isNewDirectionValid(direction)) { setDirection(direction); return true; } return false; } - default boolean canSetToDirectionAny(ForgeDirection direction){ + default boolean canSetToDirectionAny(ForgeDirection direction) { for (ExtendedFacing extendedFacing : ExtendedFacing.FOR_FACING.get(direction)) { - if(isNewExtendedFacingValid(extendedFacing)){ + if (isNewExtendedFacingValid(extendedFacing)) { return true; } } @@ -90,10 +90,10 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { } default boolean toolSetRotation(Rotation rotation) { - if(rotation==null){ + if (rotation == null) { int flips = Flip.VALUES.length; int rotations = Rotation.VALUES.length; - for (int ii = 0,jj=getFlip().ordinal(); ii < flips; ii++) { + for (int ii = 0, jj = getFlip().ordinal(); ii < flips; ii++) { for (int i = 1, j = getRotation().ordinal(); i < rotations; i++) { if (checkedSetExtendedFacing(ExtendedFacing.of(getDirection(), Rotation.VALUES[(j + i) % rotations], Flip.VALUES[(jj + ii) % flips]))) { return true; @@ -101,55 +101,55 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { } } return false; - }else { + } else { return checkedSetRotation(rotation); } } - default boolean checkedSetRotation(Rotation rotation){ - if (isNewRotationValid(rotation)){ + default boolean checkedSetRotation(Rotation rotation) { + if (isNewRotationValid(rotation)) { setRotation(rotation); return true; } return false; } - default boolean toolSetFlip(Flip flip){ - if(flip==null){ + default boolean toolSetFlip(Flip flip) { + if (flip == null) { for (int i = 1, j = getFlip().ordinal(), valuesLength = Flip.VALUES.length; i < valuesLength; i++) { if (checkedSetFlip(Flip.VALUES[(j + i) % valuesLength])) { return true; } } return false; - }else { + } else { return checkedSetFlip(flip); } } - default boolean checkedSetFlip(Flip flip){ - if (isNewFlipValid(flip)){ + default boolean checkedSetFlip(Flip flip) { + if (isNewFlipValid(flip)) { setFlip(flip); return true; } return false; } - default boolean toolSetExtendedFacing(ExtendedFacing extendedFacing){ - if(extendedFacing==null){ - for (int i = 0,j=getExtendedFacing().ordinal()+1, valuesLength = ExtendedFacing.VALUES.length; i < valuesLength; i++) { - if (checkedSetExtendedFacing(ExtendedFacing.VALUES[(j + i)%valuesLength])){ + default boolean toolSetExtendedFacing(ExtendedFacing extendedFacing) { + if (extendedFacing == null) { + for (int i = 0, j = getExtendedFacing().ordinal() + 1, valuesLength = ExtendedFacing.VALUES.length; i < valuesLength; i++) { + if (checkedSetExtendedFacing(ExtendedFacing.VALUES[(j + i) % valuesLength])) { return true; } } return false; - }else { + } else { return checkedSetExtendedFacing(extendedFacing); } } - default boolean checkedSetExtendedFacing(ExtendedFacing alignment){ - if (isNewExtendedFacingValid(alignment)){ + default boolean checkedSetExtendedFacing(ExtendedFacing alignment) { + if (isNewExtendedFacingValid(alignment)) { setExtendedFacing(alignment); return true; } @@ -157,31 +157,31 @@ public interface IAlignment extends IAlignmentLimits,IAlignmentProvider { } default boolean isNewDirectionValid(ForgeDirection direction) { - return isNewExtendedFacingValid(direction,getRotation(),getFlip()); + return isNewExtendedFacingValid(direction, getRotation(), getFlip()); } - default boolean isNewRotationValid(Rotation rotation){ - return isNewExtendedFacingValid(getDirection(),rotation,getFlip()); + default boolean isNewRotationValid(Rotation rotation) { + return isNewExtendedFacingValid(getDirection(), rotation, getFlip()); } - default boolean isNewFlipValid(Flip flip){ - return isNewExtendedFacingValid(getDirection(),getRotation(),flip); + default boolean isNewFlipValid(Flip flip) { + return isNewExtendedFacingValid(getDirection(), getRotation(), flip); } default boolean isExtendedFacingValid() { - return isNewExtendedFacingValid(getDirection(),getRotation(),getFlip()); + return isNewExtendedFacingValid(getDirection(), getRotation(), getFlip()); } @Override - default boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip){ + default boolean isNewExtendedFacingValid(ForgeDirection direction, Rotation rotation, Flip flip) { return getAlignmentLimits().isNewExtendedFacingValid(direction, rotation, flip); } @Override - default boolean isNewExtendedFacingValid(ExtendedFacing alignment){ + default boolean isNewExtendedFacingValid(ExtendedFacing alignment) { return getAlignmentLimits().isNewExtendedFacingValid( - alignment.getDirection(), - alignment.getRotation(), - alignment.getFlip()); + alignment.getDirection(), + alignment.getRotation(), + alignment.getFlip()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java index 50eea865..c368caf1 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java @@ -1,4 +1,5 @@ package com.gtnewhorizon.structurelib.alignment; + import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import com.gtnewhorizon.structurelib.alignment.enumerable.Flip; import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation; @@ -18,9 +19,9 @@ public interface IAlignmentLimits { default boolean isNewExtendedFacingValid(ExtendedFacing alignment) { return isNewExtendedFacingValid( - alignment.getDirection(), - alignment.getRotation(), - alignment.getFlip()); + alignment.getDirection(), + alignment.getRotation(), + alignment.getFlip()); } static IAlignmentLimits allowOnly(ExtendedFacing... allowedFacings) { @@ -42,7 +43,8 @@ public interface IAlignmentLimits { class Builder { protected final boolean[] validStates = new boolean[STATES_COUNT]; - private Builder() {} + private Builder() { + } public static Builder allowAll() { Builder b = new Builder(); diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/IntegerAxisSwap.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/IntegerAxisSwap.java index ea546c3f..4f7da9d1 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/IntegerAxisSwap.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/IntegerAxisSwap.java @@ -16,69 +16,69 @@ public class IntegerAxisSwap { this.forFirstAxis = Direction.getAxisVector(forFirstAxis); this.forSecondAxis = Direction.getAxisVector(forSecondAxis); this.forThirdAxis = Direction.getAxisVector(forThirdAxis); - if(abs(this.forFirstAxis.get0())+abs(this.forSecondAxis.get0())+abs(this.forThirdAxis.get0())!=1 || - abs(this.forFirstAxis.get1())+abs(this.forSecondAxis.get1())+abs(this.forThirdAxis.get1())!=1 || - abs(this.forFirstAxis.get2())+abs(this.forSecondAxis.get2())+abs(this.forThirdAxis.get2())!=1){ - throw new IllegalArgumentException("Axis are overlapping/missing! "+ - forFirstAxis.name()+" "+ - forSecondAxis.name()+" "+ - forThirdAxis.name()); + if (abs(this.forFirstAxis.get0()) + abs(this.forSecondAxis.get0()) + abs(this.forThirdAxis.get0()) != 1 || + abs(this.forFirstAxis.get1()) + abs(this.forSecondAxis.get1()) + abs(this.forThirdAxis.get1()) != 1 || + abs(this.forFirstAxis.get2()) + abs(this.forSecondAxis.get2()) + abs(this.forThirdAxis.get2()) != 1) { + throw new IllegalArgumentException("Axis are overlapping/missing! " + + forFirstAxis.name() + " " + + forSecondAxis.name() + " " + + forThirdAxis.name()); } } - public Vec3Impl translate(Vec3Impl point){ + public Vec3Impl translate(Vec3Impl point) { return new Vec3Impl( - forFirstAxis.get0()*point.get0() +forFirstAxis.get1()*point.get1() +forFirstAxis.get2()*point.get2(), - forSecondAxis.get0()*point.get0()+forSecondAxis.get1()*point.get1()+forSecondAxis.get2()*point.get2(), - forThirdAxis.get0()*point.get0() +forThirdAxis.get1()*point.get1() +forThirdAxis.get2()*point.get2() + forFirstAxis.get0() * point.get0() + forFirstAxis.get1() * point.get1() + forFirstAxis.get2() * point.get2(), + forSecondAxis.get0() * point.get0() + forSecondAxis.get1() * point.get1() + forSecondAxis.get2() * point.get2(), + forThirdAxis.get0() * point.get0() + forThirdAxis.get1() * point.get1() + forThirdAxis.get2() * point.get2() ); } - public Vec3Impl inverseTranslate(Vec3Impl point){ + public Vec3Impl inverseTranslate(Vec3Impl point) { return new Vec3Impl( - forFirstAxis.get0()*point.get0()+forSecondAxis.get0()*point.get1()+forThirdAxis.get0()*point.get2(), - forFirstAxis.get1()*point.get0()+forSecondAxis.get1()*point.get1()+forThirdAxis.get1()*point.get2(), - forFirstAxis.get2()*point.get0()+forSecondAxis.get2()*point.get1()+forThirdAxis.get2()*point.get2() + forFirstAxis.get0() * point.get0() + forSecondAxis.get0() * point.get1() + forThirdAxis.get0() * point.get2(), + forFirstAxis.get1() * point.get0() + forSecondAxis.get1() * point.get1() + forThirdAxis.get1() * point.get2(), + forFirstAxis.get2() * point.get0() + forSecondAxis.get2() * point.get1() + forThirdAxis.get2() * point.get2() ); } - public Vec3 translate(Vec3 point){ + 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 + 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){ + 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 + 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]; - out[1]=forSecondAxis.get0()*point[0]+forSecondAxis.get1()*point[1]+forSecondAxis.get2()*point[2]; - out[2]=forThirdAxis.get0()*point[0] +forThirdAxis.get1()*point[1] +forThirdAxis.get2()*point[2]; + + public void translate(int[] point, int[] out) { + out[0] = forFirstAxis.get0() * point[0] + forFirstAxis.get1() * point[1] + forFirstAxis.get2() * point[2]; + out[1] = forSecondAxis.get0() * point[0] + forSecondAxis.get1() * point[1] + forSecondAxis.get2() * point[2]; + out[2] = forThirdAxis.get0() * point[0] + forThirdAxis.get1() * point[1] + forThirdAxis.get2() * point[2]; } - public void inverseTranslate(int[] point,int[] out){ - out[0]=forFirstAxis.get0()*point[0]+forSecondAxis.get0()*point[1]+forThirdAxis.get0()*point[2]; - out[1]=forFirstAxis.get1()*point[0]+forSecondAxis.get1()*point[1]+forThirdAxis.get1()*point[2]; - out[2]=forFirstAxis.get2()*point[0]+forSecondAxis.get2()*point[1]+forThirdAxis.get2()*point[2]; + public void inverseTranslate(int[] point, int[] out) { + out[0] = forFirstAxis.get0() * point[0] + forSecondAxis.get0() * point[1] + forThirdAxis.get0() * point[2]; + out[1] = forFirstAxis.get1() * point[0] + forSecondAxis.get1() * point[1] + forThirdAxis.get1() * point[2]; + out[2] = forFirstAxis.get2() * point[0] + forSecondAxis.get2() * point[1] + forThirdAxis.get2() * point[2]; } - public void translate(double[] point,double[] out){ - out[0]=forFirstAxis.get0()*point[0] +forFirstAxis.get1()*point[1] +forFirstAxis.get2()*point[2]; - out[1]=forSecondAxis.get0()*point[0]+forSecondAxis.get1()*point[1]+forSecondAxis.get2()*point[2]; - out[2]=forThirdAxis.get0()*point[0] +forThirdAxis.get1()*point[1] +forThirdAxis.get2()*point[2]; + public void translate(double[] point, double[] out) { + out[0] = forFirstAxis.get0() * point[0] + forFirstAxis.get1() * point[1] + forFirstAxis.get2() * point[2]; + out[1] = forSecondAxis.get0() * point[0] + forSecondAxis.get1() * point[1] + forSecondAxis.get2() * point[2]; + out[2] = forThirdAxis.get0() * point[0] + forThirdAxis.get1() * point[1] + forThirdAxis.get2() * point[2]; } - public void inverseTranslate(double[] point,double[] out){ - out[0]=forFirstAxis.get0()*point[0]+forSecondAxis.get0()*point[1]+forThirdAxis.get0()*point[2]; - out[1]=forFirstAxis.get1()*point[0]+forSecondAxis.get1()*point[1]+forThirdAxis.get1()*point[2]; - out[2]=forFirstAxis.get2()*point[0]+forSecondAxis.get2()*point[1]+forThirdAxis.get2()*point[2]; + public void inverseTranslate(double[] point, double[] out) { + out[0] = forFirstAxis.get0() * point[0] + forSecondAxis.get0() * point[1] + forThirdAxis.get0() * point[2]; + out[1] = forFirstAxis.get1() * point[0] + forSecondAxis.get1() * point[1] + forThirdAxis.get1() * point[2]; + out[2] = forFirstAxis.get2() * point[0] + forSecondAxis.get2() * point[1] + forThirdAxis.get2() * point[2]; } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/ConstructableUtility.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/ConstructableUtility.java index 4369f1e5..f881f88b 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/ConstructableUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/ConstructableUtility.java @@ -43,10 +43,10 @@ public class ConstructableUtility { IMultiblockInfoContainer iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass()); if (tTileEntity instanceof IAlignment) { iMultiblockInfoContainer.construct(aStack, false, tTileEntity, - ((IAlignment) tTileEntity).getExtendedFacing()); + ((IAlignment) tTileEntity).getExtendedFacing()); } else { iMultiblockInfoContainer.construct(aStack, false, tTileEntity, - ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); + ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); } } } @@ -68,10 +68,10 @@ public class ConstructableUtility { IMultiblockInfoContainer iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass()); if (tTileEntity instanceof IAlignment) { iMultiblockInfoContainer.construct(aStack, true, tTileEntity, - ((IAlignment) tTileEntity).getExtendedFacing()); + ((IAlignment) tTileEntity).getExtendedFacing()); } else { iMultiblockInfoContainer.construct(aStack, true, tTileEntity, - ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); + ExtendedFacing.of(ForgeDirection.getOrientation(aSide))); } StructureLib.addClientSideChatMessages(IMultiblockInfoContainer.get(tTileEntity.getClass()).getDescription(aStack)); return false; diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/IConstructableProvider.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/IConstructableProvider.java index 149898f6..5e58b11c 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/IConstructableProvider.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/constructable/IConstructableProvider.java @@ -6,9 +6,9 @@ import javax.annotation.Nullable; * Implement this interface if this tile entity MIGHT be constructable */ public interface IConstructableProvider { - /** - * @return null if not constructable, an instance otherwise. - */ - @Nullable - IConstructable getConstructable(); + /** + * @return null if not constructable, an instance otherwise. + */ + @Nullable + IConstructable getConstructable(); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Direction.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Direction.java index 5aa23028..4352cf08 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Direction.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Direction.java @@ -13,11 +13,11 @@ public enum Direction { private final ForgeDirection forgeDirection; private final Vec3Impl axisVector; - public static final Direction[] VALUES=values(); + public static final Direction[] VALUES = values(); Direction(ForgeDirection forgeDirection) { this.forgeDirection = forgeDirection; - axisVector=new Vec3Impl(forgeDirection.offsetX,forgeDirection.offsetY,forgeDirection.offsetZ); + axisVector = new Vec3Impl(forgeDirection.offsetX, forgeDirection.offsetY, forgeDirection.offsetZ); } public ForgeDirection getForgeDirection() { @@ -28,7 +28,7 @@ public enum Direction { return axisVector; } - public static Vec3Impl getAxisVector(ForgeDirection forgeDirection){ + public static Vec3Impl getAxisVector(ForgeDirection forgeDirection) { return VALUES[forgeDirection.ordinal()].axisVector; } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/ExtendedFacing.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/ExtendedFacing.java index 9d22fb80..d0cd827b 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/ExtendedFacing.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/ExtendedFacing.java @@ -114,19 +114,20 @@ public enum ExtendedFacing { EAST_COUNTER_CLOCKWISE_VERTICAL("east counter clockwise vertical"), EAST_COUNTER_CLOCKWISE_BOTH("east counter clockwise both"); - public static final ExtendedFacing DEFAULT=NORTH_NORMAL_NONE; + public static final ExtendedFacing DEFAULT = NORTH_NORMAL_NONE; public static final ExtendedFacing[] VALUES = values(); - public static final Map> FOR_FACING=new HashMap<>(); + public static final Map> FOR_FACING = new HashMap<>(); public static final int STATES_COUNT = VALUES.length; + static { stream(values()).forEach(extendedFacing -> - FOR_FACING.compute(extendedFacing.direction, ((forgeDirection, extendedFacings) -> { - if (extendedFacings == null) { - extendedFacings = new ArrayList<>(); - } - extendedFacings.add(extendedFacing); - return extendedFacings; - }))); + FOR_FACING.compute(extendedFacing.direction, ((forgeDirection, extendedFacings) -> { + if (extendedFacings == null) { + extendedFacings = new ArrayList<>(); + } + extendedFacings.add(extendedFacing); + return extendedFacings; + }))); } private static final Map NAME_LOOKUP = stream(VALUES).collect(toMap(ExtendedFacing::getName2, (extendedFacing) -> extendedFacing)); @@ -143,133 +144,146 @@ public enum ExtendedFacing { ExtendedFacing(String name) { this.name = name; - direction= Direction.VALUES[ordinal()/(ROTATIONS_COUNT*FLIPS_COUNT)].getForgeDirection(); - rotation=Rotation.VALUES[ordinal()/FLIPS_COUNT-direction.ordinal()*ROTATIONS_COUNT]; - flip=Flip.VALUES[ordinal()%FLIPS_COUNT]; - ForgeDirection a,b,c; - switch (direction){ + direction = Direction.VALUES[ordinal() / (ROTATIONS_COUNT * FLIPS_COUNT)].getForgeDirection(); + rotation = Rotation.VALUES[ordinal() / FLIPS_COUNT - direction.ordinal() * ROTATIONS_COUNT]; + flip = Flip.VALUES[ordinal() % FLIPS_COUNT]; + ForgeDirection a, b, c; + switch (direction) { case DOWN: - a= ForgeDirection.WEST; - b= ForgeDirection.SOUTH; - c= ForgeDirection.UP; + a = ForgeDirection.WEST; + b = ForgeDirection.SOUTH; + c = ForgeDirection.UP; break; case UP: - a= ForgeDirection.EAST; - b= ForgeDirection.SOUTH; - c= ForgeDirection.DOWN; + a = ForgeDirection.EAST; + b = ForgeDirection.SOUTH; + c = ForgeDirection.DOWN; break; case NORTH: - a= ForgeDirection.WEST; - b= ForgeDirection.DOWN; - c= ForgeDirection.SOUTH; + a = ForgeDirection.WEST; + b = ForgeDirection.DOWN; + c = ForgeDirection.SOUTH; break; case SOUTH: - a= ForgeDirection.EAST; - b= ForgeDirection.DOWN; - c= ForgeDirection.NORTH; + a = ForgeDirection.EAST; + b = ForgeDirection.DOWN; + c = ForgeDirection.NORTH; break; case WEST: - a= ForgeDirection.SOUTH; - b= ForgeDirection.DOWN; - c= ForgeDirection.EAST; + a = ForgeDirection.SOUTH; + b = ForgeDirection.DOWN; + c = ForgeDirection.EAST; break; case EAST: - a= ForgeDirection.NORTH; - b= ForgeDirection.DOWN; - c= ForgeDirection.WEST; + a = ForgeDirection.NORTH; + b = ForgeDirection.DOWN; + c = ForgeDirection.WEST; break; - default:throw new RuntimeException("Is impossible..."); + default: + throw new RuntimeException("Is impossible..."); } - switch (flip){//This duplicates some axis swaps since flip boolean would do, but seems more convenient to use + switch (flip) {//This duplicates some axis swaps since flip boolean would do, but seems more convenient to use case HORIZONTAL: - a=a.getOpposite(); + a = a.getOpposite(); break; case BOTH: - a=a.getOpposite(); + a = a.getOpposite(); case VERTICAL: - b=b.getOpposite(); + b = b.getOpposite(); break; - case NONE: break; - default:throw new RuntimeException("Even more impossible..."); + case NONE: + break; + default: + throw new RuntimeException("Even more impossible..."); } switch (rotation) { case CLOCKWISE: { - ForgeDirection _a=a; - a =b; - b =_a.getOpposite(); + ForgeDirection _a = a; + a = b; + b = _a.getOpposite(); break; } case UPSIDE_DOWN: - a=a.getOpposite(); - b=b.getOpposite(); + a = a.getOpposite(); + b = b.getOpposite(); break; case COUNTER_CLOCKWISE: { - ForgeDirection _a=a; - a =b.getOpposite(); - b =_a; + ForgeDirection _a = a; + a = b.getOpposite(); + b = _a; break; } - case NORMAL: break; + case NORMAL: + break; default: throw new RuntimeException("More impossible..."); } - this.a=a; - this.b=b; - this.c=c; - integerAxisSwap =new IntegerAxisSwap(a,b,c); + this.a = a; + this.b = b; + this.c = c; + integerAxisSwap = new IntegerAxisSwap(a, b, c); } - public static ExtendedFacing of(ForgeDirection direction, Rotation rotation, Flip flip){ - if(direction==ForgeDirection.UNKNOWN){ + public static ExtendedFacing of(ForgeDirection direction, Rotation rotation, Flip flip) { + if (direction == ForgeDirection.UNKNOWN) { return VALUES[IAlignment.getAlignmentIndex(ForgeDirection.NORTH, rotation, flip)]; } return VALUES[IAlignment.getAlignmentIndex(direction, rotation, flip)]; } - public static ExtendedFacing of(ForgeDirection direction){ - if(direction==ForgeDirection.UNKNOWN){ + public static ExtendedFacing of(ForgeDirection direction) { + if (direction == ForgeDirection.UNKNOWN) { return DEFAULT; } return VALUES[IAlignment.getAlignmentIndex(direction, Rotation.NORMAL, Flip.NONE)]; } - public static ImmutableSet getAllWith(ForgeDirection direction) { return LOOKUP_BY_DIRECTION.get(direction);} - public static ImmutableSet getAllWith(Rotation rotation) { return LOOKUP_BY_ROTATION.get(rotation);} - public static ImmutableSet getAllWith(Flip flip) { return LOOKUP_BY_FLIP.get(flip);} - - public ExtendedFacing with(ForgeDirection direction){ - return of(direction,rotation,flip); + public static ImmutableSet getAllWith(ForgeDirection direction) { + return LOOKUP_BY_DIRECTION.get(direction); } - public ExtendedFacing with(Rotation rotation){ - return of(direction,rotation,flip); + public static ImmutableSet getAllWith(Rotation rotation) { + return LOOKUP_BY_ROTATION.get(rotation); } - public ExtendedFacing with(Flip flip){ - return of(direction,rotation,flip); + public static ImmutableSet getAllWith(Flip flip) { + return LOOKUP_BY_FLIP.get(flip); + } + + public ExtendedFacing with(ForgeDirection direction) { + return of(direction, rotation, flip); + } + + public ExtendedFacing with(Rotation rotation) { + return of(direction, rotation, flip); + } + + public ExtendedFacing with(Flip flip) { + return of(direction, rotation, flip); } public ExtendedFacing getOppositeDirection() { - return of(direction.getOpposite(),rotation,flip); + return of(direction.getOpposite(), rotation, flip); } public ExtendedFacing getOppositeRotation() { - return of(direction,rotation.getOpposite(),flip); + return of(direction, rotation.getOpposite(), flip); } public ExtendedFacing getOppositeFlip() { - return of(direction,rotation,flip.getOpposite()); + return of(direction, rotation, flip.getOpposite()); } /** * Gets the same effective facing achieved by different rot/flip combo + * * @return same effective facing, but different enum value */ - public ExtendedFacing getDuplicate(){ - return of(direction,rotation.getOpposite(),flip.getOpposite()); + public ExtendedFacing getDuplicate() { + return of(direction, rotation.getOpposite(), flip.getOpposite()); } - public int getIndex(){ + public int getIndex() { return ordinal(); } @@ -307,39 +321,47 @@ public enum ExtendedFacing { /** * Translates relative to front facing offset to world offset + * * @param abcOffset A,B,C offset (facing relative L-->R,U-->D,F-->B) - * @return X,Y,Z offset in world + * @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); } - public void getWorldOffset(int[] point,int[] out){ - integerAxisSwap.inverseTranslate(point,out); + + public void getWorldOffset(int[] point, int[] out) { + integerAxisSwap.inverseTranslate(point, out); } - public void getWorldOffset(double[] point,double[] out){ - integerAxisSwap.inverseTranslate(point,out); + + public void getWorldOffset(double[] point, double[] out) { + integerAxisSwap.inverseTranslate(point, out); } /** * Translates world offset to relative front facing offset + * * @param xyzOffset X,Y,Z offset in world - * @return A,B,C offset (facing relative L-->R,U-->D,F-->B) + * @return A, B, C offset (facing relative L-->R,U-->D,F-->B) */ - public Vec3 getOffsetABC(Vec3 xyzOffset){ + public Vec3 getOffsetABC(Vec3 xyzOffset) { return integerAxisSwap.translate(xyzOffset); } - public Vec3Impl getOffsetABC(Vec3Impl xyzOffset){ + + public Vec3Impl getOffsetABC(Vec3Impl xyzOffset) { return integerAxisSwap.translate(xyzOffset); } - public void getOffsetABC(int[] point,int[] out){ - integerAxisSwap.translate(point,out); + + public void getOffsetABC(int[] point, int[] out) { + integerAxisSwap.translate(point, out); } - public void getOffsetABC(double[] point,double[] out){ - integerAxisSwap.translate(point,out); + + public void getOffsetABC(double[] point, double[] out) { + integerAxisSwap.translate(point, out); } public IntegerAxisSwap getIntegerAxisSwap() { diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Flip.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Flip.java index 76dc5f5d..f4befdfa 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Flip.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Flip.java @@ -26,7 +26,7 @@ public enum Flip { this.name = nameIn; } - public int getIndex(){ + public int getIndex() { return ordinal(); } @@ -58,19 +58,19 @@ public enum Flip { return this.name; } - public boolean isNotFlipped(){ - return this==NONE; + public boolean isNotFlipped() { + return this == NONE; } - public boolean isBothFlipped(){ - return this==BOTH; + public boolean isBothFlipped() { + return this == BOTH; } public boolean isHorizontallyFlipped() { - return this==HORIZONTAL || isBothFlipped(); + return this == HORIZONTAL || isBothFlipped(); } public boolean isVerticallyFliped() { - return this==VERTICAL || isBothFlipped(); + return this == VERTICAL || isBothFlipped(); } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Rotation.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Rotation.java index 9ae01f20..c66f1557 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Rotation.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/enumerable/Rotation.java @@ -26,7 +26,7 @@ public enum Rotation { this.name = nameIn; } - public int getIndex(){ + public int getIndex() { return ordinal(); } @@ -58,19 +58,19 @@ public enum Rotation { return this.name; } - public boolean isNotRotated(){ - return this==NORMAL; + public boolean isNotRotated() { + return this == NORMAL; } - public boolean isClockwise(){ - return this==CLOCKWISE; + public boolean isClockwise() { + return this == CLOCKWISE; } - public boolean isCounterClockwise(){ - return this==COUNTER_CLOCKWISE; + public boolean isCounterClockwise() { + return this == COUNTER_CLOCKWISE; } - public boolean isUpsideDown(){ - return this==UPSIDE_DOWN; + public boolean isUpsideDown() { + return this == UPSIDE_DOWN; } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/block/BlockHint.java b/src/main/java/com/gtnewhorizon/structurelib/block/BlockHint.java index 25dce36c..5551e098 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/block/BlockHint.java +++ b/src/main/java/com/gtnewhorizon/structurelib/block/BlockHint.java @@ -16,52 +16,52 @@ import net.minecraft.world.IBlockAccess; import java.util.List; public class BlockHint extends Block { - private static final IIcon[] hint = new IIcon[16]; + private static final IIcon[] hint = new IIcon[16]; - public BlockHint() { - super(Material.iron); - setBlockName("structurelib.blockhint"); - setCreativeTab(StructureLib.creativeTab); - } + public BlockHint() { + super(Material.iron); + setBlockName("structurelib.blockhint"); + setCreativeTab(StructureLib.creativeTab); + } - @Override - public void registerBlockIcons(IIconRegister aIconRegister) { - //super.registerBlockIcons(aIconRegister); - hint[0] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_0"); - hint[1] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_1"); - hint[2] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_2"); - hint[3] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_3"); - hint[4] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_4"); - hint[5] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_5"); - hint[6] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_6"); - hint[7] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_7"); - hint[8] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_8"); - hint[9] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_9"); - hint[10] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_10"); - hint[11] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_11"); - hint[12] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_DEFAULT"); - hint[13] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_AIR"); - hint[14] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_NOAIR"); - hint[15] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_ERROR"); - } + @Override + public void registerBlockIcons(IIconRegister aIconRegister) { + //super.registerBlockIcons(aIconRegister); + hint[0] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_0"); + hint[1] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_1"); + hint[2] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_2"); + hint[3] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_3"); + hint[4] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_4"); + hint[5] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_5"); + hint[6] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_6"); + hint[7] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_7"); + hint[8] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_8"); + hint[9] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_9"); + hint[10] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_10"); + hint[11] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_11"); + hint[12] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_DEFAULT"); + hint[13] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_AIR"); + hint[14] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_NOAIR"); + hint[15] = aIconRegister.registerIcon(StructureLibAPI.MOD_ID + ":iconsets/HINT_ERROR"); + } - @Override - public IIcon getIcon(int aSide, int aMeta) { - return hint[aMeta]; - } + @Override + public IIcon getIcon(int aSide, int aMeta) { + return hint[aMeta]; + } - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(IBlockAccess aWorld, int xCoord, int yCoord, int zCoord, int aSide) { - int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); - return getIcon(aSide, tMeta); - } + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess aWorld, int xCoord, int yCoord, int zCoord, int aSide) { + int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + return getIcon(aSide, tMeta); + } - @Override - @SuppressWarnings("unchecked") - public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { - for (int i = 0; i <= 15; i++) { - aList.add(new ItemStack(aItem, 1, i)); - } - } + @Override + @SuppressWarnings("unchecked") + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + for (int i = 0; i <= 15; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/entity/fx/EntityFXBlockHint.java b/src/main/java/com/gtnewhorizon/structurelib/entity/fx/EntityFXBlockHint.java index 694e21e1..fdd9d86e 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/entity/fx/EntityFXBlockHint.java +++ b/src/main/java/com/gtnewhorizon/structurelib/entity/fx/EntityFXBlockHint.java @@ -15,14 +15,13 @@ import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class EntityFXBlockHint extends EntityFX { private IIcon[] icons; - private short[] mRGBa = {255,255,255,0}; + private short[] mRGBa = {255, 255, 255, 0}; - public EntityFXBlockHint(World world){ - this(world,0,0,0, Blocks.stone,0); + public EntityFXBlockHint(World world) { + this(world, 0, 0, 0, Blocks.stone, 0); } /** - * * @param world * @param x * @param y @@ -37,11 +36,11 @@ public class EntityFXBlockHint extends EntityFX { prevPosZ = posZ; noClip = true; particleMaxAge = 2000 + StructureLib.RANDOM.nextInt(200); - this.icons=icons; + this.icons = icons; } public EntityFXBlockHint(World world, int x, int y, int z, Block block, int meta) { - super(world, x+.25, y+.5, z+.25); + super(world, x + .25, y + .5, z + .25); particleGravity = 0; prevPosX = posX; prevPosY = posY; @@ -54,8 +53,8 @@ public class EntityFXBlockHint extends EntityFX { } } - public EntityFXBlockHint withColorTint(short[] coloure){ - this.mRGBa =coloure; + public EntityFXBlockHint withColorTint(short[] coloure) { + this.mRGBa = coloure; return this; } @@ -71,15 +70,15 @@ public class EntityFXBlockHint extends EntityFX { //var8, var9 - X U //var 10, var 11 - Y V - for(int i=0;i<6;i++){ - if(icons[i]==null) { + for (int i = 0; i < 6; i++) { + if (icons[i] == null) { continue; } - double u=icons[i].getMinU(); - double U=icons[i].getMaxU(); - double v=icons[i].getMinV(); - double V=icons[i].getMaxV(); - switch (i){//{DOWN, UP, NORTH, SOUTH, WEST, EAST} + double u = icons[i].getMinU(); + double U = icons[i].getMaxU(); + double v = icons[i].getMinV(); + double V = icons[i].getMaxV(); + switch (i) {//{DOWN, UP, NORTH, SOUTH, WEST, EAST} case 0: tes.addVertexWithUV(X, Y, Z + size, u, V); tes.addVertexWithUV(X, Y, Z, u, v); @@ -129,7 +128,7 @@ public class EntityFXBlockHint extends EntityFX { @Override public boolean shouldRenderInPass(int pass) { - return pass==2; + return pass == 2; } @Override diff --git a/src/main/java/com/gtnewhorizon/structurelib/entity/fx/WeightlessParticleFX.java b/src/main/java/com/gtnewhorizon/structurelib/entity/fx/WeightlessParticleFX.java index b2afa126..34be31ac 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/entity/fx/WeightlessParticleFX.java +++ b/src/main/java/com/gtnewhorizon/structurelib/entity/fx/WeightlessParticleFX.java @@ -6,31 +6,27 @@ import net.minecraft.client.particle.EntityFX; import net.minecraft.world.World; @SideOnly(Side.CLIENT) -public class WeightlessParticleFX extends EntityFX -{ - public WeightlessParticleFX(World p_i1205_1_, double p_i1205_2_, double p_i1205_4_, double p_i1205_6_, double p_i1205_8_, double p_i1205_10_, double p_i1205_12_) - { +public class WeightlessParticleFX extends EntityFX { + public WeightlessParticleFX(World p_i1205_1_, double p_i1205_2_, double p_i1205_4_, double p_i1205_6_, double p_i1205_8_, double p_i1205_10_, double p_i1205_12_) { super(p_i1205_1_, p_i1205_2_, p_i1205_4_, p_i1205_6_, p_i1205_8_, p_i1205_10_, p_i1205_12_); - this.motionX = p_i1205_8_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F); - this.motionY = p_i1205_10_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F); - this.motionZ = p_i1205_12_ + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.05F); + this.motionX = p_i1205_8_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F); + this.motionY = p_i1205_10_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F); + this.motionZ = p_i1205_12_ + (double) ((float) (Math.random() * 2.0D - 1.0D) * 0.05F); this.particleRed = this.particleGreen = this.particleBlue = this.rand.nextFloat() * 0.3F + 0.7F; this.particleScale = this.rand.nextFloat() * this.rand.nextFloat() * 6.0F + 1.0F; - this.particleMaxAge = (int)(16.0D / ((double)this.rand.nextFloat() * 0.8D + 0.2D)) + 2; - this.noClip=true; + this.particleMaxAge = (int) (16.0D / ((double) this.rand.nextFloat() * 0.8D + 0.2D)) + 2; + this.noClip = true; } /** * Called to update the entity's position/logic. */ - public void onUpdate() - { + public void onUpdate() { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; - if (this.particleAge++ >= this.particleMaxAge) - { + if (this.particleAge++ >= this.particleMaxAge) { this.setDead(); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java index 01f5fa8a..d62ac5c4 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java @@ -12,55 +12,55 @@ import java.util.List; import static net.minecraft.util.StatCollector.translateToLocal; public class ItemBlockHint extends ItemBlock { - public ItemBlockHint(Block p_i45328_1_) { - super(p_i45328_1_); - setMaxDamage(0); - setHasSubtypes(true); - setCreativeTab(CreativeTabs.tabBlock); - } + public ItemBlockHint(Block p_i45328_1_) { + super(p_i45328_1_); + setMaxDamage(0); + setHasSubtypes(true); + setCreativeTab(CreativeTabs.tabBlock); + } - @Override - @SuppressWarnings("unchecked") - public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { - aList.add(translateToLocal("structurelib.blockhint.desc.0"));//Helps while building - switch (aStack.getItemDamage()) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.1"));//Placeholder for a certain group. - break; - case 12: - aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.2"));//General placeholder. - break; - case 13: - aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.3"));//Make sure it contains Air material. - break; - case 14: - aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.4"));//Make sure it does not contain Air material. - break; - case 15: - aList.add(EnumChatFormatting.BLUE.toString() + translateToLocal("structurelib.blockhint.desc.5"));//ERROR, what did u expect? - break; - default://WTF? - aList.add("Damn son where did you get that!?"); - aList.add(EnumChatFormatting.BLUE.toString() + "From outer space... I guess..."); - } - } + @Override + @SuppressWarnings("unchecked") + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + aList.add(translateToLocal("structurelib.blockhint.desc.0"));//Helps while building + switch (aStack.getItemDamage()) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.1"));//Placeholder for a certain group. + break; + case 12: + aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.2"));//General placeholder. + break; + case 13: + aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.3"));//Make sure it contains Air material. + break; + case 14: + aList.add(EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + translateToLocal("structurelib.blockhint.desc.4"));//Make sure it does not contain Air material. + break; + case 15: + aList.add(EnumChatFormatting.BLUE.toString() + translateToLocal("structurelib.blockhint.desc.5"));//ERROR, what did u expect? + break; + default://WTF? + aList.add("Damn son where did you get that!?"); + aList.add(EnumChatFormatting.BLUE.toString() + "From outer space... I guess..."); + } + } - public int getMetadata(int aMeta) { - return aMeta; - } + public int getMetadata(int aMeta) { + return aMeta; + } - public String getUnlocalizedName(ItemStack aStack) { - return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack); - } + public String getUnlocalizedName(ItemStack aStack) { + return this.field_150939_a.getUnlocalizedName() + "." + getDamage(aStack); + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemFrontRotationTool.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemFrontRotationTool.java index 8f0a9814..3e000fd1 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemFrontRotationTool.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemFrontRotationTool.java @@ -16,23 +16,23 @@ import static com.gtnewhorizon.structurelib.StructureLibAPI.MOD_ID; import static net.minecraft.util.StatCollector.translateToLocal; public class ItemFrontRotationTool extends Item { - public ItemFrontRotationTool() { - setMaxStackSize(1); - setUnlocalizedName("structurelib.frontRotationTool"); - setTextureName(MOD_ID + ":itemFrontRotationTool"); - setCreativeTab(StructureLib.creativeTab); - } + public ItemFrontRotationTool() { + setMaxStackSize(1); + setUnlocalizedName("structurelib.frontRotationTool"); + setTextureName(MOD_ID + ":itemFrontRotationTool"); + setCreativeTab(StructureLib.creativeTab); + } - @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - return AlignmentUtility.handle(player, world, x, y, z); - } + @Override + public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + return AlignmentUtility.handle(player, world, x, y, z); + } - @Override - @SideOnly(Side.CLIENT) - public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { - aList.add(translateToLocal("item.structurelib.frontRotationTool.desc.0"));//Triggers Front Rotation Interface - aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1"));//Rotates only the front panel, - aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2"));//which allows structure rotation. - } + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { + aList.add(translateToLocal("item.structurelib.frontRotationTool.desc.0"));//Triggers Front Rotation Interface + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1"));//Rotates only the front panel, + aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2"));//which allows structure rotation. + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/proxy/CommonProxy.java b/src/main/java/com/gtnewhorizon/structurelib/proxy/CommonProxy.java index 17e9ebfd..dae0878e 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/proxy/CommonProxy.java +++ b/src/main/java/com/gtnewhorizon/structurelib/proxy/CommonProxy.java @@ -7,20 +7,35 @@ import net.minecraft.util.IIcon; import net.minecraft.world.World; public class CommonProxy { - public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa){} - public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa){} - public void hintParticle(World w, int x, int y, int z, IIcon[] icons){} - public void hintParticle(World w, int x, int y, int z, Block block, int meta){} - public EntityPlayer getCurrentPlayer() { - return null; - } - public boolean isCurrentPlayer(EntityPlayer player) { - return false; - } - public void addClientSideChatMessages(String... messages){ - } - public void startHinting(World w) {} - public void endHinting(World w) {} + public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) { + } - public void preInit(FMLPreInitializationEvent e) {} + public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) { + } + + public void hintParticle(World w, int x, int y, int z, IIcon[] icons) { + } + + public void hintParticle(World w, int x, int y, int z, Block block, int meta) { + } + + public EntityPlayer getCurrentPlayer() { + return null; + } + + public boolean isCurrentPlayer(EntityPlayer player) { + return false; + } + + public void addClientSideChatMessages(String... messages) { + } + + public void startHinting(World w) { + } + + public void endHinting(World w) { + } + + public void preInit(FMLPreInitializationEvent e) { + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IBlockPosConsumer.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IBlockPosConsumer.java index f875c54a..568e1924 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IBlockPosConsumer.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IBlockPosConsumer.java @@ -3,5 +3,5 @@ package com.gtnewhorizon.structurelib.structure; import net.minecraft.world.World; public interface IBlockPosConsumer { - void consume(World world, int x, int y, int z); + void consume(World world, int x, int y, int z); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/ICustomBlockSetting.java b/src/main/java/com/gtnewhorizon/structurelib/structure/ICustomBlockSetting.java index 5e6c0c81..db52edd5 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/ICustomBlockSetting.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/ICustomBlockSetting.java @@ -4,15 +4,15 @@ import net.minecraft.block.Block; import net.minecraft.world.World; public interface ICustomBlockSetting { - /** - * Default block setting calls {@link World#setBlock(int x, int y, int z, Block block, int meta, int updateType)} like: - * {@code world.setBlock(x,y,z,this/block,meta,2)} where updateType 2 means to update lighting and stuff - * - * @param world world that should be affected - * @param x x position to set - * @param y y position to set - * @param z z position to set - * @param meta required meta - */ - void setBlock(World world, int x, int y, int z, int meta); + /** + * Default block setting calls {@link World#setBlock(int x, int y, int z, Block block, int meta, int updateType)} like: + * {@code world.setBlock(x,y,z,this/block,meta,2)} where updateType 2 means to update lighting and stuff + * + * @param world world that should be affected + * @param x x position to set + * @param y y position to set + * @param z z position to set + * @param meta required meta + */ + void setBlock(World world, int x, int y, int z, int meta); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java index 18f47459..6b9082ff 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java @@ -10,169 +10,169 @@ import java.util.Arrays; import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE; public interface IStructureDefinition { - /** - * Used internally - * - * Might, but is not required, to throw {@link java.util.NoSuchElementException} if the given structure piece is not found. - * - * @param name same name as for other methods here - * @return the array of elements to process - * @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly matches - */ - IStructureElement[] getStructureFor(String name); + /** + * Used internally + *

+ * Might, but is not required, to throw {@link java.util.NoSuchElementException} if the given structure piece is not found. + * + * @param name same name as for other methods here + * @return the array of elements to process + * @throws java.util.NoSuchElementException if the given structure piece is not found and the moon phase perfectly matches + */ + IStructureElement[] getStructureFor(String name); - default boolean check(T object, String piece, World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - boolean forceCheckAllBlocks) { - return iterate(object, null, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, - basePositionA, basePositionB, basePositionC, false, forceCheckAllBlocks); - } + default boolean check(T object, String piece, World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + boolean forceCheckAllBlocks) { + return iterate(object, null, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, false, forceCheckAllBlocks); + } - default boolean hints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC) { - return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, - basePositionA, basePositionB, basePositionC, true, null); - } + default boolean hints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC) { + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, true, null); + } - default boolean build(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC) { - return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, - basePositionA, basePositionB, basePositionC, false, null); - } + default boolean build(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC) { + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, false, null); + } - default boolean buildOrHints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - boolean hintsOnly) { - return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, - basePositionA, basePositionB, basePositionC, hintsOnly, null); - } + default boolean buildOrHints(T object, ItemStack trigger, String piece, World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + boolean hintsOnly) { + return iterate(object, trigger, getStructureFor(piece), world, extendedFacing, basePositionX, basePositionY, basePositionZ, + basePositionA, basePositionB, basePositionC, hintsOnly, null); + } - static boolean iterate(T object, ItemStack trigger, IStructureElement[] elements, World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue) { - if (world.isRemote ^ hintsOnly) { - return false; - } + static boolean iterate(T object, ItemStack trigger, IStructureElement[] elements, World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + boolean hintsOnly, Boolean checkBlocksIfNotNullForceCheckAllIfTrue) { + if (world.isRemote ^ hintsOnly) { + return false; + } - //change base position to base offset - basePositionA = -basePositionA; - basePositionB = -basePositionB; - basePositionC = -basePositionC; + //change base position to base offset + basePositionA = -basePositionA; + basePositionB = -basePositionB; + basePositionC = -basePositionC; - int[] abc = new int[]{basePositionA, basePositionB, basePositionC}; - int[] xyz = new int[3]; + int[] abc = new int[]{basePositionA, basePositionB, basePositionC}; + int[] xyz = new int[3]; - if (checkBlocksIfNotNullForceCheckAllIfTrue != null) { - if (checkBlocksIfNotNullForceCheckAllIfTrue) { - for (IStructureElement element : elements) { - if (element.isNavigating()) { - abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); - abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); - abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); - } else { - extendedFacing.getWorldOffset(abc, xyz); - xyz[0] += basePositionX; - xyz[1] += basePositionY; - xyz[2] += basePositionZ; + if (checkBlocksIfNotNullForceCheckAllIfTrue != null) { + if (checkBlocksIfNotNullForceCheckAllIfTrue) { + for (IStructureElement element : elements) { + if (element.isNavigating()) { + abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); + abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); + abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); + } else { + extendedFacing.getWorldOffset(abc, xyz); + xyz[0] += basePositionX; + xyz[1] += basePositionY; + xyz[2] += basePositionZ; - if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) { - if (DEBUG_MODE) { - StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " + - Arrays.toString(xyz) + " " + Arrays.toString(abc)); - } - return false; - } - } else { - if (DEBUG_MODE) { - StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " + - Arrays.toString(xyz) + " " + Arrays.toString(abc)); - } - return false; - } - abc[0] += 1; - } - } - } else { - for (IStructureElement element : elements) { - if (element.isNavigating()) { - abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); - abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); - abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); - } else { - extendedFacing.getWorldOffset(abc, xyz); - xyz[0] += basePositionX; - xyz[1] += basePositionY; - xyz[2] += basePositionZ; + if (world.blockExists(xyz[0], xyz[1], xyz[2])) { + if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) { + if (DEBUG_MODE) { + StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " + + Arrays.toString(xyz) + " " + Arrays.toString(abc)); + } + return false; + } + } else { + if (DEBUG_MODE) { + StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " + + Arrays.toString(xyz) + " " + Arrays.toString(abc)); + } + return false; + } + abc[0] += 1; + } + } + } else { + for (IStructureElement element : elements) { + if (element.isNavigating()) { + abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); + abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); + abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); + } else { + extendedFacing.getWorldOffset(abc, xyz); + xyz[0] += basePositionX; + xyz[1] += basePositionY; + xyz[2] += basePositionZ; - if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) { - if (DEBUG_MODE) { - StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " + - Arrays.toString(xyz) + " " + Arrays.toString(abc)); - } - return false; - } - } else { - if (DEBUG_MODE) { - StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " + - Arrays.toString(xyz) + " " + Arrays.toString(abc)); - } - } - abc[0] += 1; - } - } - } - if (DEBUG_MODE) { - StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] pass"); - } - } else { - if (hintsOnly) { - for (IStructureElement element : elements) { - if (element.isNavigating()) { - abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); - abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); - abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); - } else { - extendedFacing.getWorldOffset(abc, xyz); - xyz[0] += basePositionX; - xyz[1] += basePositionY; - xyz[2] += basePositionZ; + if (world.blockExists(xyz[0], xyz[1], xyz[2])) { + if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) { + if (DEBUG_MODE) { + StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] failed @ " + + Arrays.toString(xyz) + " " + Arrays.toString(abc)); + } + return false; + } + } else { + if (DEBUG_MODE) { + StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] !blockExists @ " + + Arrays.toString(xyz) + " " + Arrays.toString(abc)); + } + } + abc[0] += 1; + } + } + } + if (DEBUG_MODE) { + StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] pass"); + } + } else { + if (hintsOnly) { + for (IStructureElement element : elements) { + if (element.isNavigating()) { + abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); + abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); + abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); + } else { + extendedFacing.getWorldOffset(abc, xyz); + xyz[0] += basePositionX; + xyz[1] += basePositionY; + xyz[2] += basePositionZ; - 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; - } - } - } else { - for (IStructureElement element : elements) { - if (element.isNavigating()) { - abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); - abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); - abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); - } else { - extendedFacing.getWorldOffset(abc, xyz); - xyz[0] += basePositionX; - xyz[1] += basePositionY; - xyz[2] += basePositionZ; + abc[0] += 1; + } + } + } else { + for (IStructureElement element : elements) { + if (element.isNavigating()) { + abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA(); + abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB(); + abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC(); + } else { + extendedFacing.getWorldOffset(abc, xyz); + xyz[0] += basePositionX; + xyz[1] += basePositionY; + xyz[2] += basePositionZ; - if (world.blockExists(xyz[0], xyz[1], xyz[2])) { - element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger); - } - abc[0] += 1; - } - } - } - } - return true; - } + if (world.blockExists(xyz[0], xyz[1], xyz[2])) { + element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger); + } + abc[0] += 1; + } + } + } + } + return true; + } - static StructureDefinition.Builder builder() { - return StructureDefinition.builder(); - } + static StructureDefinition.Builder builder() { + return StructureDefinition.builder(); + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElement.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElement.java index 4334c16b..22764437 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElement.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElement.java @@ -7,37 +7,37 @@ import net.minecraft.world.World; * Use StructureUtility to instantiate */ public interface IStructureElement { - boolean check(T t, World world, int x, int y, int z); + boolean check(T t, World world, int x, int y, int z); - boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger); + boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger); - boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger); + boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger); - default int getStepA() { - return 1; - } + default int getStepA() { + return 1; + } - default int getStepB() { - return 0; - } + default int getStepB() { + return 0; + } - default int getStepC() { - return 0; - } + default int getStepC() { + return 0; + } - default boolean resetA() { - return false; - } + default boolean resetA() { + return false; + } - default boolean resetB() { - return false; - } + default boolean resetB() { + return false; + } - default boolean resetC() { - return false; - } + default boolean resetC() { + return false; + } - default boolean isNavigating() { - return false; - } + default boolean isNavigating() { + return false; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementChain.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementChain.java index 31b0e9e2..52ccc487 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementChain.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementChain.java @@ -7,35 +7,35 @@ import net.minecraft.world.World; * Use StructureUtility to instantiate */ public interface IStructureElementChain extends IStructureElement { - IStructureElement[] fallbacks(); + IStructureElement[] fallbacks(); - @Override - default boolean check(T t, World world, int x, int y, int z) { - for (IStructureElement fallback : fallbacks()) { - if (fallback.check(t, world, x, y, z)) { - return true; - } - } - return false; - } + @Override + default boolean check(T t, World world, int x, int y, int z) { + for (IStructureElement fallback : fallbacks()) { + if (fallback.check(t, world, x, y, z)) { + return true; + } + } + return false; + } - @Override - default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - for (IStructureElement fallback : fallbacks()) { - if (fallback.spawnHint(t, world, x, y, z, trigger)) { - return true; - } - } - return false; - } + @Override + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + for (IStructureElement fallback : fallbacks()) { + if (fallback.spawnHint(t, world, x, y, z, trigger)) { + return true; + } + } + return false; + } - @Override - default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - for (IStructureElement fallback : fallbacks()) { - if (fallback.placeBlock(t, world, x, y, z, trigger)) { - return true; - } - } - return false; - } + @Override + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + for (IStructureElement fallback : fallbacks()) { + if (fallback.placeBlock(t, world, x, y, z, trigger)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementCheckOnly.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementCheckOnly.java index 3774a2f0..3ba0c6ca 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementCheckOnly.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementCheckOnly.java @@ -4,13 +4,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; public interface IStructureElementCheckOnly extends IStructureElement { - @Override - default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return false; - } + @Override + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return false; + } - @Override - default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return false; - } + @Override + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return false; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementNoPlacement.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementNoPlacement.java index 90259b5e..e80d23ed 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementNoPlacement.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureElementNoPlacement.java @@ -4,8 +4,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; public interface IStructureElementNoPlacement extends IStructureElement { - @Override - default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return false; - } + @Override + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return false; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureNavigate.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureNavigate.java index 707cb197..be0c7b08 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureNavigate.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureNavigate.java @@ -7,22 +7,22 @@ import net.minecraft.world.World; * Use StructureUtility to instantiate */ interface IStructureNavigate extends IStructureElement { - @Override - default boolean check(T t, World world, int x, int y, int z) { - return true; - } + @Override + default boolean check(T t, World world, int x, int y, int z) { + return true; + } - @Override - default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return true; - } + @Override + default boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return true; + } - @Override - default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return true; - } + @Override + default boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return true; + } - default boolean isNavigating() { - return true; - } + default boolean isNavigating() { + return true; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/ITierConverter.java b/src/main/java/com/gtnewhorizon/structurelib/structure/ITierConverter.java index 6e95d7a6..6eee2357 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/ITierConverter.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/ITierConverter.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; /** * a function to extract tier info from a block. + * * @param */ @FunctionalInterface diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java index c9267635..07127bb3 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java @@ -5,8 +5,9 @@ package com.gtnewhorizon.structurelib.structure; * temporary states that don't need to live in your main context, which would usually live for the whole lifetime of the * structure than just during structure check. Usually just save some few bytes, but becomes non trivial if you need to * record too much stuff. - * + *

* You will have to reset the context yourself though. The API can't guess when the old context becomes invalid. + * * @param the temporary state context */ public interface IWithExtendedContext { diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/LazyStructureElement.java b/src/main/java/com/gtnewhorizon/structurelib/structure/LazyStructureElement.java index b8c1e4a7..a1f326d7 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/LazyStructureElement.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/LazyStructureElement.java @@ -6,33 +6,33 @@ import net.minecraft.world.World; import java.util.function.Function; class LazyStructureElement implements IStructureElementDeferred { - private Function> to; - private IStructureElement elem; + private Function> to; + private IStructureElement elem; - public LazyStructureElement(Function> to) { - this.to = to; - } + public LazyStructureElement(Function> to) { + this.to = to; + } - private IStructureElement get(T t) { - if (to != null) { - elem = to.apply(t); - to = null; - } - return elem; - } + private IStructureElement get(T t) { + if (to != null) { + elem = to.apply(t); + to = null; + } + return elem; + } - @Override - public boolean check(T t, World world, int x, int y, int z) { - return get(t).check(t, world, x, y, z); - } + @Override + public boolean check(T t, World world, int x, int y, int z) { + return get(t).check(t, world, x, y, z); + } - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return get(t).placeBlock(t, world, x, y, z, trigger); - } + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return get(t).placeBlock(t, world, x, y, z, trigger); + } - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return get(t).spawnHint(t, world, x, y, z, trigger); - } + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return get(t).spawnHint(t, world, x, y, z, trigger); + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java index a7c3ac35..97ffc8d4 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java @@ -9,193 +9,193 @@ import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; public class StructureDefinition implements IStructureDefinition { - private final Map> elements; - private final Map shapes; - private final Map[]> structures; + private final Map> elements; + private final Map shapes; + private final Map[]> structures; - public static Builder builder() { - return new Builder<>(); - } + public static Builder builder() { + return new Builder<>(); + } - private StructureDefinition( - Map> elements, - Map shapes, - Map[]> structures) { - this.elements = elements; - this.shapes = shapes; - this.structures = structures; - } + private StructureDefinition( + Map> elements, + Map shapes, + Map[]> structures) { + this.elements = elements; + this.shapes = shapes; + this.structures = structures; + } - public static class Builder { - private static final char A = '\uA000'; - private static final char B = '\uB000'; - private static final char C = '\uC000'; - private char d = '\uD000'; - private final Map navigates; - private final Map> elements; - private final Map shapes; + public static class Builder { + private static final char A = '\uA000'; + private static final char B = '\uB000'; + private static final char C = '\uC000'; + private char d = '\uD000'; + private final Map navigates; + private final Map> elements; + private final Map shapes; - private Builder() { - navigates = new HashMap<>(); - elements = new HashMap<>(); - shapes = new HashMap<>(); - } + private Builder() { + navigates = new HashMap<>(); + elements = new HashMap<>(); + shapes = new HashMap<>(); + } - public Map> getElements() { - return elements; - } + public Map> getElements() { + return elements; + } - public Map getShapes() { - return shapes; - } + public Map getShapes() { + return shapes; + } - /** - * Adds shape - * + is anything but air - * - is air checks - * space bar is skip - * ~ is also skip (but marks controller position, optional and logically it is a space...) - * rest needs to be defined - *

- * next char is next block(a) - * 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 - * @param structurePiece generated or written struct - DO NOT STORE IT ANYWHERE, or at least set them to null afterwards - * @return this builder - */ - public Builder addShape(String name, String[][] structurePiece) { - StringBuilder builder = new StringBuilder(); - if (structurePiece.length > 0) { - for (String[] strings : structurePiece) { - if (strings.length > 0) { - for (String string : strings) { - builder.append(string).append(B); - } - builder.setLength(builder.length() - 1); - } - builder.append(C); - } - builder.setLength(builder.length() - 1); - } - int a = 0, b = 0, c = 0; - for (int i = 0; i < builder.length(); i++) { - char ch = builder.charAt(i); - if (ch == ' ' || ch == '~') { - builder.setCharAt(i, A); - ch = A; - } - if (ch == A) { - a++; - } else if (ch == B) { - a = 0; - b++; - } else if (ch == C) { - a = 0; - b = 0; - c++; - } else if (a != 0 || b != 0 || c != 0) { - Vec3Impl vec3 = new Vec3Impl(a, b, c); - Character navigate = navigates.get(vec3); - if (navigate == null) { - navigate = d++; - navigates.put(vec3, navigate); - addElement(navigate, step(vec3)); - } - builder.setCharAt(i - 1, navigate); - a = 0; - b = 0; - c = 0; - } - } + /** + * Adds shape + * + is anything but air + * - is air checks + * space bar is skip + * ~ is also skip (but marks controller position, optional and logically it is a space...) + * rest needs to be defined + *

+ * next char is next block(a) + * 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 + * @param structurePiece generated or written struct - DO NOT STORE IT ANYWHERE, or at least set them to null afterwards + * @return this builder + */ + public Builder addShape(String name, String[][] structurePiece) { + StringBuilder builder = new StringBuilder(); + if (structurePiece.length > 0) { + for (String[] strings : structurePiece) { + if (strings.length > 0) { + for (String string : strings) { + builder.append(string).append(B); + } + builder.setLength(builder.length() - 1); + } + builder.append(C); + } + builder.setLength(builder.length() - 1); + } + int a = 0, b = 0, c = 0; + for (int i = 0; i < builder.length(); i++) { + char ch = builder.charAt(i); + if (ch == ' ' || ch == '~') { + builder.setCharAt(i, A); + ch = A; + } + if (ch == A) { + a++; + } else if (ch == B) { + a = 0; + b++; + } else if (ch == C) { + a = 0; + b = 0; + c++; + } else if (a != 0 || b != 0 || c != 0) { + Vec3Impl vec3 = new Vec3Impl(a, b, c); + Character navigate = navigates.get(vec3); + if (navigate == null) { + navigate = d++; + navigates.put(vec3, navigate); + addElement(navigate, step(vec3)); + } + builder.setCharAt(i - 1, navigate); + a = 0; + b = 0; + c = 0; + } + } - String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]", ""); + String built = builder.toString().replaceAll("[\\uA000\\uB000\\uC000]", ""); - if (built.contains("+")) { - addElement('+', notAir()); - } - if (built.contains("-")) { - addElement('-', isAir()); - } - shapes.put(name, built); - return this; - } + if (built.contains("+")) { + addElement('+', notAir()); + } + if (built.contains("-")) { + addElement('-', isAir()); + } + shapes.put(name, built); + return this; + } - public Builder addElement(Character name, IStructureElement structurePiece) { - elements.putIfAbsent(name, structurePiece); - return this; - } + public Builder addElement(Character name, IStructureElement structurePiece) { + elements.putIfAbsent(name, structurePiece); + return this; + } - public IStructureDefinition build() { - Map[]> structures = compileStructureMap(); - if (DEBUG_MODE) { - return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), structures); - } else { - return structures::get; - } - } + public IStructureDefinition build() { + Map[]> structures = compileStructureMap(); + if (DEBUG_MODE) { + return new StructureDefinition<>(new HashMap<>(elements), new HashMap<>(shapes), structures); + } else { + return structures::get; + } + } - @SuppressWarnings("unchecked") - private Map[]> compileElementSetMap() { - Set missing = findMissing(); - if (missing.isEmpty()) { - return shapes.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, - e -> e.getValue().chars() - .mapToObj(c -> (char) c) - .distinct() - .map(elements::get) - .toArray(IStructureElement[]::new) - )); - } else { - throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + - Arrays.toString(missing.toArray())); - } - } + @SuppressWarnings("unchecked") + private Map[]> compileElementSetMap() { + Set missing = findMissing(); + if (missing.isEmpty()) { + return shapes.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> e.getValue().chars() + .mapToObj(c -> (char) c) + .distinct() + .map(elements::get) + .toArray(IStructureElement[]::new) + )); + } else { + throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + + Arrays.toString(missing.toArray())); + } + } - @SuppressWarnings("unchecked") - private Map[]> compileStructureMap() { - Set missing = findMissing(); - if (missing.isEmpty()) { - return shapes.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, - e -> e.getValue().chars().mapToObj(c -> elements.get((char) c)).toArray(IStructureElement[]::new) - )); - } else { - throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + - Arrays.toString(missing.toArray())); - } - } + @SuppressWarnings("unchecked") + private Map[]> compileStructureMap() { + Set missing = findMissing(); + if (missing.isEmpty()) { + return shapes.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> e.getValue().chars().mapToObj(c -> elements.get((char) c)).toArray(IStructureElement[]::new) + )); + } else { + throw new RuntimeException("Missing Structure Element bindings for (chars as integers): " + + Arrays.toString(missing.toArray())); + } + } - private Set findMissing() { - return shapes.values().stream() - .flatMapToInt(CharSequence::chars) - .filter(i -> !elements.containsKey((char) i)) - .boxed() - .collect(Collectors.toSet()); - } - } + private Set findMissing() { + return shapes.values().stream() + .flatMapToInt(CharSequence::chars) + .filter(i -> !elements.containsKey((char) i)) + .boxed() + .collect(Collectors.toSet()); + } + } - public Map> getElements() { - return elements; - } + public Map> getElements() { + return elements; + } - public Map getShapes() { - return shapes; - } + public Map getShapes() { + return shapes; + } - public Map[]> getStructures() { - return structures; - } + public Map[]> getStructures() { + return structures; + } - @Override - public IStructureElement[] getStructureFor(String name) { - IStructureElement[] elements = structures.get(name); - if (elements == null) - throw new NoSuchElementException(name); - return elements; - } -} \ No newline at end of file + @Override + public IStructureElement[] getStructureFor(String name) { + IStructureElement[] elements = structures.get(name); + if (elements == null) + throw new NoSuchElementException(name); + return elements; + } +} diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java index 95fc67e7..2f7d7615 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java @@ -37,1500 +37,1495 @@ import static java.lang.Integer.MIN_VALUE; * (Just import static this class to have a nice fluent syntax while defining structure definitions) */ public class StructureUtility { - private static final String NICE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz=|!@#$%&()[]{};:<>/?_,.*^'`"; - @SuppressWarnings("rawtypes") - private static final Map STEP = new HashMap<>(); - @SuppressWarnings("rawtypes") - private static final IStructureElement AIR = new IStructureElement() { - @Override - public boolean check(Object t, World world, int x, int y, int z) { - return world.isAirBlock(x, y, z); - } - - @Override - public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 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); - return false; - } - }; - @SuppressWarnings("rawtypes") - private static final IStructureElement NOT_AIR = new IStructureElement() { - @Override - public boolean check(Object t, World world, int x, int y, int z) { - return !world.isAirBlock(x, y, z); - } - - @Override - public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 14); - return true; - } - - @Override - public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, StructureLibAPI.getBlockHint(), 14, 2); - return true; - } - }; - @SuppressWarnings("rawtypes") - private static final IStructureElement ERROR = new IStructureElement() { - @Override - public boolean check(Object t, World world, int x, int y, int z) { - return false; - } - - @Override - public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 15); - return true; - } - - @Override - public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { - return true; - } - }; - - private StructureUtility() { - - } - - @SuppressWarnings("unchecked") - public static IStructureElement isAir() { - return AIR; - } - - @SuppressWarnings("unchecked") - public static IStructureElement notAir() { - return NOT_AIR; - } - - /** - * Check returns false. - * Placement is always handled by this and does nothing. - * Makes little to no use it in fallback chain. - * - */ - @SuppressWarnings("unchecked") - public static IStructureElement error() { - return ERROR; - } - - //region hint only - - /** - * Check always returns: true. - * - */ - 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) { - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), meta); - return false; - } - }; - } - - /** - * Check always returns: true. - * - */ - public static IStructureElementNoPlacement ofHintDeferred(Supplier icons) { - return new IStructureElementNoPlacement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, icons.get()); - return false; - } - }; - } - - /** - * Check always returns: true. - * - */ - public static IStructureElementNoPlacement ofHintDeferred(Supplier icons, short[] RGBa) { - return new IStructureElementNoPlacement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticleTinted(world, x, y, z, icons.get(), RGBa); - return false; - } - }; - } - - //endregion - - //region block - - /** - * A more primitive variant of {@link #ofBlocksTiered(ITierConverter, List, Object, BiConsumer, Function)} - * Main difference is this one is check only. - * @see #ofBlocksTiered(ITierConverter, Object, BiConsumer, Function) - */ - public static IStructureElementCheckOnly ofBlocksTiered(ITierConverter tierExtractor, @Nullable TIER notSet, BiConsumer setter, Function getter) { - if (tierExtractor == null) throw new IllegalArgumentException(); - if (setter == null) throw new IllegalArgumentException(); - if (getter == null) throw new IllegalArgumentException(); - - return (t, world, x, y, z) -> { - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - TIER tier = tierExtractor.convert(block, meta); - TIER current = getter.apply(t); - if (Objects.equals(notSet, current)) { - setter.accept(t, tier); - return true; - } - return Objects.equals(current, tier); - }; - } - - /** - * Element representing a component with different tiers. Player can use more blueprint to get hints denoting more - * advanced components. - * - * There is yet no TileEntity counter part of this utility. Feel free to submit a PR to add it. - * @param allKnownTiers All known tiers as of calling. Can be empty or null. No hint will be spawned if empty or null. Cannot have null elements. - * First element denotes the most primitive tier. Last element denotes the most advanced tier. - * If not all tiers are available at definition construction time, use {@link #lazy(Supplier)} or its overloads to delay a little bit. - * @param notSet The value returned from {@code getter} when there were no tier info found in T yet. Can be null. - * @param getter a function to retrieve the current tier from T - * @param setter a function to set the current tier into T - * @param tierExtractor a function to extract tier info from a block. - */ - public static IStructureElement ofBlocksTiered(ITierConverter tierExtractor, @Nullable List> allKnownTiers, @Nullable TIER notSet, BiConsumer setter, Function getter) { - List> hints = allKnownTiers == null ? Collections.emptyList() : allKnownTiers; - if (hints.stream().anyMatch(Objects::isNull)) throw new IllegalArgumentException(); - IStructureElementCheckOnly check = ofBlocksTiered(tierExtractor, notSet, setter, getter); - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return check.check(t, world, x, y, z); - } - - private Pair getHint(ItemStack trigger) { - return hints.get(Math.min(Math.max(trigger.stackSize, 1), hints.size()) - 1); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - Pair hint = getHint(trigger); - if (hint == null) - return false; - StructureLibAPI.hintParticle(world, x, y, z, hint.getKey(), hint.getValue()); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - Pair hint = getHint(trigger); - if (hint == null) - return false; - if (hint.getKey() instanceof ICustomBlockSetting) { - ICustomBlockSetting block = (ICustomBlockSetting) hint.getKey(); - block.setBlock(world, x, y, z, hint.getValue()); - } else { - world.setBlock(x, y, z, hint.getKey(), hint.getValue(), 2); - } - return true; - } - }; - } - - /** - * Denote a block using unlocalized names. This can be useful to get around mod loading order issues. - *

- * While no immediate error will be thrown, client code should ensure said mod is loaded and - * said mod is present, otherwise bad things will happen later! - */ - public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta) { - if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); - if (meta < 0) throw new IllegalArgumentException(); - if (meta > 15) throw new IllegalArgumentException(); - if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); - return new IStructureElement() { - private Block block; - - private Block getBlock() { - if (block == null) - block = GameRegistry.findBlock(modid, unlocalizedName); - return block; - } - - @Override - public boolean check(T t, World world, int x, int y, int z) { - return world.getBlock(x, y, z) == getBlock() && world.getBlockMetadata(x, y, z) == meta; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, getBlock(), meta); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - world.setBlock(x, y, z, getBlock(), meta, 2); - return true; - } - }; - } - - /** - * Similiar to the other overload, but allows client code to specify a fallback in case said block was not found later - * when the element got called. - * - * This is slightly different to using the other overload and another element in a {@link #ofChain(IStructureElement[])}, - * as that combination would cause crash, where this won't. - */ - public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta, IStructureElement fallback) { - if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); - if (meta < 0) throw new IllegalArgumentException(); - if (meta > 15) throw new IllegalArgumentException(); - if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); - if (fallback == null) throw new IllegalArgumentException(); - return new IStructureElement() { - private Block block; - private boolean initialized; - - private boolean init() { - if (!initialized) { - block = GameRegistry.findBlock(modid, unlocalizedName); - initialized = true; - } - return block != null; - } - - @Override - public boolean check(T t, World world, int x, int y, int z) { - if (init()) - return world.getBlock(x, y, z) != block && world.getBlockMetadata(x, y, z) == meta; - else - return fallback.check(t, world, x, y, z); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - if (init()) { - StructureLibAPI.hintParticle(world, x, y, z, block, meta); - return true; - } else - return fallback.spawnHint(t, world, x, y, z, trigger); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - if (init()) { - world.setBlock(x, y, z, block, meta, 2); - return true; - } else - return fallback.placeBlock(t, world, x, y, z, trigger); - } - }; - } - - /** - * 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) { - throw new IllegalArgumentException(); - } - return new IStructureElementNoPlacement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); - return true; - } - }; - } - - /** - * Allows block duplicates (with different meta) - */ - public static IStructureElementNoPlacement ofBlocksMapHint(Map> blocsMap, Block hintBlock, int hintMeta) { - if (blocsMap == null || blocsMap.isEmpty() || hintBlock == null) { - throw new IllegalArgumentException(); - } - for (Collection value : blocsMap.values()) { - if (value.isEmpty()) { - throw new IllegalArgumentException(); - } - } - return new IStructureElementNoPlacement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(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) { - throw new IllegalArgumentException(); - } - return new IStructureElementNoPlacement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(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 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) { - Block worldBlock = world.getBlock(x, y, z); - return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z)); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); - return true; - } - }; - } - - /** - * 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) { - throw new IllegalArgumentException(); - } - if (defaultBlock instanceof ICustomBlockSetting) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } else { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, 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); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } - } - - /** - * Allows block duplicates (with different meta) - */ - public static IStructureElement ofBlocksMap(Map> blocsMap, Block defaultBlock, int defaultMeta) { - if (blocsMap == null || blocsMap.isEmpty() || defaultBlock == null) { - throw new IllegalArgumentException(); - } - for (Collection value : blocsMap.values()) { - if (value.isEmpty()) { - throw new IllegalArgumentException(); - } - } - if (defaultBlock instanceof ICustomBlockSetting) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } else { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, 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); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(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) { - throw new IllegalArgumentException(); - } - if (block instanceof ICustomBlockSetting) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } else { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return block == worldBlock && meta == worldBlock.getDamageValue(world, 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); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } - } - - /** - * Same as above but ignores target meta id - */ - public static IStructureElement ofBlockAnyMeta(Block block, Block defaultBlock, int defaultMeta) { - if (block == null || defaultBlock == null) { - throw new IllegalArgumentException(); - } - if (block instanceof ICustomBlockSetting) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return block == world.getBlock(x, y, z); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } else { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return block == world.getBlock(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); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } - } - - public static IStructureElement ofBlock(Block block, int meta) { - return ofBlock(block, meta, block, meta); - } - - /** - * Same as above but ignores target meta id - */ - public static IStructureElement ofBlockAnyMeta(Block block) { - return ofBlockAnyMeta(block, block, 0); - } - - /** - * Same as above but allows to set hint particle render - */ - public static IStructureElement ofBlockAnyMeta(Block block, int defaultMeta) { - return ofBlockAnyMeta(block, block, defaultMeta); - } - - //endregion - - //region adders - - public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, Block defaultBlock, int defaultMeta) { - if (iBlockAdder == null || defaultBlock == null) { - throw new IllegalArgumentException(); - } - if (defaultBlock instanceof ICustomBlockSetting) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z)); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } else { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block worldBlock = world.getBlock(x, y, z); - return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, 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); - return true; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); - return true; - } - }; - } - } - - public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, int dots) { - return ofBlockAdder(iBlockAdder, StructureLibAPI.getBlockHint(), dots - 1); - } - - 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); - // This used to check if it's a GT tile. Since this is now an standalone mod we no longer do this - return iTileAdder.apply(t, tileEntity); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); - return true; - } - }; - } - - public static IStructureElementNoPlacement ofSpecificTileAdder(BiPredicate iTileAdder, Class tileClass, Block hintBlock, int hintMeta) { - if (iTileAdder == null || hintBlock == null || tileClass == 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); - // This used to check if it's a GT tile. Since this is now an standalone mod we no longer do this - return tileClass.isInstance(tileEntity) && iTileAdder.test(t, tileClass.cast(tileEntity)); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); - return true; - } - }; - } - // No more hatch adder. Implement it via tile adder. We could of course add a wrapper around it in gregtech, but not any more in this standalone mod. - - //endregion - - //region side effects - - 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) { - onCheckPass.accept(t); - } - return check; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return element.placeBlock(t, world, x, y, z, trigger); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return element.spawnHint(t, world, x, y, z, trigger); - } - }; - } - - 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) { - onFail.accept(t); - } - return check; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return element.placeBlock(t, world, x, y, z, trigger); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return element.spawnHint(t, world, x, y, z, trigger); - } - }; - } - - //endregion - - /** - * Enable this structure element only if given predicate returns true. - */ - public static IStructureElement onlyIf(Predicate predicate, IStructureElement downstream) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return predicate.test(t) && downstream.check(t, world, x, y, z); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return predicate.test(t) && downstream.spawnHint(t, world, x, y, z, trigger); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return predicate.test(t) && downstream.placeBlock(t, world, x, y, z, trigger); - } - }; - } - - /** - * 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. - * - */ - @SafeVarargs - public static IStructureElementChain ofChain(IStructureElement... elementChain) { - if (elementChain == null || elementChain.length == 0) { - throw new IllegalArgumentException(); - } - for (IStructureElement iStructureElement : elementChain) { - if (iStructureElement == null) { - throw new IllegalArgumentException(); - } - } - return () -> elementChain; - } - - /** - * 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. - * - */ - @SuppressWarnings("unchecked") - public static IStructureElementChain ofChain(List> elementChain) { - return ofChain(elementChain.toArray(new IStructureElement[0])); - } - - // region context - public static , E extends IStructureElement> IStructureElement withContext(E elem) { - return new IStructureElement() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return elem.check(t.getCurrentContext(), world, x, y, z); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - return elem.spawnHint(t.getCurrentContext(), world, x, y, z, trigger); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return elem.placeBlock(t.getCurrentContext(), world, x, y, z, trigger); - } - }; - } - //endregion - - //region defer - - /** - * Similar to defer, but caches the first returned element returned and won't call it again. - * Initialization is not thread safe. - */ - public static IStructureElementDeferred lazy(Supplier> to) { - if (to == null) { - throw new IllegalArgumentException(); - } - return new LazyStructureElement<>(t -> to.get()); - } - - /** - * Similar to defer, but caches the first returned element returned and won't call it again. - * Initialization is not thread safe. - */ - public static IStructureElementDeferred lazy(Function> to) { - if (to == null) { - throw new IllegalArgumentException(); - } - return new LazyStructureElement<>(to); - } - - public static IStructureElementDeferred defer(Supplier> 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.get().check(t, world, x, y, z); - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return to.get().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.get().spawnHint(t, world, x, y, z, trigger); - } - }; - } - - public static IStructureElementDeferred defer(Function> 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).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).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).spawnHint(t, world, x, y, z, trigger); - } - }; - } - - public static IStructureElementDeferred defer(Function 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)).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)).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)).spawnHint(t, world, x, y, z, trigger); - } - }; - } - - 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); - } - - @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); - } - - @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); - } - }; - } - - @SafeVarargs - public static IStructureElementDeferred defer(Function 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)].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)].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)].spawnHint(t, world, x, y, z, trigger); - } - }; - } - - @SuppressWarnings("unchecked") - 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) { - 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); - } - - @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); - } - - @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); - } - }; - } - - 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); - } - - @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); - } - - @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); - } - }; - } - - 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); - } - - @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); - } - - @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); - } - }; - } - - @SafeVarargs - 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); - } - - @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); - } - - @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); - } - }; - } - - @SuppressWarnings("unchecked") - 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) { - throw new IllegalArgumentException(); - } - return new IStructureElementDeferred() { - @Override - public boolean check(T t, World world, int x, int y, int z) { - return toCheck.apply(t).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); - } - - @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); - } - }; - } - - public static IStructureElementDeferred defer(Function keyExtractorCheck, 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(keyExtractorCheck.apply(t)).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); - } - - @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); - } - }; - } - - 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); - } - - @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); - } - - @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); - } - }; - } - - @SafeVarargs - public static IStructureElementDeferred defer(Function keyExtractorCheck, 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[keyExtractorCheck.apply(t)].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); - } - - @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); - } - }; - } - - @SuppressWarnings("unchecked") - public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, List> array) { - return defer(keyExtractorCheck, keyExtractor, array.toArray(new IStructureElement[0])); - } - - //endregion - - /** - * Used internally, to generate skips for structure definitions - * - */ - public static IStructureNavigate step(int a, int b, int c) { - return step(new Vec3Impl(a, b, c)); - } - - /** - * Used internally, to generate skips for structure definitions - * - */ - @SuppressWarnings("unchecked") - 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) { - return stepC(vec3.get0(), vec3.get1(), vec3.get2()); - } else if (vec3.get1() > 0) { - return stepB(vec3.get0(), vec3.get1(), vec3.get2()); - } else { - return stepA(vec3.get0(), vec3.get1(), vec3.get2()); - } - }); - } - - private static IStructureNavigate stepA(int a, int b, int c) { - return new IStructureNavigate() { - @Override - public int getStepA() { - return a; - } - - @Override - public int getStepB() { - return b; - } - - @Override - public int getStepC() { - return c; - } - }; - } - - private static IStructureNavigate stepB(int a, int b, int c) { - return new IStructureNavigate() { - @Override - public int getStepA() { - return a; - } - - @Override - public int getStepB() { - return b; - } - - @Override - public int getStepC() { - return c; - } - - @Override - public boolean resetA() { - return true; - } - }; - } - - private static IStructureNavigate stepC(int a, int b, int c) { - return new IStructureNavigate() { - @Override - public int getStepA() { - return a; - } - - @Override - public int getStepB() { - return b; - } - - @Override - public int getStepC() { - return c; - } - - @Override - public boolean resetA() { - return true; - } - - @Override - public boolean resetB() { - return true; - } - }; - } - - /** - * Used only to get pseudo code in structure writer... - * - * NOTE: GT specific code got removed. TODO add a mean - * @param tileEntityClassifier return a string that denote the type of a tile entity, or null if it's nothing special. useful if the tile entity cannot be simply distinguished via getClass. - */ - public static String getPseudoJavaCode(World world, ExtendedFacing extendedFacing, - int basePositionX, int basePositionY, int basePositionZ, - int basePositionA, int basePositionB, int basePositionC, - Function tileEntityClassifier, - int sizeA, int sizeB, int sizeC, boolean transpose) { - Map> blocks = new TreeMap<>(Comparator.comparing(Block::getUnlocalizedName)); - Set> tiles = new HashSet<>(); - Set specialTiles = new HashSet<>(); - 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) { - blocks.compute(block, (b, set) -> { - if (set == null) { - set = new TreeSet<>(); - } - set.add(block.getDamageValue(world, x, y, z)); - return set; - }); - } - } else { - String classification = tileEntityClassifier.apply(tileEntity); - if (classification == null) { - tiles.add(tileEntity.getClass()); - } else - specialTiles.add(classification); - } - })); - Map map = new HashMap<>(); - StringBuilder builder = new StringBuilder(); - { - int i = 0; - char c; - builder.append("\n\nStructure:\n") - .append("\nBlocks:\n"); - for (Map.Entry> entry : blocks.entrySet()) { - Block block = entry.getKey(); - Set set = entry.getValue(); - for (Integer meta : set) { - c = NICE_CHARS.charAt(i++); - if (i > NICE_CHARS.length()) { - return "Too complicated for nice chars"; - } - map.put(block.getUnlocalizedName() + '\0' + meta, c); - builder.append(c).append(" -> ofBlock...(") - .append(block.getUnlocalizedName()).append(", ").append(meta).append(", ...);\n"); - } - } - builder.append("\nTiles:\n"); - for (Class tile : tiles) { - c = NICE_CHARS.charAt(i++); - if (i > NICE_CHARS.length()) { - return "Too complicated for nice chars"; - } - map.put(tile.getCanonicalName(), c); - builder.append(c).append(" -> ofTileAdder(") - .append(tile).append(", ...);\n"); - } - builder.append("\nSpecial Tiles:\n"); - for (String tile : specialTiles) { - c = NICE_CHARS.charAt(i++); - if (i > NICE_CHARS.length()) { - return "Too complicated for nice chars"; - } - map.put(tile, c); - builder.append(c).append(" -> ofSpecialTileAdder(") - .append(tile).append(", ...); // You will probably want to change it to something else\n"); - } - } - builder.append("\nOffsets:\n") - .append(basePositionA).append(' ').append(basePositionB).append(' ').append(basePositionC).append('\n'); - 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' + block.getDamageValue(world, x, y, z))); - } else { - builder.append(' '); - } - } else { - String classification = tileEntityClassifier.apply(tileEntity); - if (classification == null) { - classification = tileEntity.getClass().getCanonicalName(); - } - builder.append(map.get(classification)); - } - }), - () -> 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' + block.getDamageValue(world, x, y, z))); - } else { - builder.append(' '); - } - } else { - String classification = tileEntityClassifier.apply(tileEntity); - if (classification == null) { - classification = tileEntity.getClass().getCanonicalName(); - } - builder.append(map.get(classification)); - } - }), - () -> 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[] 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); - } - - } - } - } - - public static void iterate(World world, ExtendedFacing extendedFacing, - 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]; - 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(); - } - 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]; - } - } - return shape; - } + private static final String NICE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz=|!@#$%&()[]{};:<>/?_,.*^'`"; + @SuppressWarnings("rawtypes") + private static final Map STEP = new HashMap<>(); + @SuppressWarnings("rawtypes") + private static final IStructureElement AIR = new IStructureElement() { + @Override + public boolean check(Object t, World world, int x, int y, int z) { + return world.isAirBlock(x, y, z); + } + + @Override + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 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); + return false; + } + }; + @SuppressWarnings("rawtypes") + private static final IStructureElement NOT_AIR = new IStructureElement() { + @Override + public boolean check(Object t, World world, int x, int y, int z) { + return !world.isAirBlock(x, y, z); + } + + @Override + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 14); + return true; + } + + @Override + public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, StructureLibAPI.getBlockHint(), 14, 2); + return true; + } + }; + @SuppressWarnings("rawtypes") + private static final IStructureElement ERROR = new IStructureElement() { + @Override + public boolean check(Object t, World world, int x, int y, int z) { + return false; + } + + @Override + public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 15); + return true; + } + + @Override + public boolean placeBlock(Object o, World world, int x, int y, int z, ItemStack trigger) { + return true; + } + }; + + private StructureUtility() { + + } + + @SuppressWarnings("unchecked") + public static IStructureElement isAir() { + return AIR; + } + + @SuppressWarnings("unchecked") + public static IStructureElement notAir() { + return NOT_AIR; + } + + /** + * Check returns false. + * Placement is always handled by this and does nothing. + * Makes little to no use it in fallback chain. + */ + @SuppressWarnings("unchecked") + public static IStructureElement error() { + return ERROR; + } + + //region hint only + + /** + * Check always returns: true. + */ + 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) { + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), meta); + return false; + } + }; + } + + /** + * Check always returns: true. + */ + public static IStructureElementNoPlacement ofHintDeferred(Supplier icons) { + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, icons.get()); + return false; + } + }; + } + + /** + * Check always returns: true. + */ + public static IStructureElementNoPlacement ofHintDeferred(Supplier icons, short[] RGBa) { + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticleTinted(world, x, y, z, icons.get(), RGBa); + return false; + } + }; + } + + //endregion + + //region block + + /** + * A more primitive variant of {@link #ofBlocksTiered(ITierConverter, List, Object, BiConsumer, Function)} + * Main difference is this one is check only. + * + * @see #ofBlocksTiered(ITierConverter, Object, BiConsumer, Function) + */ + public static IStructureElementCheckOnly ofBlocksTiered(ITierConverter tierExtractor, @Nullable TIER notSet, BiConsumer setter, Function getter) { + if (tierExtractor == null) throw new IllegalArgumentException(); + if (setter == null) throw new IllegalArgumentException(); + if (getter == null) throw new IllegalArgumentException(); + + return (t, world, x, y, z) -> { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + TIER tier = tierExtractor.convert(block, meta); + TIER current = getter.apply(t); + if (Objects.equals(notSet, current)) { + setter.accept(t, tier); + return true; + } + return Objects.equals(current, tier); + }; + } + + /** + * Element representing a component with different tiers. Player can use more blueprint to get hints denoting more + * advanced components. + *

+ * There is yet no TileEntity counter part of this utility. Feel free to submit a PR to add it. + * + * @param allKnownTiers All known tiers as of calling. Can be empty or null. No hint will be spawned if empty or null. Cannot have null elements. + * First element denotes the most primitive tier. Last element denotes the most advanced tier. + * If not all tiers are available at definition construction time, use {@link #lazy(Supplier)} or its overloads to delay a little bit. + * @param notSet The value returned from {@code getter} when there were no tier info found in T yet. Can be null. + * @param getter a function to retrieve the current tier from T + * @param setter a function to set the current tier into T + * @param tierExtractor a function to extract tier info from a block. + */ + public static IStructureElement ofBlocksTiered(ITierConverter tierExtractor, @Nullable List> allKnownTiers, @Nullable TIER notSet, BiConsumer setter, Function getter) { + List> hints = allKnownTiers == null ? Collections.emptyList() : allKnownTiers; + if (hints.stream().anyMatch(Objects::isNull)) throw new IllegalArgumentException(); + IStructureElementCheckOnly check = ofBlocksTiered(tierExtractor, notSet, setter, getter); + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return check.check(t, world, x, y, z); + } + + private Pair getHint(ItemStack trigger) { + return hints.get(Math.min(Math.max(trigger.stackSize, 1), hints.size()) - 1); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + Pair hint = getHint(trigger); + if (hint == null) + return false; + StructureLibAPI.hintParticle(world, x, y, z, hint.getKey(), hint.getValue()); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + Pair hint = getHint(trigger); + if (hint == null) + return false; + if (hint.getKey() instanceof ICustomBlockSetting) { + ICustomBlockSetting block = (ICustomBlockSetting) hint.getKey(); + block.setBlock(world, x, y, z, hint.getValue()); + } else { + world.setBlock(x, y, z, hint.getKey(), hint.getValue(), 2); + } + return true; + } + }; + } + + /** + * Denote a block using unlocalized names. This can be useful to get around mod loading order issues. + *

+ * While no immediate error will be thrown, client code should ensure said mod is loaded and + * said mod is present, otherwise bad things will happen later! + */ + public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta) { + if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); + if (meta < 0) throw new IllegalArgumentException(); + if (meta > 15) throw new IllegalArgumentException(); + if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); + return new IStructureElement() { + private Block block; + + private Block getBlock() { + if (block == null) + block = GameRegistry.findBlock(modid, unlocalizedName); + return block; + } + + @Override + public boolean check(T t, World world, int x, int y, int z) { + return world.getBlock(x, y, z) == getBlock() && world.getBlockMetadata(x, y, z) == meta; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, getBlock(), meta); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, getBlock(), meta, 2); + return true; + } + }; + } + + /** + * Similiar to the other overload, but allows client code to specify a fallback in case said block was not found later + * when the element got called. + *

+ * This is slightly different to using the other overload and another element in a {@link #ofChain(IStructureElement[])}, + * as that combination would cause crash, where this won't. + */ + public static IStructureElement ofBlockUnlocalizedName(String modid, String unlocalizedName, int meta, IStructureElement fallback) { + if (StringUtils.isBlank(unlocalizedName)) throw new IllegalArgumentException(); + if (meta < 0) throw new IllegalArgumentException(); + if (meta > 15) throw new IllegalArgumentException(); + if (StringUtils.isBlank(modid)) throw new IllegalArgumentException(); + if (fallback == null) throw new IllegalArgumentException(); + return new IStructureElement() { + private Block block; + private boolean initialized; + + private boolean init() { + if (!initialized) { + block = GameRegistry.findBlock(modid, unlocalizedName); + initialized = true; + } + return block != null; + } + + @Override + public boolean check(T t, World world, int x, int y, int z) { + if (init()) + return world.getBlock(x, y, z) != block && world.getBlockMetadata(x, y, z) == meta; + else + return fallback.check(t, world, x, y, z); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + if (init()) { + StructureLibAPI.hintParticle(world, x, y, z, block, meta); + return true; + } else + return fallback.spawnHint(t, world, x, y, z, trigger); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + if (init()) { + world.setBlock(x, y, z, block, meta, 2); + return true; + } else + return fallback.placeBlock(t, world, x, y, z, trigger); + } + }; + } + + /** + * 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) { + throw new IllegalArgumentException(); + } + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + }; + } + + /** + * Allows block duplicates (with different meta) + */ + public static IStructureElementNoPlacement ofBlocksMapHint(Map> blocsMap, Block hintBlock, int hintMeta) { + if (blocsMap == null || blocsMap.isEmpty() || hintBlock == null) { + throw new IllegalArgumentException(); + } + for (Collection value : blocsMap.values()) { + if (value.isEmpty()) { + throw new IllegalArgumentException(); + } + } + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(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) { + throw new IllegalArgumentException(); + } + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(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 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) { + Block worldBlock = world.getBlock(x, y, z); + return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z)); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + }; + } + + /** + * 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) { + throw new IllegalArgumentException(); + } + if (defaultBlock instanceof ICustomBlockSetting) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } else { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, 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); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } + } + + /** + * Allows block duplicates (with different meta) + */ + public static IStructureElement ofBlocksMap(Map> blocsMap, Block defaultBlock, int defaultMeta) { + if (blocsMap == null || blocsMap.isEmpty() || defaultBlock == null) { + throw new IllegalArgumentException(); + } + for (Collection value : blocsMap.values()) { + if (value.isEmpty()) { + throw new IllegalArgumentException(); + } + } + if (defaultBlock instanceof ICustomBlockSetting) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, x, y, z)); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } else { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return blocsMap.getOrDefault(worldBlock, Collections.emptySet()).contains(worldBlock.getDamageValue(world, 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); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(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) { + throw new IllegalArgumentException(); + } + if (block instanceof ICustomBlockSetting) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } else { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return block == worldBlock && meta == worldBlock.getDamageValue(world, 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); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } + } + + /** + * Same as above but ignores target meta id + */ + public static IStructureElement ofBlockAnyMeta(Block block, Block defaultBlock, int defaultMeta) { + if (block == null || defaultBlock == null) { + throw new IllegalArgumentException(); + } + if (block instanceof ICustomBlockSetting) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return block == world.getBlock(x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } else { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return block == world.getBlock(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); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } + } + + public static IStructureElement ofBlock(Block block, int meta) { + return ofBlock(block, meta, block, meta); + } + + /** + * Same as above but ignores target meta id + */ + public static IStructureElement ofBlockAnyMeta(Block block) { + return ofBlockAnyMeta(block, block, 0); + } + + /** + * Same as above but allows to set hint particle render + */ + public static IStructureElement ofBlockAnyMeta(Block block, int defaultMeta) { + return ofBlockAnyMeta(block, block, defaultMeta); + } + + //endregion + + //region adders + + public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, Block defaultBlock, int defaultMeta) { + if (iBlockAdder == null || defaultBlock == null) { + throw new IllegalArgumentException(); + } + if (defaultBlock instanceof ICustomBlockSetting) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z)); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } else { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block worldBlock = world.getBlock(x, y, z); + return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, 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); + return true; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, defaultBlock, defaultMeta); + return true; + } + }; + } + } + + public static IStructureElement ofBlockAdder(IBlockAdder iBlockAdder, int dots) { + return ofBlockAdder(iBlockAdder, StructureLibAPI.getBlockHint(), dots - 1); + } + + 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); + // This used to check if it's a GT tile. Since this is now an standalone mod we no longer do this + return iTileAdder.apply(t, tileEntity); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + }; + } + + public static IStructureElementNoPlacement ofSpecificTileAdder(BiPredicate iTileAdder, Class tileClass, Block hintBlock, int hintMeta) { + if (iTileAdder == null || hintBlock == null || tileClass == 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); + // This used to check if it's a GT tile. Since this is now an standalone mod we no longer do this + return tileClass.isInstance(tileEntity) && iTileAdder.test(t, tileClass.cast(tileEntity)); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta); + return true; + } + }; + } + // No more hatch adder. Implement it via tile adder. We could of course add a wrapper around it in gregtech, but not any more in this standalone mod. + + //endregion + + //region side effects + + 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) { + onCheckPass.accept(t); + } + return check; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.placeBlock(t, world, x, y, z, trigger); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.spawnHint(t, world, x, y, z, trigger); + } + }; + } + + 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) { + onFail.accept(t); + } + return check; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.placeBlock(t, world, x, y, z, trigger); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return element.spawnHint(t, world, x, y, z, trigger); + } + }; + } + + //endregion + + /** + * Enable this structure element only if given predicate returns true. + */ + public static IStructureElement onlyIf(Predicate predicate, IStructureElement downstream) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return predicate.test(t) && downstream.check(t, world, x, y, z); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return predicate.test(t) && downstream.spawnHint(t, world, x, y, z, trigger); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return predicate.test(t) && downstream.placeBlock(t, world, x, y, z, trigger); + } + }; + } + + /** + * 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. + */ + @SafeVarargs + public static IStructureElementChain ofChain(IStructureElement... elementChain) { + if (elementChain == null || elementChain.length == 0) { + throw new IllegalArgumentException(); + } + for (IStructureElement iStructureElement : elementChain) { + if (iStructureElement == null) { + throw new IllegalArgumentException(); + } + } + return () -> elementChain; + } + + /** + * 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. + */ + @SuppressWarnings("unchecked") + public static IStructureElementChain ofChain(List> elementChain) { + return ofChain(elementChain.toArray(new IStructureElement[0])); + } + + // region context + public static , E extends IStructureElement> IStructureElement withContext(E elem) { + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return elem.check(t.getCurrentContext(), world, x, y, z); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + return elem.spawnHint(t.getCurrentContext(), world, x, y, z, trigger); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return elem.placeBlock(t.getCurrentContext(), world, x, y, z, trigger); + } + }; + } + //endregion + + //region defer + + /** + * Similar to defer, but caches the first returned element returned and won't call it again. + * Initialization is not thread safe. + */ + public static IStructureElementDeferred lazy(Supplier> to) { + if (to == null) { + throw new IllegalArgumentException(); + } + return new LazyStructureElement<>(t -> to.get()); + } + + /** + * Similar to defer, but caches the first returned element returned and won't call it again. + * Initialization is not thread safe. + */ + public static IStructureElementDeferred lazy(Function> to) { + if (to == null) { + throw new IllegalArgumentException(); + } + return new LazyStructureElement<>(to); + } + + public static IStructureElementDeferred defer(Supplier> 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.get().check(t, world, x, y, z); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return to.get().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.get().spawnHint(t, world, x, y, z, trigger); + } + }; + } + + public static IStructureElementDeferred defer(Function> 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).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).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).spawnHint(t, world, x, y, z, trigger); + } + }; + } + + public static IStructureElementDeferred defer(Function 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)).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)).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)).spawnHint(t, world, x, y, z, trigger); + } + }; + } + + 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); + } + + @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); + } + + @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); + } + }; + } + + @SafeVarargs + public static IStructureElementDeferred defer(Function 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)].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)].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)].spawnHint(t, world, x, y, z, trigger); + } + }; + } + + @SuppressWarnings("unchecked") + 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) { + 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); + } + + @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); + } + + @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); + } + }; + } + + 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); + } + + @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); + } + + @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); + } + }; + } + + 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); + } + + @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); + } + + @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); + } + }; + } + + @SafeVarargs + 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); + } + + @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); + } + + @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); + } + }; + } + + @SuppressWarnings("unchecked") + 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) { + throw new IllegalArgumentException(); + } + return new IStructureElementDeferred() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + return toCheck.apply(t).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); + } + + @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); + } + }; + } + + public static IStructureElementDeferred defer(Function keyExtractorCheck, 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(keyExtractorCheck.apply(t)).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); + } + + @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); + } + }; + } + + 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); + } + + @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); + } + + @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); + } + }; + } + + @SafeVarargs + public static IStructureElementDeferred defer(Function keyExtractorCheck, 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[keyExtractorCheck.apply(t)].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); + } + + @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); + } + }; + } + + @SuppressWarnings("unchecked") + public static IStructureElementDeferred defer(Function keyExtractorCheck, BiFunction keyExtractor, List> array) { + return defer(keyExtractorCheck, keyExtractor, array.toArray(new IStructureElement[0])); + } + + //endregion + + /** + * Used internally, to generate skips for structure definitions + */ + public static IStructureNavigate step(int a, int b, int c) { + return step(new Vec3Impl(a, b, c)); + } + + /** + * Used internally, to generate skips for structure definitions + */ + @SuppressWarnings("unchecked") + 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) { + return stepC(vec3.get0(), vec3.get1(), vec3.get2()); + } else if (vec3.get1() > 0) { + return stepB(vec3.get0(), vec3.get1(), vec3.get2()); + } else { + return stepA(vec3.get0(), vec3.get1(), vec3.get2()); + } + }); + } + + private static IStructureNavigate stepA(int a, int b, int c) { + return new IStructureNavigate() { + @Override + public int getStepA() { + return a; + } + + @Override + public int getStepB() { + return b; + } + + @Override + public int getStepC() { + return c; + } + }; + } + + private static IStructureNavigate stepB(int a, int b, int c) { + return new IStructureNavigate() { + @Override + public int getStepA() { + return a; + } + + @Override + public int getStepB() { + return b; + } + + @Override + public int getStepC() { + return c; + } + + @Override + public boolean resetA() { + return true; + } + }; + } + + private static IStructureNavigate stepC(int a, int b, int c) { + return new IStructureNavigate() { + @Override + public int getStepA() { + return a; + } + + @Override + public int getStepB() { + return b; + } + + @Override + public int getStepC() { + return c; + } + + @Override + public boolean resetA() { + return true; + } + + @Override + public boolean resetB() { + return true; + } + }; + } + + /** + * Used only to get pseudo code in structure writer... + *

+ * NOTE: GT specific code got removed. TODO add a mean + * + * @param tileEntityClassifier return a string that denote the type of a tile entity, or null if it's nothing special. useful if the tile entity cannot be simply distinguished via getClass. + */ + public static String getPseudoJavaCode(World world, ExtendedFacing extendedFacing, + int basePositionX, int basePositionY, int basePositionZ, + int basePositionA, int basePositionB, int basePositionC, + Function tileEntityClassifier, + int sizeA, int sizeB, int sizeC, boolean transpose) { + Map> blocks = new TreeMap<>(Comparator.comparing(Block::getUnlocalizedName)); + Set> tiles = new HashSet<>(); + Set specialTiles = new HashSet<>(); + 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) { + blocks.compute(block, (b, set) -> { + if (set == null) { + set = new TreeSet<>(); + } + set.add(block.getDamageValue(world, x, y, z)); + return set; + }); + } + } else { + String classification = tileEntityClassifier.apply(tileEntity); + if (classification == null) { + tiles.add(tileEntity.getClass()); + } else + specialTiles.add(classification); + } + })); + Map map = new HashMap<>(); + StringBuilder builder = new StringBuilder(); + { + int i = 0; + char c; + builder.append("\n\nStructure:\n") + .append("\nBlocks:\n"); + for (Map.Entry> entry : blocks.entrySet()) { + Block block = entry.getKey(); + Set set = entry.getValue(); + for (Integer meta : set) { + c = NICE_CHARS.charAt(i++); + if (i > NICE_CHARS.length()) { + return "Too complicated for nice chars"; + } + map.put(block.getUnlocalizedName() + '\0' + meta, c); + builder.append(c).append(" -> ofBlock...(") + .append(block.getUnlocalizedName()).append(", ").append(meta).append(", ...);\n"); + } + } + builder.append("\nTiles:\n"); + for (Class tile : tiles) { + c = NICE_CHARS.charAt(i++); + if (i > NICE_CHARS.length()) { + return "Too complicated for nice chars"; + } + map.put(tile.getCanonicalName(), c); + builder.append(c).append(" -> ofTileAdder(") + .append(tile).append(", ...);\n"); + } + builder.append("\nSpecial Tiles:\n"); + for (String tile : specialTiles) { + c = NICE_CHARS.charAt(i++); + if (i > NICE_CHARS.length()) { + return "Too complicated for nice chars"; + } + map.put(tile, c); + builder.append(c).append(" -> ofSpecialTileAdder(") + .append(tile).append(", ...); // You will probably want to change it to something else\n"); + } + } + builder.append("\nOffsets:\n") + .append(basePositionA).append(' ').append(basePositionB).append(' ').append(basePositionC).append('\n'); + 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' + block.getDamageValue(world, x, y, z))); + } else { + builder.append(' '); + } + } else { + String classification = tileEntityClassifier.apply(tileEntity); + if (classification == null) { + classification = tileEntity.getClass().getCanonicalName(); + } + builder.append(map.get(classification)); + } + }), + () -> 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' + block.getDamageValue(world, x, y, z))); + } else { + builder.append(' '); + } + } else { + String classification = tileEntityClassifier.apply(tileEntity); + if (classification == null) { + classification = tileEntity.getClass().getCanonicalName(); + } + builder.append(map.get(classification)); + } + }), + () -> 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[] 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); + } + + } + } + } + + public static void iterate(World world, ExtendedFacing extendedFacing, + 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]; + 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(); + } + 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]; + } + } + return shape; + } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/adders/IBlockAdder.java b/src/main/java/com/gtnewhorizon/structurelib/structure/adders/IBlockAdder.java index 78f7c719..c80693a3 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/adders/IBlockAdder.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/adders/IBlockAdder.java @@ -4,12 +4,12 @@ package com.gtnewhorizon.structurelib.structure.adders; import net.minecraft.block.Block; public interface IBlockAdder { - /** - * Callback on block added, needs to check if block is valid (and add it) - * - * @param block block attempted to add - * @param meta meta of block attempted to add - * @return is structure still valid - */ - boolean apply(T t, Block block, int meta); + /** + * Callback on block added, needs to check if block is valid (and add it) + * + * @param block block attempted to add + * @param meta meta of block attempted to add + * @return is structure still valid + */ + boolean apply(T t, Block block, int meta); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/adders/ITileAdder.java b/src/main/java/com/gtnewhorizon/structurelib/structure/adders/ITileAdder.java index 1445be6b..14e3b358 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/adders/ITileAdder.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/adders/ITileAdder.java @@ -3,11 +3,11 @@ package com.gtnewhorizon.structurelib.structure.adders; import net.minecraft.tileentity.TileEntity; public interface ITileAdder { - /** - * Callback to add hatch, needs to check if tile is valid (and add it) - * - * @param tileEntity tile - * @return managed to add hatch (structure still valid) - */ - boolean apply(T t, TileEntity tileEntity); + /** + * Callback to add hatch, needs to check if tile is valid (and add it) + * + * @param tileEntity tile + * @return managed to add hatch (structure still valid) + */ + boolean apply(T t, TileEntity tileEntity); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/util/Vec3Impl.java b/src/main/java/com/gtnewhorizon/structurelib/util/Vec3Impl.java index 80a99eb1..db2abb07 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/util/Vec3Impl.java +++ b/src/main/java/com/gtnewhorizon/structurelib/util/Vec3Impl.java @@ -23,11 +23,15 @@ public class Vec3Impl implements Comparable { * Gets the coordinate. */ public int get(int index) { - switch (index){ - case 0: return val0; - case 1: return val1; - case 2: return val2; - default: return 0; + switch (index) { + case 0: + return val0; + case 1: + return val1; + case 2: + return val2; + default: + return 0; } } @@ -64,17 +68,17 @@ public class Vec3Impl implements Comparable { return new Vec3Impl(val0 - pos.val0, val1 - pos.val1, val2 - pos.val2); } - public Vec3Impl add(int pos0,int pos1,int pos2) { + public Vec3Impl add(int pos0, int pos1, int pos2) { return new Vec3Impl(val0 + pos0, val1 + pos1, val2 + pos2); } - public Vec3Impl sub(int pos0,int pos1,int pos2) { + public Vec3Impl sub(int pos0, int pos1, int pos2) { return new Vec3Impl(val0 - pos0, val1 - pos1, val2 - pos2); } public Vec3Impl crossProduct(Vec3Impl vec) { return new Vec3Impl(val1 * vec.val2 - val2 * vec.val1, val2 * vec.val0 - val0 * vec.val2, - val0 * vec.val1 - val1 * vec.val0); + val0 * vec.val1 - val1 * vec.val0); } public boolean withinDistance(Vec3Impl to, double distance) { @@ -95,17 +99,17 @@ public class Vec3Impl implements Comparable { public double distanceSq(double x, double y, double z, boolean useCenter) { double d0 = useCenter ? 0.5D : 0.0D; - double d1 = (double)val0 + d0 - x; - double d2 = (double)val1 + d0 - y; - double d3 = (double)val2 + d0 - z; + double d1 = (double) val0 + d0 - x; + double d2 = (double) val1 + d0 - y; + double d3 = (double) val2 + d0 - z; return d1 * d1 + d2 * d2 + d3 * d3; } public int manhattanDistance(Vec3Impl to) { - float f = (float)Math.abs(to.val0 - val0); - float f1 = (float)Math.abs(to.val1 - val1); - float f2 = (float)Math.abs(to.val2 - val2); - return (int)(f + f1 + f2); + float f = (float) Math.abs(to.val0 - val0); + float f1 = (float) Math.abs(to.val1 - val1); + float f2 = (float) Math.abs(to.val2 - val2); + return (int) (f + f1 + f2); } @Override @@ -114,14 +118,14 @@ public class Vec3Impl implements Comparable { } public Vec3Impl abs() { - return new Vec3Impl(Math.abs(val0),Math.abs(val1),Math.abs(val2)); + return new Vec3Impl(Math.abs(val0), Math.abs(val1), Math.abs(val2)); } public boolean equals(Object o) { if (this == o) { return true; } else if (o instanceof Vec3Impl) { - Vec3Impl vec3i = (Vec3Impl)o; + Vec3Impl vec3i = (Vec3Impl) o; return val0 == vec3i.val0 && val1 == vec3i.val1 && val2 == vec3i.val2; } return false; @@ -130,4 +134,4 @@ public class Vec3Impl implements Comparable { public int hashCode() { return (val1 + val2 * 31) * 31 + val0; } -} \ No newline at end of file +} diff --git a/src/main/java/com/gtnewhorizon/structurelib/util/XSTR.java b/src/main/java/com/gtnewhorizon/structurelib/util/XSTR.java index 099c87d9..e3b8198b 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/util/XSTR.java +++ b/src/main/java/com/gtnewhorizon/structurelib/util/XSTR.java @@ -43,10 +43,10 @@ public class XSTR extends Random { private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53) private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24) private static final AtomicLong seedUniquifier = new AtomicLong(8682522807148012L); - public static final XSTR XSTR_INSTANCE=new XSTR(){ + public static final XSTR XSTR_INSTANCE = new XSTR() { @Override public synchronized void setSeed(long seed) { - if(!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) { + if (!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) { throw new NoSuchMethodError("This is meant to be shared!, leave seed state alone!"); } } @@ -275,4 +275,4 @@ public class XSTR extends Random { } } } -} \ No newline at end of file +}