Skip to content

Coalesce Base Predicate counts + information into record and make MultiPredicate have counts - #5342

Draft
ghzdude wants to merge 25 commits into
GregTechCEu:1.20.1from
ghzdude:gh/predicate-settings
Draft

Coalesce Base Predicate counts + information into record and make MultiPredicate have counts#5342
ghzdude wants to merge 25 commits into
GregTechCEu:1.20.1from
ghzdude:gh/predicate-settings

Conversation

@ghzdude

@ghzdude ghzdude commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What

Multipredicates should now be able to be treated like base predicates for testing min/max counts

Implementation Details

Added record PredicateSettings which combines several of BasePredicate's fields
MultiPredicate also has a settings field, though it is nullable unlike in BasePredicate
For MultiPredicates, if settings == null they behave exactly as before.
When settings is nonnull, it also gets checked along with children predicates
both must be true to pass
Lang has also been introduced for the to-be-used recipe view tooltips

AI Usage

  • No AI driven tools were used for this pull request.
  • Yes AI driven tools were used for this pull request.

Outcome

you should be able to do a.or(b).setMinCount(4) to mean "4 combined of either predicates" now

How Was This Tested

ran client, only check the assembly line which formed as expected

@ghzdude ghzdude added type: refactor Suggestion to refactor a section of code 1.20.1 labels Aug 24, 2026
}

@CheckReturnValue
public MultiPredicate setMinCount(int min) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a bool if the min and max counts should be applied to children?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 children

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines 500 to 513
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);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure if this is the best approach for combining the settings of a and b into a new multi predicate
any thoughts?

@ghzdude
ghzdude force-pushed the gh/predicate-settings branch from 93aef72 to 0f62381 Compare August 31, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20.1 type: refactor Suggestion to refactor a section of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants