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

Improve tag loading and load non-vanilla tags as well #4849

Merged
merged 24 commits into from
Oct 22, 2024

Conversation

eclipseisoffline
Copy link
Contributor

@eclipseisoffline eclipseisoffline commented Jul 12, 2024

This PR improves the way Geyser loads tags sent by the server, which allows both vanilla and non-vanilla tags to be loaded. It also makes it easier to add new registries to load tags for. Loading all tags for a registry, and not just vanilla ones, is important for datapack support and matches the behaviour of the Java client. Datapacks can define custom tags and then use these elsewhere, such as in custom enchantments.

To start with, the PR adds a new JavaRegistryKey<T> record, which is used to define a Java registry (can be both hardcoded or data-driven). The record doesn't store the contents of a registry (this is done by RegistryCache or other classes for hardcoded registries), rather, it stores its registry key, and optionally a network serializer- and deserializer for translating between network IDs and registry objects.

JavaRegistryKey<T> is used to define registries that Geyser should load data-driven objects (in RegistryCache) or tags (in TagCache) for. Instances of this record are created and stored in the new JavaRegistries class, which also has methods to allow for easy creation of the registry keys.

Along with this, the PR also adds a new Tag<T> record, which stores a JavaRegistryKey<T> and a Key - the first being the registry of the tag and the second being the actual tag key. TagCache now uses the Tag<T> record for tag lookup. The old way of looking tags up in int[][] arrays has been replaced by a simple Map<Tag<?>, int[].

TagCache now loads all registries listed in JavaRegistries, as long as they satisfy the requirements for loading tags - that is, they must have a network serializer- and deserializer registered to be able to translate between network IDs and registry objects, which is required for the functionality of TagCache.

Along with the changes to tag loading, this PR also adds a new HolderSet class, which makes loading and using Minecraft's holder sets easier within Geyser, and has a better integration with Geyser's tag cache.

Basic gameplay testing, as well as confirming both vanilla- and non-vanilla tags load by letting Geyser make a printout of loaded tags, has been done.

…rics

# Conflicts:
#	core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java
#	core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java
#	core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java
#	core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java
#	core/src/main/java/org/geysermc/geyser/item/enchantment/Enchantment.java
#	core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java
@eclipseisoffline
Copy link
Contributor Author

A lot has changed now, generics have been implemented for type safety and some stuff has moved around or been added. Pretty happy with how it looks now, but this definitely still needs testing.

@eclipseisoffline
Copy link
Contributor Author

Both of @Camotoy's reviews have been addressed in the latest commit. I've also done some basic gameplay testing and let Geyser make a printout of all loaded tags to confirm both vanilla- and non-vanilla tags loaded successfully.

@Camotoy Camotoy changed the base branch from master to feature/1.21.2 October 22, 2024 22:31
@Camotoy Camotoy merged commit e78b248 into GeyserMC:feature/1.21.2 Oct 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom enchantments using the new method are not visible in the tooltip
3 participants