From f2ec8d5cee9e7d87f8a3b78f9fb82a183d749221 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Mon, 24 Mar 2025 06:51:30 +0000 Subject: [PATCH] Random stuff to make it run --- .../geyser/inventory/click/ClickPlan.java | 12 ++- .../DataComponentRegistryPopulator.java | 7 +- .../populator/ItemRegistryPopulator.java | 89 +++++++++++-------- .../geyser/session/GeyserSession.java | 4 +- ...BedrockInventoryTransactionTranslator.java | 9 +- gradle/libs.versions.toml | 2 +- 6 files changed, 76 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java index d4344f6e8..4d8af3882 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java @@ -41,6 +41,7 @@ import org.geysermc.geyser.util.thirdparty.Fraction; import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerActionType; import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType; import org.geysermc.mcprotocollib.protocol.data.game.inventory.MoveToHotbarAction; +import org.geysermc.mcprotocollib.protocol.data.game.item.HashedStack; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSelectBundleItemPacket; @@ -50,6 +51,8 @@ import org.jetbrains.annotations.Contract; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; +import java.util.Map; +import java.util.Set; public final class ClickPlan { private final List plan = new ArrayList<>(); @@ -157,8 +160,8 @@ public final class ClickPlan { action.slot, action.click.actionType, action.click.action, - clickedItemStack, - changedItems + hashStack(clickedItemStack), + new Int2ObjectOpenHashMap<>() // TODO fixme ); session.sendDownstreamGamePacket(clickPacket); @@ -514,4 +517,9 @@ public final class ClickPlan { private record ClickAction(Click click, int slot, boolean force) { } + + // TODO probably move this + public static HashedStack hashStack(ItemStack stack) { + return stack == null ? null : new HashedStack(stack.getId(), stack.getAmount(), Map.of(), Set.of()); // TODO this is WRONG. figure out stack hashing + } } 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 29d85cdd2..1a247f609 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 @@ -75,8 +75,13 @@ public final class DataComponentRegistryPopulator { byte[] bytes = Base64.getDecoder().decode(encodedValue); ByteBuf buf = Unpooled.wrappedBuffer(bytes); int varInt = MinecraftTypes.readVarInt(buf); - System.out.println("int: " + varInt + " " + componentEntry.getKey()); + //System.out.println("int: " + varInt + " " + componentEntry.getKey()); DataComponentType dataComponentType = DataComponentTypes.from(varInt); + if (dataComponentType == DataComponentTypes.ENCHANTMENTS + || dataComponentType == DataComponentTypes.STORED_ENCHANTMENTS + || dataComponentType == DataComponentTypes.JUKEBOX_PLAYABLE) { + continue; // TODO Broken reading in MCPL + } DataComponent dataComponent = dataComponentType.readDataComponent(buf); map.put(dataComponentType, dataComponent); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java index 0b8d7f982..6de62ceac 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java @@ -112,46 +112,61 @@ public class ItemRegistryPopulator { } public static void populate() { + // 1.21.5 Map itemFallbacks = new HashMap<>(); - itemFallbacks.put(Items.PALE_OAK_PLANKS, Items.BIRCH_PLANKS); - itemFallbacks.put(Items.PALE_OAK_FENCE, Items.BIRCH_FENCE); - itemFallbacks.put(Items.PALE_OAK_FENCE_GATE, Items.BIRCH_FENCE_GATE); - itemFallbacks.put(Items.PALE_OAK_STAIRS, Items.BIRCH_STAIRS); - itemFallbacks.put(Items.PALE_OAK_DOOR, Items.BIRCH_DOOR); - itemFallbacks.put(Items.PALE_OAK_TRAPDOOR, Items.BIRCH_TRAPDOOR); - itemFallbacks.put(Items.PALE_OAK_SLAB, Items.BIRCH_SLAB); - itemFallbacks.put(Items.PALE_OAK_LOG, Items.BIRCH_LOG); - itemFallbacks.put(Items.STRIPPED_PALE_OAK_LOG, Items.STRIPPED_BIRCH_LOG); - itemFallbacks.put(Items.PALE_OAK_WOOD, Items.BIRCH_WOOD); - itemFallbacks.put(Items.PALE_OAK_LEAVES, Items.BIRCH_LEAVES); - itemFallbacks.put(Items.PALE_OAK_SAPLING, Items.BIRCH_SAPLING); - itemFallbacks.put(Items.STRIPPED_PALE_OAK_WOOD, Items.STRIPPED_BIRCH_WOOD); - itemFallbacks.put(Items.PALE_OAK_SIGN, Items.BIRCH_SIGN); - itemFallbacks.put(Items.PALE_OAK_HANGING_SIGN, Items.BIRCH_HANGING_SIGN); - itemFallbacks.put(Items.PALE_OAK_BOAT, Items.BIRCH_BOAT); - itemFallbacks.put(Items.PALE_OAK_CHEST_BOAT, Items.BIRCH_CHEST_BOAT); - itemFallbacks.put(Items.PALE_OAK_BUTTON, Items.BIRCH_BUTTON); - itemFallbacks.put(Items.PALE_OAK_PRESSURE_PLATE, Items.BIRCH_PRESSURE_PLATE); - itemFallbacks.put(Items.RESIN_CLUMP, Items.RAW_COPPER); - itemFallbacks.put(Items.RESIN_BRICK_WALL, Items.RED_SANDSTONE_WALL); - itemFallbacks.put(Items.RESIN_BRICK_STAIRS, Items.RED_SANDSTONE_STAIRS); - itemFallbacks.put(Items.RESIN_BRICK_SLAB, Items.RED_SANDSTONE_SLAB); - itemFallbacks.put(Items.RESIN_BLOCK, Items.RED_SANDSTONE); - itemFallbacks.put(Items.RESIN_BRICK, Items.BRICK); - itemFallbacks.put(Items.RESIN_BRICKS, Items.CUT_RED_SANDSTONE); - itemFallbacks.put(Items.CHISELED_RESIN_BRICKS, Items.CHISELED_RED_SANDSTONE); - itemFallbacks.put(Items.CLOSED_EYEBLOSSOM, Items.WHITE_TULIP); - itemFallbacks.put(Items.OPEN_EYEBLOSSOM, Items.OXEYE_DAISY); - itemFallbacks.put(Items.PALE_MOSS_BLOCK, Items.MOSS_BLOCK); - itemFallbacks.put(Items.PALE_MOSS_CARPET, Items.MOSS_CARPET); - itemFallbacks.put(Items.PALE_HANGING_MOSS, Items.HANGING_ROOTS); - itemFallbacks.put(Items.CREAKING_HEART, Items.CHISELED_POLISHED_BLACKSTONE); - itemFallbacks.put(Items.CREAKING_SPAWN_EGG, Items.HOGLIN_SPAWN_EGG); + itemFallbacks.put(Items.BUSH, Items.SHORT_GRASS); + itemFallbacks.put(Items.CACTUS_FLOWER, Items.BUBBLE_CORAL_FAN); + itemFallbacks.put(Items.FIREFLY_BUSH, Items.SHORT_GRASS); + itemFallbacks.put(Items.LEAF_LITTER, Items.PINK_PETALS); + itemFallbacks.put(Items.SHORT_DRY_GRASS, Items.DEAD_BUSH); + itemFallbacks.put(Items.TALL_DRY_GRASS, Items.TALL_GRASS); + itemFallbacks.put(Items.WILDFLOWERS, Items.PINK_PETALS); + itemFallbacks.put(Items.TEST_BLOCK, Items.STRUCTURE_BLOCK); + itemFallbacks.put(Items.TEST_INSTANCE_BLOCK, Items.JIGSAW); + itemFallbacks.put(Items.BLUE_EGG, Items.EGG); + itemFallbacks.put(Items.BROWN_EGG, Items.EGG); + + // 1.21.4 + Map oneTwentyFourFallbacks = new HashMap<>(itemFallbacks); + oneTwentyFourFallbacks.put(Items.PALE_OAK_PLANKS, Items.BIRCH_PLANKS); + oneTwentyFourFallbacks.put(Items.PALE_OAK_FENCE, Items.BIRCH_FENCE); + oneTwentyFourFallbacks.put(Items.PALE_OAK_FENCE_GATE, Items.BIRCH_FENCE_GATE); + oneTwentyFourFallbacks.put(Items.PALE_OAK_STAIRS, Items.BIRCH_STAIRS); + oneTwentyFourFallbacks.put(Items.PALE_OAK_DOOR, Items.BIRCH_DOOR); + oneTwentyFourFallbacks.put(Items.PALE_OAK_TRAPDOOR, Items.BIRCH_TRAPDOOR); + oneTwentyFourFallbacks.put(Items.PALE_OAK_SLAB, Items.BIRCH_SLAB); + oneTwentyFourFallbacks.put(Items.PALE_OAK_LOG, Items.BIRCH_LOG); + oneTwentyFourFallbacks.put(Items.STRIPPED_PALE_OAK_LOG, Items.STRIPPED_BIRCH_LOG); + oneTwentyFourFallbacks.put(Items.PALE_OAK_WOOD, Items.BIRCH_WOOD); + oneTwentyFourFallbacks.put(Items.PALE_OAK_LEAVES, Items.BIRCH_LEAVES); + oneTwentyFourFallbacks.put(Items.PALE_OAK_SAPLING, Items.BIRCH_SAPLING); + oneTwentyFourFallbacks.put(Items.STRIPPED_PALE_OAK_WOOD, Items.STRIPPED_BIRCH_WOOD); + oneTwentyFourFallbacks.put(Items.PALE_OAK_SIGN, Items.BIRCH_SIGN); + oneTwentyFourFallbacks.put(Items.PALE_OAK_HANGING_SIGN, Items.BIRCH_HANGING_SIGN); + oneTwentyFourFallbacks.put(Items.PALE_OAK_BOAT, Items.BIRCH_BOAT); + oneTwentyFourFallbacks.put(Items.PALE_OAK_CHEST_BOAT, Items.BIRCH_CHEST_BOAT); + oneTwentyFourFallbacks.put(Items.PALE_OAK_BUTTON, Items.BIRCH_BUTTON); + oneTwentyFourFallbacks.put(Items.PALE_OAK_PRESSURE_PLATE, Items.BIRCH_PRESSURE_PLATE); + oneTwentyFourFallbacks.put(Items.RESIN_CLUMP, Items.RAW_COPPER); + oneTwentyFourFallbacks.put(Items.RESIN_BRICK_WALL, Items.RED_SANDSTONE_WALL); + oneTwentyFourFallbacks.put(Items.RESIN_BRICK_STAIRS, Items.RED_SANDSTONE_STAIRS); + oneTwentyFourFallbacks.put(Items.RESIN_BRICK_SLAB, Items.RED_SANDSTONE_SLAB); + oneTwentyFourFallbacks.put(Items.RESIN_BLOCK, Items.RED_SANDSTONE); + oneTwentyFourFallbacks.put(Items.RESIN_BRICK, Items.BRICK); + oneTwentyFourFallbacks.put(Items.RESIN_BRICKS, Items.CUT_RED_SANDSTONE); + oneTwentyFourFallbacks.put(Items.CHISELED_RESIN_BRICKS, Items.CHISELED_RED_SANDSTONE); + oneTwentyFourFallbacks.put(Items.CLOSED_EYEBLOSSOM, Items.WHITE_TULIP); + oneTwentyFourFallbacks.put(Items.OPEN_EYEBLOSSOM, Items.OXEYE_DAISY); + oneTwentyFourFallbacks.put(Items.PALE_MOSS_BLOCK, Items.MOSS_BLOCK); + oneTwentyFourFallbacks.put(Items.PALE_MOSS_CARPET, Items.MOSS_CARPET); + oneTwentyFourFallbacks.put(Items.PALE_HANGING_MOSS, Items.HANGING_ROOTS); + oneTwentyFourFallbacks.put(Items.CREAKING_HEART, Items.CHISELED_POLISHED_BLACKSTONE); + oneTwentyFourFallbacks.put(Items.CREAKING_SPAWN_EGG, Items.HOGLIN_SPAWN_EGG); List paletteVersions = new ArrayList<>(2); - paletteVersions.add(new PaletteVersion("1_21_40", Bedrock_v748.CODEC.getProtocolVersion(), itemFallbacks, (item, mapping) -> mapping)); - paletteVersions.add(new PaletteVersion("1_21_50", Bedrock_v766.CODEC.getProtocolVersion())); - paletteVersions.add(new PaletteVersion("1_21_60", Bedrock_v776.CODEC.getProtocolVersion())); + paletteVersions.add(new PaletteVersion("1_21_40", Bedrock_v748.CODEC.getProtocolVersion(), oneTwentyFourFallbacks, (item, mapping) -> mapping)); + paletteVersions.add(new PaletteVersion("1_21_50", Bedrock_v766.CODEC.getProtocolVersion(), itemFallbacks, (item, mapping) -> mapping)); + paletteVersions.add(new PaletteVersion("1_21_60", Bedrock_v776.CODEC.getProtocolVersion(), itemFallbacks, (item, mapping) -> mapping)); paletteVersions.add(new PaletteVersion("1_21_70", Bedrock_v786.CODEC.getProtocolVersion())); GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap(); diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index c1ca49af4..6ce811356 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1443,14 +1443,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { * Sends a chat message to the Java server. */ public void sendChat(String message) { - sendDownstreamGamePacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet(), 0)); } /** * Sends a command to the Java server. */ public void sendCommand(String command) { - sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatCommandSignedPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet(), (byte) 0)); } public void setClientRenderDistance(int clientRenderDistance) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index d3e2ba5df..404e213a7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -52,6 +52,7 @@ import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.PlayerInventory; import org.geysermc.geyser.inventory.click.Click; +import org.geysermc.geyser.inventory.click.ClickPlan; import org.geysermc.geyser.inventory.item.GeyserInstrument; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.BlockItem; @@ -84,7 +85,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction; -import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; +import org.geysermc.mcprotocollib.protocol.data.game.item.HashedStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.component.InstrumentComponent; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket; @@ -132,7 +133,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator changedItem; + Int2ObjectMap changedItem; if (dropAll) { inventory.setItem(hotbarSlot, GeyserItemStack.EMPTY, session); changedItem = Int2ObjectMaps.singleton(hotbarSlot, null); @@ -142,11 +143,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator