Skip to content

Commit

Permalink
Fix Tag Expr NPE and add support for untagged things (#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Dec 19, 2024
1 parent 2089c4b commit c701b1e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 39 deletions.
20 changes: 11 additions & 9 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2022,15 +2022,17 @@
"cover.robotic_arm.transfer_mode.transfer_exact": "ʇɔɐxƎ ʎןddnS",
"cover.storage.title": "ɹǝʌoƆ ǝbɐɹoʇS",
"cover.tag_filter.info.0": "suoıssǝɹdxǝ xǝןdɯoɔ sʇdǝɔɔⱯq§",
"cover.tag_filter.info.1": "ᗡNⱯ = &",
"cover.tag_filter.info.2": "ᴚO = |",
"cover.tag_filter.info.3": "ᴚOX = ^",
"cover.tag_filter.info.4": "⟘ON = ¡",
"cover.tag_filter.info.5": "ʎʇıɹoıɹd ɹoɟ ) (",
"cover.tag_filter.info.6": "pɹɐɔpןıʍ ɹoɟ *",
"cover.tag_filter.info.7": ":ǝןdɯɐxƎq§",
"cover.tag_filter.info.8": ")*ǝןqnoᗡ*¡ & *ǝʇɐןd( | pןo⅁*ʇsnp9§",
"cover.tag_filter.info.9": "sǝʇɐןd ǝןqnop ʇou ʇnq 'sǝʇɐןd ןןɐ ɹo sǝzıs ןןɐ ɟo sʇsnp pןob ןןɐ ɥɔʇɐɯ ןןıM",
"cover.tag_filter.info.1": "ᗡNⱯ = ɹ§q & ɐ9§",
"cover.tag_filter.info.10": ")ʌן*¡ & sʇınɔɹıɔ:nǝɔʇb( | pןob/sʇsnp*9§ :ǝןdɯɐxƎq§",
"cover.tag_filter.info.11": "sǝuo ΛꞀ ʇdǝɔxǝ sʇınɔɹıɔ ןןɐ ɹo sʇsnp pןob ןןɐ sǝɥɔʇɐɯ sıɥ⟘",
"cover.tag_filter.info.2": "ᴚO = ɹ§q | ɐ9§",
"cover.tag_filter.info.3": "ᴚOX = ɹ§q ^ ɐ9§",
"cover.tag_filter.info.4": "⟘ON = ɹ§ɐ¡9§",
"cover.tag_filter.info.5": "buıdnoɹb ɹoɟ ɹ§)ɐ(9§",
"cover.tag_filter.info.6": "pɹɐɔpןıʍ ɹoɟ ɹ§*9§",
"cover.tag_filter.info.7": "pǝbbɐʇun ɹoɟ ɹ§$9§",
"cover.tag_filter.info.8": "˙,ǝdʎʇqns/bɐʇ:ǝɔɐdsǝɯɐu, ɯɹoɟ ǝɥʇ uı ǝɯoɔ sbɐ⟘q§",
"cover.tag_filter.info.9": "˙pǝpıʌoɹd ʇ,usı ǝuo ɟı pǝɯnssɐ sı ǝɔɐdsǝɯɐu ,:ǝbɹoɟ, ǝɥ⟘",
"cover.tag_filter.matches": "sǝɥɔʇɐɯ ɯǝʇI",
"cover.tag_filter.matches_not": "ɥɔʇɐɯ ʇou sǝop ɯǝʇI",
"cover.tag_filter.test_slot.info": "uoıssǝɹdxǝ ɹǝʇןıɟ ǝɥʇ sǝɥɔʇɐɯ ʇı ɟı ʇsǝʇ oʇ ɯǝʇı ɐ ʇɹǝsuI",
Expand Down
20 changes: 11 additions & 9 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2022,15 +2022,17 @@
"cover.robotic_arm.transfer_mode.transfer_exact": "Supply Exact",
"cover.storage.title": "Storage Cover",
"cover.tag_filter.info.0": "§bAccepts complex expressions",
"cover.tag_filter.info.1": "& = AND",
"cover.tag_filter.info.2": "| = OR",
"cover.tag_filter.info.3": "^ = XOR",
"cover.tag_filter.info.4": "! = NOT",
"cover.tag_filter.info.5": "( ) for priority",
"cover.tag_filter.info.6": "* for wildcard",
"cover.tag_filter.info.7": "§bExample:",
"cover.tag_filter.info.8": "§6dust*Gold | (plate* & !*Double*)",
"cover.tag_filter.info.9": "Will match all gold dusts of all sizes or all plates, but not double plates",
"cover.tag_filter.info.1": "§6a & b§r = AND",
"cover.tag_filter.info.10": "§bExample: §6*dusts/gold | (gtceu:circuits & !*lv)",
"cover.tag_filter.info.11": "This matches all gold dusts or all circuits except LV ones",
"cover.tag_filter.info.2": "§6a | b§r = OR",
"cover.tag_filter.info.3": "§6a ^ b§r = XOR",
"cover.tag_filter.info.4": "§6!a§r = NOT",
"cover.tag_filter.info.5": "§6(a)§r for grouping",
"cover.tag_filter.info.6": "§6*§r for wildcard",
"cover.tag_filter.info.7": "§6$§r for untagged",
"cover.tag_filter.info.8": "§bTags come in the form 'namespace:tag/subtype'.",
"cover.tag_filter.info.9": "The 'forge:' namespace is assumed if one isn't provided.",
"cover.tag_filter.matches": "Item matches",
"cover.tag_filter.matches_not": "Item does not match",
"cover.tag_filter.test_slot.info": "Insert a item to test if it matches the filter expression",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setOreDict(String oreDict) {

@Override
public boolean test(FluidStack fluidStack) {
if (oreDictFilterExpression.isEmpty()) return true;
if (oreDictFilterExpression.isEmpty()) return false;
if (cache.containsKey(fluidStack.getFluid())) return cache.getOrDefault(fluidStack.getFluid(), false);
if (TagExprFilter.tagsMatch(matchExpr, fluidStack)) {
cache.put(fluidStack.getFluid(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void setOreDict(String oreDict) {

@Override
public boolean test(ItemStack itemStack) {
if (oreDictFilterExpression.isEmpty()) return true;
if (oreDictFilterExpression.isEmpty()) return false;
if (cache.containsKey(itemStack.getItem())) return cache.getOrDefault(itemStack.getItem(), false);
if (TagExprFilter.tagsMatch(matchExpr, itemStack)) {
cache.put(itemStack.getItem(), true);
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,19 @@ public static void init(RegistrateLangProvider provider) {
provider.add("cover.filter.blacklist.enabled", "Blacklist");
provider.add("cover.tag_filter.title", "Tag Filter");
multilineLang(provider, "cover.tag_filter.info",
"§bAccepts complex expressions\n& = AND\n| = OR\n^ = XOR\n! = NOT\n( ) for priority\n* for wildcard\n§bExample:\n§6dust*Gold | (plate* & !*Double*)\nWill match all gold dusts of all sizes or all plates, but not double plates");
"""
§bAccepts complex expressions
§6a & b§r = AND
§6a | b§r = OR
§6a ^ b§r = XOR
§6!a§r = NOT
§6(a)§r for grouping
§6*§r for wildcard
§6$§r for untagged
§bTags come in the form 'namespace:tag/subtype'.
The 'forge:' namespace is assumed if one isn't provided.
§bExample: §6*dusts/gold | (gtceu:circuits & !*lv)
This matches all gold dusts or all circuits except LV ones""");
provider.add("cover.tag_filter.test_slot.info",
"Insert a item to test if it matches the filter expression");
provider.add("cover.tag_filter.matches", "Item matches");
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/com/gregtechceu/gtceu/utils/TagExprFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public boolean matches(Set<String> input) {
return switch (op.type) {
case And -> left.matches(input) && right.matches(input);
case Or -> left.matches(input) || right.matches(input);
case Xor -> (left.matches(input) && !right.matches(input)) ||
(!left.matches(input) && right.matches(input));
case Xor -> left.matches(input) ^ right.matches(input);
default -> false;
};
}
Expand All @@ -87,7 +86,7 @@ public UnaryExpr(Token token, MatchExpr expr) {
@Override
public boolean matches(Set<String> input) {
if (token.type == TokenType.Not) {
return !expr.matches(input);
return expr != null && !expr.matches(input);
}

return false;
Expand All @@ -104,6 +103,8 @@ public StringExpr(String value) {

@Override
public boolean matches(Set<String> input) {
if (value == null || value.isEmpty()) return false;
if (value.equals("$") && input.isEmpty()) return true;
if (!value.contains(":") && !value.startsWith("*")) {
value = "forge:" + value;
}
Expand Down Expand Up @@ -136,7 +137,7 @@ public GroupingExpr(MatchExpr inner) {

@Override
public boolean matches(Set<String> input) {
return inner.matches(input);
return inner != null && inner.matches(input);
}
}

Expand Down Expand Up @@ -278,24 +279,20 @@ public static TagExprParser.MatchExpr parseExpression(String expression) {
* @return if any of the items oreDicts matches the rules
*/
public static boolean tagsMatch(TagExprParser.MatchExpr expr, ItemStack stack) {
Set<String> oreDicts = stack.getTags().map(TagKey::location)
.map(ResourceLocation::toString).collect(Collectors.toSet());
Set<String> tags = stack.getTags()
.map(TagKey::location)
.map(ResourceLocation::toString)
.collect(Collectors.toSet());

if (oreDicts.isEmpty() || expr == null) {
return false;
}

return expr.matches(oreDicts);
return expr != null && expr.matches(tags);
}

public static boolean tagsMatch(TagExprParser.MatchExpr expr, FluidStack stack) {
Set<String> oreDicts = stack.getFluid().defaultFluidState().getTags().map(TagKey::location)
.map(ResourceLocation::toString).collect(Collectors.toSet());

if (oreDicts.isEmpty() || expr == null) {
return false;
}
Set<String> tags = stack.getFluid().defaultFluidState().getTags()
.map(TagKey::location)
.map(ResourceLocation::toString)
.collect(Collectors.toSet());

return expr.matches(oreDicts);
return expr != null && expr.matches(tags);
}
}

0 comments on commit c701b1e

Please sign in to comment.