Fabric API

Fabric API

152M Downloads

[Feature Request] Recipe Sync API

mezz opened this issue ยท 4 comments

commented

For mods that use recipes on the client, it would be useful to have a way for mods to sync recipes from the server to the client.

Considerations

  • Mods should exist on the server in order to make the request there.
    • This will avoid clients requesting massive amounts of data from a server in an uncontrolled way.
  • There should be a period of time or event where mods can request specific recipe types to by synced.
    • Not all recipes need to by synced and multiple mods may require the same recipe types, so this will prevent sending too much data or redundant data.
  • Recipes sent to the client should include the ID (so ideally the whole RecipeHolder should by synced and stored in a RecipeMap).
    • This will give mods better ability to manage recipes on the client similarly to how they are managed on the server, allowing for persisting references to recipes across game play sessions.

@shartte completed an implementation in neoforged/NeoForge#2021 with some additional motivations and design rationale.

commented

Is there a need to allow the recipes to be synced during play? Or can it all happen at during configuration?

Care will need to be taken to ensure that the packet is split if required.

commented

Is there a need to allow the recipes to be synced during play? Or can it all happen at during configuration?

I think it will be fine to sync them alongside the two places that ClientboundUpdateRecipesPackets are sent in the serverside PlayerList class. If mods have a more specific need for syncing some recipes at a specific time, I think it will not be a shared need like this one and would be better to implement individually.

Care will need to be taken to ensure that the packet is split if required.

Recipe syncing is more efficient than in past versions because the new HolderSets are much more compact than item lists, so the packet splitting may not be as big of a concern.

commented

Do you have a previous example of splitting packets I can reference, or any recommendations for this case?

commented

Do you have a previous example of splitting packets I can reference, or any recommendations for this case?

#4590 is a great example as well as registry sync, as it wont be using the vanilla packet it wont need to encode it twice as this PR does, the packet can just be a byte[]

I was thinking a configuration task would be the best way to go about doing this. The API maybe being an event that allows mods to supplies some predicates (with some helpers to include all recipes of a specific type) that will be used to test each event to see if they need syncing or not.