Skip to content

Coalesce Predicate Information and Improve Predicate Testing - #5342

Merged
jurrejelle merged 76 commits into
GregTechCEu:1.20.1from
ghzdude:gh/predicate-settings
Sep 20, 2026
Merged

jurrejelle merged 76 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, which is nonnull by default
MultiPredicate settings are checked along with their children
getPredicateAtPos() now returns a PredicateResult record, which stores the matched base predicate and a parent chain
BasePredicate's Air/any fields are removed and handled completely in MultiPredicate
multi predicate and base predicate have copy, equals, and hash methods
the predicate context counts both base predicates and multi predicates
added TestType enum to clean up testing logic between base predicate and multi predicate

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
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
@ghzdude
ghzdude force-pushed the gh/predicate-settings branch 3 times, most recently from da9a8e9 to 1dcbd26 Compare September 4, 2026 06:45
@ghzdude
ghzdude marked this pull request as ready for review September 4, 2026 06:59
@ghzdude
ghzdude requested a review from a team as a code owner September 4, 2026 06:59
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/predicates/SettingsHolder.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
@jurrejelle

Copy link
Copy Markdown
Contributor

Edit to add: review assisted by opus

Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/XorPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/predicates/BasePredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
@jurrejelle

Copy link
Copy Markdown
Contributor

Sidenote, but tests blow up for now x3 something while forming a multi crashes

PredicateSettings codec (unused)
update xorpred nonvalid
global/slice count key to PredicateSettings
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
at least merge if b is single
also don't increment count for -1 global/slice max
@ghzdude

ghzdude commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

So, the reason many tests were failing is due to certain multiblocks, namely the Large Chemical Reactor, not forming correctly. The formation failure is because the global/slice count maps can have "duplicated" keys. The keys are being duplicated because they (base predicates and multi predicates) are being copied in the MultiPredicate#combine() method.

A quick fix is to stop copying on combination, but this then results in undesirable mutation (parents) when using the same multipredicate reference combined with two other multi predicates. like so:

var a = blocks(...)
var b = blocks(...).and(a) // a is parent to {a + b}
var c = blocks(...).and(a) // a is now parent to {a + c}

I could use a list of parents, but then it becomes difficult to determine which parent to call in MultiPredicate#testParents(), and testing all of them can result in the same multi predicate being counted multiple times

I've also made an attempt to implement an equals method for BasePredicate and TestablePredicate, but this doesn't seem to help, the duplicate keys are still present in the count maps. I'm not entirely sure how to fix this.

Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/predicates/SettingsHolder.java Outdated
move TestType into own class
create PredicateResult to keep track of MultiPredicate call chain
`getPredicateAtPos()` now returns a nonnull result
rework XOR to not require a full override of `getPredicateAtPos()`
delete parent field in BasePredicate and MultiPredicate
remove leaf and branch methods in MultiPredicate
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/PredicateResult.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/PredicateContext.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
Comment thread src/main/java/com/gregtechceu/gtceu/api/multiblock/MultiPredicate.java Outdated
rename with -> set
test self in and/or/xor
get rid of second condition in MultiPredicate as it's redundant now
move air and any stuff into MultiPredicate only
move set default settings to type makePredicate
MultiPredicate of -> ofSingle
improve XorPredicate on predicate match
fixed missed count in PredicateResult
@ghzdude ghzdude changed the title Coalesce Base Predicate counts + information into record and make MultiPredicate have counts Coalesce Predicate Information and Improve Predicate Testing Sep 14, 2026
improve xor a bit
@ghzdude
ghzdude force-pushed the gh/predicate-settings branch from 76f36ab to 84f5c8b Compare September 15, 2026 19:29
get rid of is top method
add javadoc
simplify TestType error methods a bit
@jurrejelle
jurrejelle merged commit 0f3cf82 into GregTechCEu:1.20.1 Sep 20, 2026
4 checks passed
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