diff --git a/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserRecipe.java b/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserRecipe.java index d9cae943f..b0f5a1b44 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserRecipe.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserRecipe.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay; /** - * A more compact version of {link org.geysermc.mcprotocollib.protocol.data.game.recipe.Recipe}. + * A more compact version of {@link org.geysermc.mcprotocollib.protocol.data.game.recipe.display.RecipeDisplay}. */ public interface GeyserRecipe { /** diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java index 2cc7bd5a6..ecd293bff 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java @@ -40,9 +40,9 @@ import org.cloudburstmc.protocol.bedrock.data.TrimPattern; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.type.living.animal.tameable.WolfEntity; import org.geysermc.geyser.inventory.item.BannerPattern; +import org.geysermc.geyser.inventory.item.GeyserInstrument; import org.geysermc.geyser.inventory.recipe.TrimRecipe; import org.geysermc.geyser.item.enchantment.Enchantment; -import org.geysermc.geyser.inventory.item.GeyserInstrument; import org.geysermc.geyser.level.JavaDimension; import org.geysermc.geyser.level.JukeboxSong; import org.geysermc.geyser.level.PaintingType; @@ -77,35 +77,35 @@ import java.util.function.ToIntFunction; @Accessors(fluent = true) @Getter public final class RegistryCache { - private static final Map, Map> DEFAULTS; - private static final Map, BiConsumer>> REGISTRIES = new HashMap<>(); + private static final Map> DEFAULTS; + private static final Map>> REGISTRIES = new HashMap<>(); static { - register(JavaRegistries.CHAT_TYPE, cache -> cache.chatTypes, ChatDecoration::readChatType); - register(JavaRegistries.DIMENSION_TYPE, cache -> cache.dimensions, JavaDimension::read); + register("chat_type", cache -> cache.chatTypes, ChatDecoration::readChatType); + register("dimension_type", cache -> cache.dimensions, JavaDimension::read); register(JavaRegistries.ENCHANTMENT, cache -> cache.enchantments, Enchantment::read); - register(JavaRegistries.JUKEBOX_SONG, cache -> cache.jukeboxSongs, JukeboxSong::read); - register(JavaRegistries.PAINTING_VARIANT, cache -> cache.paintings, context -> PaintingType.getByName(context.id())); - register(JavaRegistries.TRIM_MATERIAL, cache -> cache.trimMaterials, TrimRecipe::readTrimMaterial); - register(JavaRegistries.TRIM_PATTERN, cache -> cache.trimPatterns, TrimRecipe::readTrimPattern); - register(JavaRegistries.BIOME, (cache, array) -> cache.biomeTranslations = array, BiomeTranslator::loadServerBiome); - register(JavaRegistries.BANNER_PATTERN, cache -> cache.bannerPatterns, context -> BannerPattern.getByJavaIdentifier(context.id())); - register(JavaRegistries.WOLF_VARIANT, cache -> cache.wolfVariants, context -> WolfEntity.BuiltInWolfVariant.getByJavaIdentifier(context.id().asString())); - register(JavaRegistries.INSTRUMENT, cache -> cache.instruments, GeyserInstrument::read); + register("instrument", cache -> cache.instruments, GeyserInstrument::read); + register("jukebox_song", cache -> cache.jukeboxSongs, JukeboxSong::read); + register("painting_variant", cache -> cache.paintings, context -> PaintingType.getByName(context.id())); + register("trim_material", cache -> cache.trimMaterials, TrimRecipe::readTrimMaterial); + register("trim_pattern", cache -> cache.trimPatterns, TrimRecipe::readTrimPattern); + register("worldgen/biome", (cache, array) -> cache.biomeTranslations = array, BiomeTranslator::loadServerBiome); + register("banner_pattern", cache -> cache.bannerPatterns, context -> BannerPattern.getByJavaIdentifier(context.id())); + register("wolf_variant", cache -> cache.wolfVariants, context -> WolfEntity.BuiltInWolfVariant.getByJavaIdentifier(context.id().asString())); // Load from MCProtocolLib's classloader NbtMap tag = MinecraftProtocol.loadNetworkCodec(); - Map, Map> defaults = new HashMap<>(); + Map> defaults = new HashMap<>(); // Don't create a keySet - no need to create the cached object in HashMap if we don't use it again - REGISTRIES.forEach((registry, $) -> { - List rawValues = tag.getCompound(registry.registryKey().asString()).getList("value", NbtType.COMPOUND); + REGISTRIES.forEach((key, $) -> { + List rawValues = tag.getCompound(key.asString()).getList("value", NbtType.COMPOUND); Map values = new HashMap<>(); for (NbtMap value : rawValues) { Key name = MinecraftKey.key(value.getString("name")); values.put(name, value.getCompound("element")); } // Can make these maps immutable and as efficient as possible after initialization - defaults.put(registry, Map.copyOf(values)); + defaults.put(key, Map.copyOf(values)); }); DEFAULTS = Map.copyOf(defaults); @@ -141,7 +141,7 @@ public final class RegistryCache { * Loads a registry in, if we are tracking it. */ public void load(ClientboundRegistryDataPacket packet) { - var reader = REGISTRIES.get(JavaRegistries.fromKey(packet.getRegistry())); + var reader = REGISTRIES.get(packet.getRegistry()); if (reader != null) { reader.accept(this, packet.getEntries()); } else { @@ -155,7 +155,27 @@ public final class RegistryCache { * @param reader converts the RegistryEntry NBT into a class file * @param the class that represents these entries. */ - private static void register(JavaRegistryKey registry, Function> localCacheFunction, Function reader) { + private static void register(String registry, Function> localCacheFunction, Function reader) { + register(MinecraftKey.key(registry), localCacheFunction, reader); + } + + /** + * @param registry the Java registry resource location. + * @param localCacheFunction which local field in RegistryCache are we caching entries for this registry? + * @param reader converts the RegistryEntry NBT into a class file + * @param the class that represents these entries. + */ + private static void register(JavaRegistryKey registry, Function> localCacheFunction, Function reader) { + register(registry.registryKey(), localCacheFunction, reader); + } + + /** + * @param registry the Java registry resource location. + * @param localCacheFunction which local field in RegistryCache are we caching entries for this registry? + * @param reader converts the RegistryEntry NBT into a class file + * @param the class that represents these entries. + */ + private static void register(Key registry, Function> localCacheFunction, Function reader) { REGISTRIES.put(registry, (registryCache, entries) -> { Map localRegistry = null; JavaRegistry localCache = localCacheFunction.apply(registryCache); @@ -192,8 +212,8 @@ public final class RegistryCache { /** * @param localCacheFunction the int array to set the final values to. */ - private static void register(JavaRegistryKey registry, BiConsumer localCacheFunction, ToIntFunction reader) { - REGISTRIES.put(registry, (registryCache, entries) -> { + private static void register(String registry, BiConsumer localCacheFunction, ToIntFunction reader) { + REGISTRIES.put(MinecraftKey.key(registry), (registryCache, entries) -> { Int2IntMap temp = new Int2IntOpenHashMap(); int greatestId = 0; for (int i = 0; i < entries.size(); i++) { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java index f0cd3afde..646b647d0 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java @@ -27,23 +27,14 @@ package org.geysermc.geyser.session.cache.registry; import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.protocol.bedrock.data.TrimMaterial; -import org.cloudburstmc.protocol.bedrock.data.TrimPattern; -import org.geysermc.geyser.entity.type.living.animal.tameable.WolfEntity; -import org.geysermc.geyser.inventory.item.BannerPattern; import org.geysermc.geyser.item.enchantment.Enchantment; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.inventory.item.GeyserInstrument; -import org.geysermc.geyser.level.JavaDimension; -import org.geysermc.geyser.level.JukeboxSong; -import org.geysermc.geyser.level.PaintingType; import org.geysermc.geyser.level.block.type.Block; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.ListRegistry; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.cache.RegistryCache; import org.geysermc.geyser.util.MinecraftKey; -import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType; import java.util.ArrayList; import java.util.List; @@ -56,20 +47,7 @@ public class JavaRegistries { public static final JavaRegistryKey BLOCK = create("block", BlockRegistries.JAVA_BLOCKS, Block::javaId); public static final JavaRegistryKey ITEM = create("item", Registries.JAVA_ITEMS, Item::javaId); - public static final JavaRegistryKey CHAT_TYPE = create("chat_type", RegistryCache::chatTypes); - public static final JavaRegistryKey DIMENSION_TYPE = create("dimension_type", RegistryCache::dimensions); public static final JavaRegistryKey ENCHANTMENT = create("enchantment", RegistryCache::enchantments); - public static final JavaRegistryKey JUKEBOX_SONG = create("jukebox_song", RegistryCache::jukeboxSongs); - public static final JavaRegistryKey PAINTING_VARIANT = create("painting_variant", RegistryCache::paintings); - public static final JavaRegistryKey TRIM_MATERIAL = create("trim_material", RegistryCache::trimMaterials); - public static final JavaRegistryKey TRIM_PATTERN = create("trim_pattern", RegistryCache::trimPatterns); - public static final JavaRegistryKey INSTRUMENT = create("instrument", RegistryCache::instruments); - /** - * This registry should not be used in holder sets, tags, etc. It's simply used as a mapping from Java biomes to Bedrock ones. - */ - public static final JavaRegistryKey BIOME = create("worldgen/biome"); - public static final JavaRegistryKey BANNER_PATTERN = create("banner_pattern", RegistryCache::bannerPatterns); - public static final JavaRegistryKey WOLF_VARIANT = create("wolf_variant", RegistryCache::wolfVariants); private static JavaRegistryKey create(String key, JavaRegistryKey.NetworkSerializer networkSerializer, JavaRegistryKey.NetworkDeserializer networkDeserializer) { JavaRegistryKey registry = new JavaRegistryKey<>(MinecraftKey.key(key), networkSerializer, networkDeserializer); @@ -85,11 +63,6 @@ public class JavaRegistries { return create(key, (session, object) -> getter.get(session.getRegistryCache()).byValue(object), (session, id) -> getter.get(session.getRegistryCache()).byId(id)); } - private static JavaRegistryKey create(String key) { - // Cast for ambiguous call - return create(key, (JavaRegistryKey.NetworkSerializer) null, null); - } - @Nullable public static JavaRegistryKey fromKey(Key registryKey) { for (JavaRegistryKey registry : VALUES) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a88862965..9031799cf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ jline = "3.21.0" terminalconsoleappender = "1.2.0" folia = "1.19.4-R0.1-SNAPSHOT" viaversion = "4.9.2" -adapters = "1.13-SNAPSHOT" +adapters = "1.14-SNAPSHOT" cloud = "2.0.0-rc.2" cloud-minecraft = "2.0.0-beta.9" cloud-minecraft-modded = "2.0.0-beta.7"