aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2021-05-31 22:59:51 +0800
committerGlease <4586901+Glease@users.noreply.github.com>2021-07-30 14:34:37 +0800
commitf812b4a50c922290d6cdee4d1e5e20530814abdc (patch)
treed6af8e27d52bf8006b70657332dc20d78ece9da5 /src/main/java/gregtech/api/util
parentc1146c404994ee80c5b1d282bd0f03d3532bedca (diff)
downloadGT5-Unofficial-f812b4a50c922290d6cdee4d1e5e20530814abdc.tar.gz
GT5-Unofficial-f812b4a50c922290d6cdee4d1e5e20530814abdc.tar.bz2
GT5-Unofficial-f812b4a50c922290d6cdee4d1e5e20530814abdc.zip
Add GT_MetaTileEntity_CubicMultiBlockBase and a few minor changes
1. add ofCoil() IStructureElement to standardise how to add a homogeneous set of coils to the structure definition 2. Changed newMetaEntity's return type back to IMetaTileEntity to prevent addons crying out 3. Initialize mExtendedFacing to ensure rendering code don't step on null
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_StructureUtility.java73
-rw-r--r--src/main/java/gregtech/api/util/IGT_HatchAdder.java5
2 files changed, 76 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java
index c8d845ec19..1db672245c 100644
--- a/src/main/java/gregtech/api/util/GT_StructureUtility.java
+++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java
@@ -3,13 +3,24 @@ package gregtech.api.util;
import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.HeatingCoilLevel;
+import gregtech.api.interfaces.IHeatingCoil;
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;
+import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
+import java.util.function.Function;
+
+import static com.gtnewhorizon.structurelib.StructureLibAPI.HINT_BLOCK_META_GENERIC_11;
+
public class GT_StructureUtility {
+ public static final int HINT_COIL_DEFAULT_DOTS = HINT_BLOCK_META_GENERIC_11;
+
private GT_StructureUtility() {
throw new AssertionError("Not instantiable");
}
@@ -68,4 +79,66 @@ public class GT_StructureUtility {
}
};
}
+
+ /**
+ * Assume a default of LV coil. Assume all coils accepted. Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots.
+ * @see #ofCoil(BiPredicate, Function, int, Block, int)
+ */
+ public static <T> IStructureElement<T> ofCoil(BiConsumer<T, HeatingCoilLevel> heatingCoilSetter, Function<T, HeatingCoilLevel> heatingCoilGetter) {
+ return ofCoil((t, l) -> {
+ heatingCoilSetter.accept(t, l);
+ return true;
+ }, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, GregTech_API.sBlockCasings5, 0);
+ }
+
+ /**
+ * Assumes using {@link #HINT_COIL_DEFAULT_DOTS} as dots
+ * @see #ofCoil(BiPredicate, Function, int, Block, int)
+ */
+ public static <T> IStructureElement<T> ofCoil(BiPredicate<T, HeatingCoilLevel> heatingCoilSetter, Function<T, HeatingCoilLevel> heatingCoilGetter, Block defaultCoil, int defaultMeta) {
+ return ofCoil(heatingCoilSetter, heatingCoilGetter, HINT_COIL_DEFAULT_DOTS, defaultCoil, defaultMeta);
+ }
+
+ /**
+ * Heating coil structure element.
+ * @param heatingCoilSetter Notify the controller of this new coil.
+ * Got called exactly once per coil.
+ * Might be called less times if structure test fails.
+ * If the setter returns false then it assumes the coil is rejected.
+ * @param heatingCoilGetter Get the current heating level. Null means no coil recorded yet.
+ * @param dots The hinting dots
+ * @param defaultCoil The block to place when auto constructing
+ * @param defaultMeta The block meta to place when auto constructing
+ */
+ public static <T> IStructureElement<T> ofCoil(BiPredicate<T, HeatingCoilLevel> heatingCoilSetter, Function<T, HeatingCoilLevel> heatingCoilGetter, int dots, Block defaultCoil, int defaultMeta) {
+ if (heatingCoilSetter == null || heatingCoilGetter == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ Block block = world.getBlock(x, y, z);
+ if (!(block instanceof IHeatingCoil))
+ return false;
+ HeatingCoilLevel existingLevel = heatingCoilGetter.apply(t),
+ newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z));
+ if (existingLevel == null) {
+ return heatingCoilSetter.test(t, newLevel);
+ } else {
+ return newLevel == existingLevel;
+ }
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), dots);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ return world.setBlock(x, y, z, defaultCoil, defaultMeta, 3);
+ }
+ };
+ }
}
diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
index be0194fc65..362fddaf1f 100644
--- a/src/main/java/gregtech/api/util/IGT_HatchAdder.java
+++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
@@ -6,9 +6,10 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
public interface IGT_HatchAdder<T> {
/**
* 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...
+ * @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);
+ boolean apply(T t, IGregTechTileEntity iGregTechTileEntity, Short aShort);
}