From 546b42d7440839477455b818133d80221c70c582 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sat, 29 May 2021 23:52:15 +0800 Subject: Initial StructureLib integration --- .../gregtech/api/util/GT_StructureUtility.java | 71 ++++++++++++++++++++++ .../java/gregtech/api/util/IGT_HatchAdder.java | 14 +++++ 2 files changed, 85 insertions(+) create mode 100644 src/main/java/gregtech/api/util/GT_StructureUtility.java create mode 100644 src/main/java/gregtech/api/util/IGT_HatchAdder.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java new file mode 100644 index 0000000000..c8d845ec19 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -0,0 +1,71 @@ +package gregtech.api.util; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class GT_StructureUtility { + private GT_StructureUtility() { + throw new AssertionError("Not instantiable"); + } + + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots) { + return ofHatchAdder(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1); + } + + public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta) { + if (IGT_HatchAdder == null || hintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElementNoPlacement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity && IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex); + } + + @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 IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { + return ofHatchAdderOptional(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta); + } + + public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { + if (IGT_HatchAdder == null || hintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElement() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return (tileEntity instanceof IGregTechTileEntity && + IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex)) || + (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); + } + + @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; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); + return true; + } + }; + } +} diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java new file mode 100644 index 0000000000..be0194fc65 --- /dev/null +++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java @@ -0,0 +1,14 @@ +package gregtech.api.util; + + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public interface IGT_HatchAdder { + /** + * Callback to add hatch, needs to check if hatch is valid (and add it) + * @param iGregTechTileEntity hatch + * @param aShort requested texture index, or null if not... + * @return managed to add hatch (structure still valid) + */ + boolean apply(T t,IGregTechTileEntity iGregTechTileEntity, Short aShort); +} -- cgit