Skip to content

Commit

Permalink
Fixed invalid recipe filters affecting all recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 2, 2024
1 parent 8e42881 commit 38ae4e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,33 @@ static RecipeFilter of(Context cx, @Nullable Object o) {
var input = map.get("input");

if (input != null) {
predicate.list.add(new InputFilter(ReplacementMatchInfo.wrap(cx, input, ReplacementMatchInfo.TYPE_INFO)));
var m = ReplacementMatchInfo.wrap(cx, input, ReplacementMatchInfo.TYPE_INFO);

if (m != ReplacementMatchInfo.NONE) {
predicate.list.add(new InputFilter(m));
} else {
throw Context.reportRuntimeError("Unable to parse recipe input filter `" + input + "`", cx);
}
}

var output = map.get("output");

if (output != null) {
predicate.list.add(new OutputFilter(ReplacementMatchInfo.wrap(cx, output, ReplacementMatchInfo.TYPE_INFO)));
var m = ReplacementMatchInfo.wrap(cx, output, ReplacementMatchInfo.TYPE_INFO);

if (m != ReplacementMatchInfo.NONE) {
predicate.list.add(new OutputFilter(m));
} else {
throw Context.reportRuntimeError("Unable to parse recipe output filter `" + output + "`", cx);
}
}

NeoForge.EVENT_BUS.post(new RecipeFilterParseEvent(cx, predicate.list, map));

if (predicate.list.isEmpty() && !map.isEmpty()) {
throw Context.reportRuntimeError("Unable to parse recipe filter " + map, cx);
}

return predicate.list.isEmpty() ? ConstantFilter.TRUE : predicate.list.size() == 1 ? predicate.list.getFirst() : predicate;
} catch (RecipeExceptionJS rex) {
if (rex.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static ReplacementMatchInfo wrap(Context cx, Object o, TypeInfo target) {
} else if (o instanceof Map || o instanceof NativeJavaMap) {
return (ReplacementMatchInfo) TYPE_INFO.wrap(cx, o, target);
} else {
return new ReplacementMatchInfo(ReplacementMatch.wrap(cx, o), false);
var m = ReplacementMatch.wrap(cx, o);
return m == ReplacementMatch.NONE ? NONE : new ReplacementMatchInfo(m, false);
}
}

Expand Down

0 comments on commit 38ae4e6

Please sign in to comment.