diff --git a/src/main/java/one/oth3r/sit/file/CustomBlock.java b/src/main/java/one/oth3r/sit/file/CustomBlock.java index 0f17147..4940f70 100644 --- a/src/main/java/one/oth3r/sit/file/CustomBlock.java +++ b/src/main/java/one/oth3r/sit/file/CustomBlock.java @@ -91,19 +91,27 @@ public class CustomBlock { } // a boolean to check if one of the blocks are in a filtered tag - boolean tagCheck = false; + // & a switch for if there is only not(!) tags + boolean tagCheck = false, hasPositiveTags = false; - // for all the entered tags for (String tag : blockTags) { // substring to remove # and if needed, ! - // if there is a math for the NOT(!) tag, return false - if (tag.startsWith("!") && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.of(tag.substring(2))))) return false; - // if there is a match, return true - if (blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.tryParse(tag.substring(1))))) tagCheck = true; + if (tag.startsWith("!")) { + // if there is a match for the NOT(!) tag, return false + Identifier id = Identifier.tryParse(tag.substring(2)); + if (id != null && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), id))) return false; + } else { + // flip the hasPositiveTags boolean + hasPositiveTags = true; + // if there is a match, return true + Identifier id = Identifier.tryParse(tag.substring(1)); + if (id != null && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), id))) tagCheck = true; + } } - // not returning true in the loop because there might be a (!) not tag that the block might fall into, after the block was already in another tag - return tagCheck; + // if there were any required tags, return whether we matched one + // if there were only not(!) tags, and we didn't violate any, return true + return hasPositiveTags? tagCheck : true; } @Override diff --git a/src/main/java/one/oth3r/sit/file/CustomItem.java b/src/main/java/one/oth3r/sit/file/CustomItem.java index 325fe19..4e4680d 100644 --- a/src/main/java/one/oth3r/sit/file/CustomItem.java +++ b/src/main/java/one/oth3r/sit/file/CustomItem.java @@ -51,22 +51,27 @@ public class CustomItem { } // a boolean to check if one of the items are in a filtered tag - boolean tagCheck = false; + // & a switch for if there is only not(!) tags + boolean tagCheck = false, hasPositiveTags = false; - // check the custom item tags for (String tag : itemTags) { // substring to remove # and if needed, "!" - // if a NOT tag if (tag.startsWith("!")) { // if there is a math for the NOT(!) tag, return false - if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), Identifier.of(tag.substring(2))))) return false; + Identifier id = Identifier.tryParse(tag.substring(2)); + if (id != null && itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), id))) return false; + } else { + // flip the hasPositiveTags boolean + hasPositiveTags = true; + // else (normal tag), if there is a match, set tagCheck to true + Identifier id = Identifier.tryParse(tag.substring(1)); + if (id != null && itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), id))) tagCheck = true; } - // else (normal tag), if there is a match, set tagCheck to true - else if (itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), Identifier.of(tag.substring(1))))) tagCheck = true; } - // not returning true in the loop because there might be a (!) not tag that the item might fall into, after the item was already in another tag - return tagCheck; + // if there were any required tags, return whether we matched one + // if there were only not(!) tags, and we didn't violate any, return true + return hasPositiveTags? tagCheck : true; } @Override