forked from virt-mirrors/Sit
fix not(!) tag check logic
This commit is contained in:
parent
d82b4b49f9
commit
2eb6952144
2 changed files with 29 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue