Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add Recipe API

Open qixils opened this issue 2 years ago • 13 comments

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

qixils avatar Jul 15 '21 09:07 qixils

Should add an entry in bukkit's Registry for this. Just like nms has one for recipe types.

Machine-Maker avatar Jul 16 '21 07:07 Machine-Maker

done! :)

qixils avatar Jul 16 '21 17:07 qixils

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)

qixils avatar Aug 26 '21 03:08 qixils

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.

stale[bot] avatar Nov 02 '21 05:11 stale[bot]

Still applicable and pending review 🙁

qixils avatar Nov 02 '21 05:11 qixils

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.

stale[bot] avatar Jan 01 '22 11:01 stale[bot]

Why are these recipe methods on the World interface?

Machine-Maker avatar Jan 03 '22 06:01 Machine-Maker

because each NMS world has its own RecipeManager class? presumably because different worlds can have different recipes loaded depending on the installed data packs

qixils avatar Jan 03 '22 06:01 qixils

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 avatar Jan 03 '22 06:01 Machine-Maker

@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

qixils avatar Mar 05 '22 06:03 qixils

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

qixils avatar Mar 05 '22 07:03 qixils

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.

stale[bot] avatar May 31 '22 01:05 stale[bot]

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

qixils avatar Jun 08 '22 15:06 qixils