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

Add system for Dynamic Registry Flags #330

Merged
merged 17 commits into from
Jul 31, 2023

Conversation

cocona20xx
Copy link
Contributor

This PR adds the beginnings of a system similar to (but far simpler than) the Static Registry Sync API for Dynamic Registries, allowing flags to be set which modify the behavior of Dynamic Registries.

Currently, only one flag, DynamicRegistryFlag.OPTIONAL, exists—this flag is a clone of the similar SyncOption#skipWhenEmpty, and thus only effects synchronized dynamic registries, and simply has no effect on non-synced dyn. registries.

Both the OPTIONAL flag (and it's FAPI counterpart) set whether a dynamic registry should attempt to be synced with a connecting client which does not have said dynamic registry. This allows for clients without certain dynamic registries to still be able to connect, and thus is useful when creating entirely server-sided mods intended to be compatible with vanilla.

More flags can easily be added in the future, however the infrastructure for flags that apply to all dynamic registries, and not just synced ones, has not yet been set up—a future PR to add such a flag would need to add a mixin for that purpose somewhere other than DynamicRegistrySync.

Note that the test mod for the registry API is ironically too complicated to serve as a proper test for this API addition—I have created a test mod locally (using the mavenLocal() repo) and tested having a vanilla client connect to a pure QSL + testmod server with an optional dynamic registry defined in the testmod, and it thankfully did work. If required, I can upload this testmod's repo to github with instructions on how to run it.

- Currently, only one flag, `OPTIONAL`, exists.
- Modified DynamicRegistrySyncMixin in order to implement these flags. Due to the Redirect mixin header used to implement the flag filtering being taken directly from FAPI, the header of DynamicRegistrySyncMixin was changed to mention FabricMC copyright, in accordance with QSL contribution rules in CONTRIBUTING.md
- Modify DynamicRegistryFlagManager to use Identifiers over RegistryKeys internally, in order to avoid generic-related jank.
- Fix mixin ported from FAPI by correcting method target string to use Quilt Mappings.
- Implement very basic tests.
@ix0rai ix0rai added enhancement New feature or request library: core Related to the core library. s: waiting for test This pull request is waiting to be tested, the PR cannot be put in FCP until it has been tested. labels Jul 26, 2023
@cocona20xx
Copy link
Contributor Author

This should probably be considered a blocking addition for FAPI 0.86.0 & 0.86.1 compat in QFAPI alongside #329.

@cocona20xx
Copy link
Contributor Author

Going to go through and implement some of the changes suggested by @Pyrofab in a moment. Probably going to have both varargs for the flags and the current system, in order to have similarities to both QSL's static registry flags and FAPI's dynamic registry flags.

Disabling flags will need to check if the dynamic registries are frozen, and if they are, refuse to change the state of the flag on that registry. This should stop desyncs, hopefully.

- Added protected helper method DynamicMetaRegistryImpl#isFrozen for use in DynamicRegistryFlagManager
- Added DynamicMetaRegistryImpl#LOGGER with the name "quilt_dynamic_registries" as a logger for catching exceptions related to the setting of flags
- Removed the ability to disable dynamic registry flags, changed the signature of the related flag-enabling methods from enableFlag -> setFlag (on both DynamicRegistryFlag and DynamicRegistryFlagManager)
- DynamicRegistryFlagManager#setFlag now throws an IllegalStateException if a mod attempts to enable a flag when dynamic registries are frozen. This is caught and printed to the logger mentioned prior in DynamicRegistryFlag calls
- Added varargs for setting DynamicRegistryFlag values on dynamic registry creation
- Improved DynamicRegistryFlag#OPTIONAL javadocs slightly
@cocona20xx cocona20xx requested a review from Pyrofab July 26, 2023 19:29
@EnnuiL EnnuiL added t: refactor This proposes a refactor. t: new api This adds a new API. and removed enhancement New feature or request t: new api This adds a new API. labels Jul 29, 2023
Copy link
Contributor

@EnnuiL EnnuiL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I do have style cleanup suggestions in mind, I believe it would get way too nitpicky to have it block a PR (I'd rather have a post-merge commit than that);
The important thing is: the logic looks sound to me; Ennui's Stamp of Approval (Can Skip FCP Edition)

EnnuiL and others added 4 commits July 29, 2023 01:05
One of them needs a more specific wording change, so it's going to be done in another commit since that's easier for us

Co-authored-by: Ennui Langeweile <[email protected]>
accidentally dropped a word

guh
@cocona20xx
Copy link
Contributor Author

I LOVE FORGETTING A SINGLE WORD AND HAVING TO MAKE ANOTHER COMMIT!!!!!

@EnnuiL
Copy link
Contributor

EnnuiL commented Jul 29, 2023

I LOVE FORGETTING A SINGLE WORD AND HAVING TO MAKE ANOTHER COMMIT!!!!!

mood

cocona20xx and others added 2 commits July 29, 2023 00:33
Hopefully the final style change moment

Co-authored-by: Ennui Langeweile <[email protected]>
- Added back methods to DynamicMetaRegistry with the same signature as the old ones to avoid binary incompatibility. These are marked as deprecated and should be removed in a breaking/major QSL release.
@cocona20xx cocona20xx requested a review from Pyrofab July 31, 2023 03:01
@EnnuiL EnnuiL merged commit 8a65dbd into QuiltMC:1.20 Jul 31, 2023
2 checks passed
cocona20xx added a commit to cocona20xx/quilt-standard-libraries that referenced this pull request Aug 2, 2023
* Implement Dynamic Registry Flags.
- Currently, only one flag, `OPTIONAL`, exists.
- Modified DynamicRegistrySyncMixin in order to implement these flags. Due to the Redirect mixin header used to implement the flag filtering being taken directly from FAPI, the header of DynamicRegistrySyncMixin was changed to mention FabricMC copyright, in accordance with QSL contribution rules in CONTRIBUTING.md

* Implement Dynamic Registry Flags p2
- Modify DynamicRegistryFlagManager to use Identifiers over RegistryKeys internally, in order to avoid generic-related jank.
- Fix mixin ported from FAPI by correcting method target string to use Quilt Mappings.
- Implement very basic tests.

* Expanded upon OPTIONAL flag javadocs to elaborate use-case

* Expanded further on OPTIONAL javadocs

* Implemented some changes suggested by Pyrofab

- Added protected helper method DynamicMetaRegistryImpl#isFrozen for use in DynamicRegistryFlagManager
- Added DynamicMetaRegistryImpl#LOGGER with the name "quilt_dynamic_registries" as a logger for catching exceptions related to the setting of flags
- Removed the ability to disable dynamic registry flags, changed the signature of the related flag-enabling methods from enableFlag -> setFlag (on both DynamicRegistryFlag and DynamicRegistryFlagManager)
- DynamicRegistryFlagManager#setFlag now throws an IllegalStateException if a mod attempts to enable a flag when dynamic registries are frozen. This is caught and printed to the logger mentioned prior in DynamicRegistryFlag calls
- Added varargs for setting DynamicRegistryFlag values on dynamic registry creation
- Improved DynamicRegistryFlag#OPTIONAL javadocs slightly

* Commit most style changes

One of them needs a more specific wording change, so it's going to be done in another commit since that's easier for us

Co-authored-by: Ennui Langeweile <[email protected]>

* Make documentation for DynamicRegistryFlag more accurate

* Improve the javadocs on DynamicRegistryFlag AGAIN

accidentally dropped a word

guh

* BUT WAIT, THERE'S MORE!

Hopefully the final style change moment

Co-authored-by: Ennui Langeweile <[email protected]>

* Implement style change in DynamicRegistryFlagManager

Co-authored-by: LambdAurora <[email protected]>

* Fix binary incompatibility hopefully?
- Added back methods to DynamicMetaRegistry with the same signature as the old ones to avoid binary incompatibility. These are marked as deprecated and should be removed in a breaking/major QSL release.

* Remove deprecation annotations on compat. method overloads in DynamicMetaRegistry

---------

Co-authored-by: Ennui Langeweile <[email protected]>
Co-authored-by: LambdAurora <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library: core Related to the core library. s: waiting for test This pull request is waiting to be tested, the PR cannot be put in FCP until it has been tested. t: new api This adds a new API. t: refactor This proposes a refactor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants