neoforged / NeoForge

Neo Modding API for Minecraft, based on Forge
https://projects.neoforged.net/neoforged/neoforge
Other
1.14k stars 165 forks source link

VillagerTradesEvent and WandererTradesEvent has no way to access DatapackRegistries. #1527

Open Lanse505 opened 1 week ago

Lanse505 commented 1 week ago

Created an issue per @sciwhiz12 's recommendation/request.

Feature Suggestion: Provide RegistryAccess for VillagerTradesEvent and WandererTradesEvent

Currently, neither the VillagerTradesEvent nor the WandererTradesEvent has access to a RegistryAccess instance. This limitation affects mods that rely on DatapackRegistry values to create specific ItemStack objects. According to the documentation, both events are triggered during reload by the TagsUpdatedEvent. However, neither event inherits from TagsUpdatedEvent nor receives a reference to RegistryAccess, making it impossible to access data from datapack registries.

Example Use Case

In my current mod, I have a "Drone/Princess/Queen"-variant item that contains all the species information and attributes as part of a Genome object (stored as a DataComponent), which is generated from the IAllele representing the species. Since IAllele is a DatapackRegistry object, I am unable to access the IAllele from the DatapackRegistry using its corresponding ResourceKey<IAllele>.

Proposed Solution

While it is possible to access the server instance through ServerLifecycleHooks, a more elegant solution would be to pass down the RegistryAccess provided by the TagsUpdatedEvent at some point in the event chain. This would make it easier to have access to datapack registries and allow mod developers to utilize DatapackRegistry values more effectively.

ZestyBlaze commented 1 week ago

I can actually see this being useful in my mod's case soon too, I can't see this PR being too difficult at all, I'll sketch up a draft PR when I get home

dhyces commented 1 week ago

While we're adding this to these events, might as well also add RegistryAccess to RegisterBrewingRecipesEvent too (would be nice for me, as I have a mod that needs to be installed on both client and server and would like to add data-pack potion recipes)

ZestyBlaze commented 1 week ago

@Lanse505 PR for it done, should be merged in a couple days if no other additions or changes are needed