Skip to content

Adding PredicateChoice to Paper API (updated version) - #12017

Merged
lynxplay merged 6 commits into
PaperMC:mainfrom
CPieter:feature/predicate-choice
Aug 28, 2026
Merged

Adding PredicateChoice to Paper API (updated version)#12017
lynxplay merged 6 commits into
PaperMC:mainfrom
CPieter:feature/predicate-choice

Conversation

@CPieter

@CPieter CPieter commented Jan 26, 2025

Copy link
Copy Markdown
Contributor

This PR is an updated version of derverdox's PredicateChoice PR #9996. Since the branch in the old PR was quite outdated I reïmplemented the changes in a new branch, but most of the changes remain the same. Credit of the code should go to derverdox and Machine-Maker.
The feature seems to work fine from my testing but I'm unfamiliar with the Paper API so I please let me know if I missed something.

@CPieter
CPieter requested a review from a team as a code owner January 26, 2025 12:16
@CPieter CPieter changed the title Adding PredicateChoice to Paper API (second version) Adding PredicateChoice to Paper API (updated version) Jan 26, 2025

@lynxplay lynxplay left a comment

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.

Welcome to paper 🎉
Thank you for updating the PR. I don'T have time for a indepth review rn, but I left some initial easy nitpicks around comments 👍

Will get to a review next week probably

Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java Outdated
@Doc94

Doc94 commented Jan 26, 2025

Copy link
Copy Markdown
Member

Hi and welcome to the Paper PR world (well this more a thing can say a Paper Team Member xd)

The paper comments currently just apply to code in patches, its not required in the api,craftbukkit,paper classes.

@CPieter

CPieter commented Jan 26, 2025

Copy link
Copy Markdown
Contributor Author

I just noticed there is already a PredicateRecipeChoice for potions, with the addition of the PredicateChoice this could be a bit confusing. Maybe it should be renamed to something more clear like a PotionRecipeChoice/PotionPredicateChoice?

@Doc94

Doc94 commented Jan 26, 2025

Copy link
Copy Markdown
Member

I just noticed there is already a PredicateRecipeChoice for potions, with the addition of the PredicateChoice this could be a bit confusing. Maybe it should be renamed to something more clear like a PotionRecipeChoice/PotionPredicateChoice?

well rename sounds a little breaking i think, maybe this new PredicateChoice can be named ItemPredicateChoice (? or add an extension of RecipeChoice for Potion and move things to that for make clear the diff... but not really sure.

@lynxplay lynxplay added type: feature Request for a new Feature. scope: api labels Jan 26, 2025
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
@Machine-Maker

Copy link
Copy Markdown
Member

I just noticed there is already a PredicateRecipeChoice for potions, with the addition of the PredicateChoice this could be a bit confusing. Maybe it should be renamed to something more clear like a PotionRecipeChoice/PotionPredicateChoice?

Since PredicateRecipeChoice isn't public, delete it, and make PotionMix#createPredicateChoice return an instance of the new type. But also deprecate that method, and suggest to use the new method you create.

Here's a great example of what I talked about in my review, suggesting to keep implementation types out of the "api" because we can now just delete PredicateRecipeChoice entirely.

@Machine-Maker Machine-Maker left a comment

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.

Looks good, just a few more things. I also opened the PR adding the future alternative to MaterialChoice. Will merge mine in after yours

Comment thread paper-api/src/main/java/org/bukkit/inventory/PredicateChoiceImpl.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java Outdated
@CPieter

CPieter commented Feb 3, 2025

Copy link
Copy Markdown
Contributor Author

Since PredicateRecipeChoice isn't public, delete it, and make PotionMix#createPredicateChoice return an instance of the new type. But also deprecate that method, and suggest to use the new method you create.

Here's a great example of what I talked about in my review, suggesting to keep implementation types out of the "api" because we can now just delete PredicateRecipeChoice entirely.

Most issues with the PR should now be resolved, but I'm not quite sure how to properly replace the PotionMix predicate choice. The new PredicateChoice requires an example stack, but this might not really make sense for use in the PotionMix. I'm hesitant to make the example stack nullable since not having one can break recipes. Maybe the PotionMix update should be left to a seperate PR?

@CPieter
CPieter requested a review from Machine-Maker February 9, 2025 09:30
@Machine-Maker

Machine-Maker commented Feb 17, 2025

Copy link
Copy Markdown
Member

Everything looks mostly good, some small style stuff, but we can fix that ourselves right before we merge it.

The new PredicateChoice requires an example stack, but this might not really make sense for use in the PotionMix

I think what we can do is just create a dummy example stack there. The only place the old predicate choice was used was in potion mixes where the example stack didn't matter. So just creating a random itemstack isn't going to break anything unless people start using the now-deprecated method for actual recipes. Which is their problem.

@CPieter
CPieter marked this pull request as draft February 28, 2025 18:48
@CPieter

CPieter commented Feb 28, 2025

Copy link
Copy Markdown
Contributor Author

After additional testing I've found that the predicate matching works unpredictably when used with shapeless recipes. I've converted the PR to a draft while I figure out the issue.

@derverdox

Copy link
Copy Markdown

Thanks for continuing to work on the idea! All the best, Verdox

@paulcomte

Copy link
Copy Markdown

Hey @CPieter any update on this feature? I'd be really glad to see this live

Replace RecipeChoice class with an interface + records, add PredicateChoice,
implement recipe book matching, and switch over potion mixing recipes.
@Machine-Maker
Machine-Maker force-pushed the feature/predicate-choice branch from 3f515a9 to 9255caf Compare August 5, 2026 01:12

@Machine-Maker Machine-Maker left a comment

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.

Ok, I found the issue, (ty Claude) and did a bunch of testing, I think this is fixed now. Works for shaped/shapeless and the recipe book.

@Machine-Maker
Machine-Maker marked this pull request as ready for review August 5, 2026 01:13
@papermc-projects papermc-projects Bot moved this from Changes required to Full approval in Paper PR Queue Aug 5, 2026
Comment thread paper-api/src/main/java/org/bukkit/inventory/PredicateRecipeChoiceImpl.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/PredicateRecipeChoiceImpl.java Outdated
Comment thread paper-api/src/main/java/org/bukkit/inventory/PredicateRecipeChoiceImpl.java Outdated
@Machine-Maker Machine-Maker self-assigned this Aug 6, 2026
@Machine-Maker

Copy link
Copy Markdown
Member

Ok, addressed reviews

@lynxplay lynxplay left a comment

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.

Not much of a fan of the test logic, maybe the models of today can emit something more logical. A full test matrix seems possibly better but requires a good bit of work. So for now they can stay in.

LGTM

@lynxplay
lynxplay merged commit 1797fbc into PaperMC:main Aug 28, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Full approval to Merged in Paper PR Queue Aug 28, 2026
granny added a commit to PurpurMC/Purpur that referenced this pull request Aug 30, 2026
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@1797fbcc Add PredicateChoice (PaperMC/Paper#12017) [closes #1460]
PaperMC/Paper@a2a42c5b Correctly consume chunkStatus in loadChunksAsync (PaperMC/Paper#14220)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api type: feature Request for a new Feature.

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

7 participants