Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Datapack Registry to be configured by RegistryBuilder #1447

Merged

Conversation

Argon4W
Copy link
Contributor

@Argon4W Argon4W commented Aug 12, 2024

Modify the RegistryDataLoader$RegistryData and RegistryBuilder to allow datapack registries to be configured by RegistryBuilder.

@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

@CLAassistant
Copy link

CLAassistant commented Aug 12, 2024

CLA assistant check
All committers have signed the CLA.

@Matyrobbrt Matyrobbrt added enhancement New (or improvement to existing) feature or request data driven This request involves a data driven system 1.21.2 Targeted at Minecraft 1.21.2 labels Aug 13, 2024
@Matyrobbrt
Copy link
Member

Why do you need to configure dp regs with registrybuilder?
I'm not sure this is the best approach, instead ModifyRegistriesEvent should also fire for data pack registries.

@Argon4W
Copy link
Contributor Author

Argon4W commented Aug 13, 2024

Why do you need to configure dp regs with registrybuilder? I'm not sure this is the best approach, instead ModifyRegistriesEvent should also fire for data pack registries.

Sorry but I noticed that the doc of the ModifyRegistriesEvent said that it cannot be used to modify datapack registries.

Also, even if this event works, it cannot add default value for the datapack registry cuz the generated registry is MappedRegistry instead of DefaultedMappedRegistry.

@Matyrobbrt
Copy link
Member

Ah, so your usecase is adding default values to the registry? I suppose that's fine, but if you add the consumer to the registry data, please make it the last parameter of the record.

@Argon4W
Copy link
Contributor Author

Argon4W commented Aug 23, 2024

Ah, so your usecase is adding default values to the registry? I suppose that's fine, but if you add the consumer to the registry data, please make it the last parameter of the record.

Okay, I just added a new commit to make the consumer the last parameter.

@Matyrobbrt Matyrobbrt added 1.21.1 Targeted at Minecraft 1.21.1 and removed 1.21.2 Targeted at Minecraft 1.21.2 labels Aug 27, 2024
@XFactHD XFactHD linked an issue Sep 12, 2024 that may be closed by this pull request
@Shadows-of-Fire
Copy link
Contributor

I don't think letting a datapack registry be a DefaultedMappedRegistry is a good idea, since by virtue of being a data registry, data objects may be removed (including the default object) which will invalidate the nonnull contract of DefaultedMappedRegistry#get(ResourceLocation).

Allowing the configuration through registry builder satisfies requirements from #1158, which is (or rather, might be?) useful, but use of a default key is a footgun.

@Argon4W
Copy link
Contributor Author

Argon4W commented Sep 18, 2024

I don't think letting a datapack registry be a DefaultedMappedRegistry is a good idea, since by virtue of being a data registry, data objects may be removed (including the default object) which will invalidate the nonnull contract of DefaultedMappedRegistry#get(ResourceLocation).

Allowing the configuration through registry builder satisfies requirements from #1158, which is (or rather, might be?) useful, but use of a default key is a footgun.

Indeed, the default object may be removed. But it also allow datapacks to change a hardcoded default state, making the datapack behavior more flexible. Also, modifying default object isn’t quite common, and the default value is disabled at default, so if you want to add a default value, you should declare it explicitly and take the risk.

@Argon4W
Copy link
Contributor Author

Argon4W commented Sep 18, 2024

I don't think letting a datapack registry be a DefaultedMappedRegistry is a good idea, since by virtue of being a data registry, data objects may be removed (including the default object) which will invalidate the nonnull contract of DefaultedMappedRegistry#get(ResourceLocation).

Allowing the configuration through registry builder satisfies requirements from #1158, which is (or rather, might be?) useful, but use of a default key is a footgun.

BTW, adding default value can prevent the usage of unsafe null value or Optional as default value. Though I can use Holder.direct() and RegistryFileCodec/ByteBufCodecs.holder to achieve similar behavior like the default value, it just feel hacky and the default value has no key to represent

@Shadows-of-Fire
Copy link
Contributor

Eh, well, people can use it at their own risk. It isn't really any different than just calling .holderOrThrow on a datapack registry, which people are almost certainly doing.

@Shadows-of-Fire Shadows-of-Fire merged commit 600c870 into neoforged:1.21.x Sep 23, 2024
6 checks passed
@neoforged-releases
Copy link

🚀 This PR has been released as NeoForge version 21.1.58.

@Argon4W Argon4W deleted the 1.21.x-datapack-registry-improvements branch September 23, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1 data driven This request involves a data driven system enhancement New (or improvement to existing) feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Datapack Registry Callbacks
4 participants