From cb41cea9226a72cfb2d334d514a0dcef97497ef1 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 26 Jan 2024 10:04:09 +0100 Subject: [PATCH] Add UtilsWrapper.parseBlockState as wrapper for the same method in UtilsJS --- .../dev/latvian/mods/kubejs/bindings/UtilsWrapper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/bindings/UtilsWrapper.java b/common/src/main/java/dev/latvian/mods/kubejs/bindings/UtilsWrapper.java index 7b8489055..20460853e 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/bindings/UtilsWrapper.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/bindings/UtilsWrapper.java @@ -23,6 +23,8 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -245,4 +247,12 @@ static ParticleOptions particleOptions(Object o) { return ERROR_PARTICLE; } + + @Info("Parses a block state from the input string. May throw for invalid inputs!") + static BlockState parseBlockState(Object o) { + if (o instanceof BlockState bs) { + return bs; + } + return o == null ? Blocks.AIR.defaultBlockState() : UtilsJS.parseBlockState(o.toString()); + } } \ No newline at end of file