From 5836dabcdaa8945762d690f7e2784895959060dd Mon Sep 17 00:00:00 2001 From: Alex <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:11:09 +0100 Subject: [PATCH] Use mcpl staticify PR (#5284) * Use mcpl staticify PR * Fix missing generic arg * Update libs.versions.toml --- .../org/geysermc/geyser/level/WorldManager.java | 5 ++--- .../registry/loader/RecipeRegistryLoader.java | 16 ++++++++-------- .../DataComponentRegistryPopulator.java | 8 +++----- .../geyser/session/DownstreamSession.java | 10 ---------- .../level/JavaLevelChunkWithLightTranslator.java | 3 ++- .../scoreboard/network/ScoreboardIssueTests.java | 2 +- gradle/libs.versions.toml | 2 +- 7 files changed, 17 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/level/WorldManager.java b/core/src/main/java/org/geysermc/geyser/level/WorldManager.java index a85462108b6..c33fc766527 100644 --- a/core/src/main/java/org/geysermc/geyser/level/WorldManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/WorldManager.java @@ -39,7 +39,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; -import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper; import org.geysermc.mcprotocollib.protocol.data.game.setting.Difficulty; import java.util.HashMap; @@ -203,9 +202,9 @@ public void getDecoratedPotData(GeyserSession session, Vector3i pos, Consumer
  • , DataComponent> components = new HashMap<>(); Int2ObjectMaps.fastForEach(map, entry -> { - DataComponentType type = DataComponentType.from(entry.getIntKey()); + DataComponentType type = DataComponentType.from(entry.getIntKey()); ByteBuf buf = Unpooled.wrappedBuffer(entry.getValue()); - DataComponent value = type.readDataComponent(ItemCodecHelper.INSTANCE, buf); + DataComponent value = type.readDataComponent(buf); components.put(type, value); }); return new DataComponents(components); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/RecipeRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/RecipeRegistryLoader.java index 4cbd2ea47cb..74c36c00a63 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/RecipeRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/RecipeRegistryLoader.java @@ -31,7 +31,7 @@ import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtType; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; -import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; +import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; @@ -81,10 +81,10 @@ public abstract class RecipeRegistryLoader implements RegistryLoader getShapelessRecipes(List recipes, MinecraftCodecHelper helper) { + private static List getShapelessRecipes(List recipes) { List deserializedRecipes = new ObjectArrayList<>(recipes.size()); for (NbtMap recipe : recipes) { - ItemStack output = toItemStack(recipe.getCompound("output"), helper); + ItemStack output = toItemStack(recipe.getCompound("output")); List rawInputs = recipe.getList("inputs", NbtType.COMPOUND); Ingredient[] javaInputs = new Ingredient[rawInputs.size()]; for (int i = 0; i < rawInputs.size(); i++) { @@ -95,16 +95,16 @@ private static List getShapelessRecipes(List recipes, Mine return deserializedRecipes; } - private static List getShapedRecipes(List recipes, MinecraftCodecHelper helper) { + private static List getShapedRecipes(List recipes) { List deserializedRecipes = new ObjectArrayList<>(recipes.size()); for (NbtMap recipe : recipes) { - ItemStack output = toItemStack(recipe.getCompound("output"), helper); + ItemStack output = toItemStack(recipe.getCompound("output")); List shape = recipe.getList("shape", NbtType.INT_ARRAY); // In the recipes mapping, each recipe is mapped by a number List letterToRecipe = new ArrayList<>(); for (NbtMap rawInput : recipe.getList("inputs", NbtType.COMPOUND)) { - letterToRecipe.add(toItemStack(rawInput, helper)); + letterToRecipe.add(toItemStack(rawInput)); } Ingredient[] inputs = new Ingredient[shape.size() * shape.get(0).length]; @@ -126,14 +126,14 @@ private static List getShapedRecipes(List recipes, Minecra * id is the Java item ID as an integer, components is an optional String of the data components serialized * as bytes in Base64 (so MCProtocolLib can parse the data). */ - private static ItemStack toItemStack(NbtMap nbt, MinecraftCodecHelper helper) { + private static ItemStack toItemStack(NbtMap nbt) { int id = nbt.getInt("id"); int count = nbt.getInt("count", 1); String componentsRaw = nbt.getString("components", null); if (componentsRaw != null) { byte[] bytes = Base64.getDecoder().decode(componentsRaw); ByteBuf buf = Unpooled.wrappedBuffer(bytes); - DataComponents components = helper.readDataComponentPatch(buf); + DataComponents components = MinecraftTypes.readDataComponentPatch(buf); return new ItemStack(id, count, components); } return new ItemStack(id, count); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/DataComponentRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/DataComponentRegistryPopulator.java index d8547bbfc11..742564a390e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/DataComponentRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/DataComponentRegistryPopulator.java @@ -36,11 +36,10 @@ import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.registry.Registries; -import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; +import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; -import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper; import java.io.InputStream; import java.io.InputStreamReader; @@ -71,10 +70,9 @@ public static void populate() { String encodedValue = componentEntry.getValue().getAsString(); byte[] bytes = Base64.getDecoder().decode(encodedValue); ByteBuf buf = Unpooled.wrappedBuffer(bytes); - MinecraftCodecHelper helper = new MinecraftCodecHelper(); - int varInt = helper.readVarInt(buf); + int varInt = MinecraftTypes.readVarInt(buf); DataComponentType dataComponentType = DataComponentType.from(varInt); - DataComponent dataComponent = dataComponentType.readDataComponent(ItemCodecHelper.INSTANCE, buf); + DataComponent dataComponent = dataComponentType.readDataComponent(buf); map.put(dataComponentType, dataComponent); } diff --git a/core/src/main/java/org/geysermc/geyser/session/DownstreamSession.java b/core/src/main/java/org/geysermc/geyser/session/DownstreamSession.java index 22827ccfacc..a55f84ab23f 100644 --- a/core/src/main/java/org/geysermc/geyser/session/DownstreamSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/DownstreamSession.java @@ -31,7 +31,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.mcprotocollib.network.ClientSession; import org.geysermc.mcprotocollib.network.packet.Packet; -import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; @Getter @RequiredArgsConstructor @@ -53,13 +52,4 @@ public void disconnect(Component reason, Throwable throwable) { public boolean isClosed() { return !this.session.isConnected(); } - - /** - * Gets the codec helper for this session. - * - * @return the codec helper for this session - */ - public MinecraftCodecHelper getCodecHelper() { - return (MinecraftCodecHelper) this.session.getCodecHelper(); - } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java index af3c8595e21..f4b74be0275 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java @@ -61,6 +61,7 @@ import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.BlockEntityUtils; import org.geysermc.geyser.util.ChunkUtils; +import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes; import org.geysermc.mcprotocollib.protocol.data.game.chunk.BitStorage; import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkSection; import org.geysermc.mcprotocollib.protocol.data.game.chunk.DataPalette; @@ -115,7 +116,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData()); boolean extendedCollisionNextSection = false; for (int sectionY = 0; sectionY < chunkSize; sectionY++) { - ChunkSection javaSection = session.getDownstream().getCodecHelper().readChunkSection(in); + ChunkSection javaSection = MinecraftTypes.readChunkSection(in); javaChunks[sectionY] = javaSection.getChunkData(); javaBiomes[sectionY] = javaSection.getBiomeData(); boolean extendedCollision = extendedCollisionNextSection; diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java index 0b3d2c5e7cb..e01ea7cd36c 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java @@ -212,7 +212,7 @@ void nameNotUpdating() { }); // metadata set: invisible, custom name, custom name visible - context.translate(setEntityDataTranslator, new ClientboundSetEntityDataPacket(1298, new EntityMetadata[]{ + context.translate(setEntityDataTranslator, new ClientboundSetEntityDataPacket(1298, new EntityMetadata[]{ new ByteEntityMetadata(0, MetadataType.BYTE, (byte) 0x20), new ObjectEntityMetadata<>(2, MetadataType.OPTIONAL_CHAT, Optional.of(Component.text("tesss"))), new BooleanEntityMetadata(3, MetadataType.BOOLEAN, true) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e5e8a3faa46..f74de4de0ff 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ protocol-common = "3.0.0.Beta5-20241213.160944-20" protocol-codec = "3.0.0.Beta5-20241213.160944-20" raknet = "1.0.0.CR3-20240416.144209-1" minecraftauth = "4.1.1" -mcprotocollib = "1.21.4-20250118.154631-17" +mcprotocollib = "1.21.4-20250121.131208-18" adventure = "4.14.0" adventure-platform = "4.3.0" junit = "5.9.2"