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

Registry Modification API #8920

Closed
wants to merge 10 commits into from
Closed

Conversation

Machine-Maker
Copy link
Member

@Machine-Maker Machine-Maker commented Feb 26, 2023

Adds two new "events" that PluginBootstrap can register to which enable modification and addition to both built-in and data-driven registries. This opens up tons of new possibilities for plugins to customize things with API that was previously only possible with nms/reflection.

Data-Driven: Types which are loaded purely from datapacks (custom and vanilla)
Built-In: Loaded via source code, never read from a file

There are two events plugins can listen to, one is fired when an "entry" is about to be added to a registry, either a built-in or data-driven. This allows modification of the "entry" before it's registered. The second event is fired right before the registry is frozen (to prevent new additions). This is used to add completely new entries.

Demo

There are two "demonstration" apis added, one for ChatType and one for GameEvent. Just allows some very simply customization, more just to show how it works for both built-in and data-driven types.


TODO

Preview Give feedback
  1. 5 of 5
  2. 4 of 4

@Machine-Maker Machine-Maker requested a review from a team as a code owner February 26, 2023 18:08
@Machine-Maker Machine-Maker added the status: blocked Issue or Request is waiting on some other issue or change. label Feb 26, 2023
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from a9bf51a to 2f40827 Compare February 27, 2023 05:19
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 2f40827 to 52f2089 Compare February 27, 2023 23:45
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 8db100c to 1edf434 Compare February 28, 2023 17:53
@Machine-Maker Machine-Maker removed the status: blocked Issue or Request is waiting on some other issue or change. label Feb 28, 2023
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 4faadcf to 41d255f Compare March 15, 2023 21:26
@Machine-Maker Machine-Maker changed the base branch from master to dev/1.19.4 March 15, 2023 21:27
@Machine-Maker
Copy link
Member Author

Updated for 1.19.4 and moved the vibration level to the builder so that it can be changed. Also added a test to make sure the match the map that was previously used.

Base automatically changed from dev/1.19.4 to master March 16, 2023 15:32
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 5ace877 to 19508f6 Compare March 19, 2023 20:19
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch 2 times, most recently from 9b1ff9b to d0708a3 Compare March 27, 2023 19:05
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from d0708a3 to b9991c4 Compare March 28, 2023 17:19
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch 2 times, most recently from 73ec071 to ee324d6 Compare May 28, 2023 00:43
@Machine-Maker
Copy link
Member Author

For the GameEvent builder, I decided to not make the vibration level configurable there. They are really 2 different systems, the vibration stuff and game events. Not all game events are listened to for vibrations, so I think a better solution is to use the game event bukkit events to change the level of certain game events.

I also reverted the change that changed all the static final fields in GameEvent to Reference because we are now going with code generation to generate a file full of keys for GameEvent for use with the registry mod api.

@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 18eebc2 to c32bcc0 Compare May 28, 2023 01:31
Comment on lines 316 to 251
+/**
+ * Register listeners to points in a registry's lifecycle.
+ */
[email protected]
[email protected]
+public interface RegistryManager {
+
+ /**
+ * Register a listener which is called when an object is about
+ * to be added to the specified registry. Useful for modifying
+ * objects before they are added.
+ *
+ * @param registryKey the registry key
+ * @param listener an instance of the listener
+ * @param <T> object type
+ * @param <B> object builder type
+ */
+ <T extends Keyed, B extends RegistryBuilder<T>> void registerAdditionListener(@NotNull RegistryKey<T> registryKey, @NotNull RegistryAdditionListener<T, B> listener);
+
+ /**
+ * Register a listener which is called when a registry is about
+ * to be frozen. Useful for adding new entries to registries
+ * that support custom entries.
+ *
+ * @param registryKey the registry key
+ * @param listener an instance of the listener
+ * @param <T> object type
+ * @param <B> object builder type
+ */
+ <T extends Keyed, B extends RegistryBuilder<T>> void registerPreFreezeListener(@NotNull RegistryKey<T> registryKey, @NotNull RegistryPreFreezeListener<T, B> listener);
+}
Copy link
Member

Choose a reason for hiding this comment

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

It may just be me, but I find the usage of "register" in the context of registries despite being used for the listener system be a bit confusing.

Although it would deviate from PluginManger's registerEvent naming scheme.. I think it may be better to reduce confusion.
Maybe something like:

  • newRegisterListener, newRegistrationListener, onRegistration
  • onFinalization, onPreFreeze, onRegistryFinalization

I am not sure, the point is, I think that we should perhaps not use the term register here as it may be a bit confusing. Although, just seeing what others might think here.

@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch 3 times, most recently from 1ff0675 to 38e3441 Compare May 12, 2024 02:17
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 38e3441 to 6a9d061 Compare May 28, 2024 19:35
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch 3 times, most recently from e882fe4 to 0511ba4 Compare June 9, 2024 15:06
@Amejonah1200
Copy link

🥳❔

@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch 3 times, most recently from d7fc4f7 to 6385241 Compare June 13, 2024 14:51
@Machine-Maker Machine-Maker force-pushed the feature/registry-modification branch from 7054949 to df157b7 Compare June 14, 2024 21:49
@Machine-Maker Machine-Maker changed the base branch from master to dev/1.21 June 14, 2024 21:49
@lynxplay lynxplay closed this Jun 15, 2024
@lynxplay lynxplay deleted the feature/registry-modification branch June 15, 2024 13:41
@lynxplay
Copy link
Contributor

Merged into preliminary 1.21 registry dev branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

10 participants