Paper
Paper copied to clipboard
Add Recipe API
Adds several methods to the World
for interacting with Minecraft's RecipeManager
, allowing you to get a recipe via assorted means (such as by providing a container block or collection of items). A test plugin is available here.
Patch is named "Add Recipe API" because the new methods that Spigot recently added are exclusive to the crafting table so they're hardly deserving of the title "Recipe API" >:(
Closes #616
Use cases:
- Custom crafting in an inventory like a dispenser or a custom chest
- Automatic crafting in a dispenser or automatically smelting block/mob drops
- etc
Implementation notes:
- the I type of RecipeType matches what container the recipes expect, not necessarily what they're typically associated with
- a custom MenulessContainer class is used to create a container that is compatible with all inventory types (specifically the outlier of CraftingContainer ~~which is only important because it uses width&height which should be abstracted out into an interface >:(~~) which overrides any methods that reference the
menu
field to prevent NPE (not that it should matter much because my code doesn't use any of them)- should this be moved to a CraftWorld subclass with a more specific name so other patches don't try to use it and possibly experience errors from future updates? or is it fine here?
- features astronomical performance improvements!!!!!1! i expect to see this implemented within every paper fork by the top of the hour
Feedback welcome! :D
Should add an entry in bukkit's Registry for this. Just like nms has one for recipe types.
done! :)
Comments addressed and patch rebased.
Note: an expanded recipe API has been implemented upstream but, unlike this patch, it does not support crafting types other than crafting tables (i.e. furnaces, stonecutters, etc)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still applicable and pending review 🙁
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Why are these recipe methods on the World interface?
because each NMS world has its own RecipeManager class? presumably because different worlds can have different recipes loaded depending on the installed data packs
because each NMS world has its own recipe manager class? presumably because different worlds can have different recipes loaded depending on the installed data packs
The getRecipeManager method on ServerLevel just redirects to the getRecipeManager method on MinecraftServer which is global. Only one instance of RecipeManager is created. And datapacks are global, not per world.
@Machine-Maker sorry for late reply-- just looked into it and while you are correct that the RecipeManager has only one instance, several of its methods require you to specify the world. i'll keep those on the World interface and move the rest to Server
Rebased for 1.18.2 and addressed world concerns
edit: wtf how did i remove the request for review from code maintainers
um ok thanks github
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
bumping to prevent stale bot & to say i'll rebase when 1.19 update is done & to say i still am not sure what to do about unit tests failing when using the PaperRegistry class