Coalesce Base Predicate counts + information into record and make MultiPredicate have counts - #5342
Coalesce Base Predicate counts + information into record and make MultiPredicate have counts#5342ghzdude wants to merge 25 commits into
Conversation
| } | ||
|
|
||
| @CheckReturnValue | ||
| public MultiPredicate setMinCount(int min) { |
There was a problem hiding this comment.
can we add a bool if the min and max counts should be applied to children?
There was a problem hiding this comment.
thoughts on something like
blocks(...) // a
.and(b)
.and(c)
.withSettings() // mark this multi predicate as having its own settings
.setMaxCount(1) // sets the max count of this multipredicate and not its childrenThere was a problem hiding this comment.
I think by default, it should be non-recursive (e.g. I think if someone does "a.and(b).setMin(4)" they want to have "4 of a or b combined".
A similar usecase to consider is Precicate.frames(STEEL) already returns framebox.and(frameboxblockentities) so if someone does Predicate.frames(STEEL).setMin(4) and it's recursive, it would never match (unless they have 4 normal frame boxes and 4 pipe frame boxes)
| private static MultiPredicate combine(MultiPredicate a, Logic type, @Nullable MultiPredicate b) { | ||
| if (b == null || b.isEmpty()) return a; // no op | ||
| if (a.isEmpty()) return b; | ||
| if (!Objects.equals(a.settings, b.settings)) { | ||
| a.applySettingsToChildren(); | ||
| b.applySettingsToChildren(); | ||
| } | ||
| List<BasePredicate> predicates = new ArrayList<>(); | ||
| List<MultiPredicate> children = new ArrayList<>(); | ||
| appendPredicates(type, a, predicates, children); | ||
| appendPredicates(type, b, predicates, children); | ||
| predicates.sort(BasePredicate::compareTo); | ||
| return type.makePredicate(children, predicates, a.hasAir || b.hasAir); | ||
| return type.makePredicate(children, predicates, a.hasAir || b.hasAir, null); | ||
| } |
There was a problem hiding this comment.
im not sure if this is the best approach for combining the settings of a and b into a new multi predicate
any thoughts?
add set settings copy settings
count with new interface instead of PredicateSettings organize methods in MultiPredicate
…ed to the MultiPredicate instead of its children javadoc
add builder pattern generic to SettingsHolder
improve nonevalid in xor
93aef72 to
0f62381
Compare
What
Multipredicates should now be able to be treated like base predicates for testing min/max counts
Implementation Details
Added record
PredicateSettingswhich combines several of BasePredicate's fieldsMultiPredicate also has a settings field, though it is nullable unlike in BasePredicate
For MultiPredicates, if
settings == nullthey behave exactly as before.When
settingsis nonnull, it also gets checked along with children predicatesboth must be
trueto passLang has also been introduced for the to-be-used recipe view tooltips
AI Usage
Outcome
you should be able to do
a.or(b).setMinCount(4)to mean "4 combined of either predicates" nowHow Was This Tested
ran client, only check the assembly line which formed as expected