diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2021-07-18 08:20:13 +0800 |
---|---|---|
committer | Glease <4586901+Glease@users.noreply.github.com> | 2021-07-30 14:41:25 +0800 |
commit | 1cdefed2daf27b0a36032067f9af97962bf353fb (patch) | |
tree | f1cbed6f3f6765b36dc36a12b402b9e312421b60 /src/main/java/gregtech/api/util | |
parent | 112f7809ecaa0ccb5e8060b70d7e437086ffa735 (diff) | |
download | GT5-Unofficial-1cdefed2daf27b0a36032067f9af97962bf353fb.tar.gz GT5-Unofficial-1cdefed2daf27b0a36032067f9af97962bf353fb.tar.bz2 GT5-Unofficial-1cdefed2daf27b0a36032067f9af97962bf353fb.zip |
Fix mod loading order problem
This utility method could probably be extracted to upstream. Let's do it when the structurelib integration comes to the end of test phase.
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_StructureUtility.java | 37 |
1 files changed, 35 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 5067c698ab..7e39a0d838 100644 --- a/src/main/java/gregtech/api/util/GT_StructureUtility.java +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -3,6 +3,7 @@ package gregtech.api.util; import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.interfaces.IHeatingCoil; @@ -12,13 +13,12 @@ import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import org.apache.commons.lang3.StringUtils; 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 { private GT_StructureUtility() { throw new AssertionError("Not instantiable"); @@ -133,4 +133,37 @@ public class GT_StructureUtility { } }; } + + public static <T> IStructureElement<T> 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<T>() { + 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; + } + }; + } } |