fix not(!) tag check logic

This commit is contained in:
Oth3r 2025-06-14 18:47:51 -05:00
commit 2eb6952144
2 changed files with 29 additions and 16 deletions

View file

@ -91,19 +91,27 @@ public class CustomBlock {
} }
// a boolean to check if one of the blocks are in a filtered tag // 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) { for (String tag : blockTags) {
// substring to remove # and if needed, ! // substring to remove # and if needed, !
// if there is a math for the NOT(!) tag, return false if (tag.startsWith("!")) {
if (tag.startsWith("!") && blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.of(tag.substring(2))))) return false; // 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 // if there is a match, return true
if (blockState.isIn(TagKey.of(Registries.BLOCK.getKey(), Identifier.tryParse(tag.substring(1))))) tagCheck = 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 // if there were any required tags, return whether we matched one
return tagCheck; // if there were only not(!) tags, and we didn't violate any, return true
return hasPositiveTags? tagCheck : true;
} }
@Override @Override

View file

@ -51,22 +51,27 @@ public class CustomItem {
} }
// a boolean to check if one of the items are in a filtered tag // 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) { for (String tag : itemTags) {
// substring to remove # and if needed, "!" // substring to remove # and if needed, "!"
// if a NOT tag
if (tag.startsWith("!")) { if (tag.startsWith("!")) {
// if there is a math for the NOT(!) tag, return false // 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 // 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; Identifier id = Identifier.tryParse(tag.substring(1));
if (id != null && itemStack.isIn(TagKey.of(Registries.ITEM.getKey(), id))) 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 // if there were any required tags, return whether we matched one
return tagCheck; // if there were only not(!) tags, and we didn't violate any, return true
return hasPositiveTags? tagCheck : true;
} }
@Override @Override