From 98c841b875d88f9cb45c422f15ec258431834a1b Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 30 Sep 2024 15:22:57 -0500 Subject: [PATCH] better blockstate checker --- src/main/java/one/oth3r/sit/file/CustomBlock.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/one/oth3r/sit/file/CustomBlock.java b/src/main/java/one/oth3r/sit/file/CustomBlock.java index 192e963..0c4f5e7 100644 --- a/src/main/java/one/oth3r/sit/file/CustomBlock.java +++ b/src/main/java/one/oth3r/sit/file/CustomBlock.java @@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.block.BlockState; import net.minecraft.registry.Registries; import net.minecraft.registry.tag.TagKey; +import net.minecraft.state.State; import net.minecraft.util.Identifier; import one.oth3r.sit.utl.Utl; @@ -51,14 +52,16 @@ public class CustomBlock { if (!blockType) return false; // now check if the state is one of the acceptable states - for (String state : blockStates) { //todo extract the blockstates to check them better + for (String state : blockStates) { // if there is a NOT (!) blockstate if (state.startsWith("!")) { // if it is contained in the block, return false - if (blockState.toString().contains(state.substring(1))) return false; + // remove the '!' + String fixedState = state.substring(1); + if (blockState.getEntries().entrySet().stream().map(State.PROPERTY_MAP_PRINTER).anyMatch(s -> s.equals(fixedState))) return false; } // else check if the blockstate matches, if not return false - else if (!blockState.toString().contains(state)) return false; + else if (blockState.getEntries().entrySet().stream().map(State.PROPERTY_MAP_PRINTER).noneMatch(s -> s.equals(state))) return false; } // if here, all passes have passed