Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Adding PredicateChoice to Paper API

Open derverdox opened this issue 2 years ago • 8 comments

3 days ago I posted a pull request #9991 about adding CustomModelChoice. However, we came to the conclusion that we need a more generalized approach. As a result, I began working on what is called PredicateChoice. To make it work the StackedContents logic had to be edited. In the ExtraContentsMap we don't store the exact ingredient items of every recipe ingredient. Instead, whenever we account a new stack in StackedContents logic we compare it to the provided predicates and store them as "ingredient items" if they fulfill at least one predicate.

We act like the items in the inventory of the player are the exact choices when any ingredient predicate returns true.

It gets more apparent when looking at the changes. The first tests showed that it works like a charm.

Pros

  • With predicate choice one can implement his own version of ItemPredicate. This allows for the programmer to make the recipe check for whatever he wants.
  • They still work as intended if you want to use MaterialChoice or ExactChoice.

Cons

  • If you use PredicateChoice the predicate tests Bukkit ItemStacks. Consequently, NMS stacks need to instantiate their Craftbukkit mirror to make the checks happen.

Let me know your thoughts! :) Maybe I have missed something.

derverdox avatar Dec 03 '23 12:12 derverdox

This is just a quick mockup of what I had in mind. Ignore the API, it is just quicker to make it not an interface+record. I didn't exhaustively test it, but the test in the test-plugin work so far.

Machine-Maker avatar Dec 03 '23 18:12 Machine-Maker

This is just a quick mockup of what I had in mind. Ignore the API, it is just quicker to make it not an interface+record. I didn't exhaustively test it, but the test in the test plugin work so far.

Looks good to me! :) My PR was more of a proof of concept. I am fine with your implementation. Do you want me to fix my PR? Or do we just pick your's instead? I think it doesn't make a difference right?

derverdox avatar Dec 03 '23 18:12 derverdox

You can go ahead and fixup yours

Machine-Maker avatar Dec 03 '23 18:12 Machine-Maker

You can go ahead and fixup yours

Allright

derverdox avatar Dec 03 '23 19:12 derverdox

Upon testing this found that clicking the recipe book item does not move the items in your inventory to the crafting grid. image Ingredients have custom model data, lore, and attributes set. The recipe does work, just not the recipe books behavior. This may be more to blame on the recipe book patch than this patch.

partydev avatar Jan 09 '24 01:01 partydev

Is this still being worked on?

JakeGBLP avatar Mar 07 '24 17:03 JakeGBLP

Is this still being worked on?

Hello! I was working on my bachelor thesis lately so i was not able to fully work on this. Will continue soon!

derverdox avatar Mar 20 '24 22:03 derverdox

Upon testing this found that clicking the recipe book item does not move the items in your inventory to the crafting grid. image Ingredients have custom model data, lore, and attributes set. The recipe does work, just not the recipe books behavior. This may be more to blame on the recipe book patch than this patch.

Hey. I just uploaded a fix to the recipe book problem. The issue seems to be resolved. It would be nice if you could test as well! :)

derverdox avatar Mar 21 '24 15:03 derverdox