From 79e989092349505d4a3c7cfc1a078b29bb3b2171 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:03:29 -0400 Subject: [PATCH 1/6] Fix smithing tables not opening --- .../geyser/translator/inventory/InventoryTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java index e6cc010f5..8fe6597c6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java @@ -88,7 +88,7 @@ public abstract class InventoryTranslator { put(ContainerType.LOOM, new LoomInventoryTranslator()); put(ContainerType.MERCHANT, new MerchantInventoryTranslator()); put(ContainerType.SHULKER_BOX, new ShulkerInventoryTranslator()); - put(ContainerType.SMITHING, new SmithingInventoryTranslator()); + put(ContainerType.LEGACY_SMITHING, new SmithingInventoryTranslator()); put(ContainerType.STONECUTTER, new StonecutterInventoryTranslator()); /* Lectern */ From d7c68659122fd27a68081e70e1142550e115f5c2 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:36:00 -0400 Subject: [PATCH 2/6] Fix #3607 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3fef94519..ddd3c38bf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ websocket = "1.5.1" protocol = "2.9.17-20230217.002312-1" raknet = "1.6.28-20220125.214016-6" mcauthlib = "d9d773e" -mcprotocollib = "1.19.4-20230314.173921-2" +mcprotocollib = "1.19.4-20230315.153350-3" adventure = "4.12.0-20220629.025215-9" adventure-platform = "4.1.2" junit = "5.9.2" From acb25b0c99ad5cf638dad3e168116c00d9930a9e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 17 Mar 2023 13:41:01 -0400 Subject: [PATCH 3/6] Remove legacy 1.19.2x Bedrock code --- .../geysermc/geyser/network/GameProtocol.java | 4 -- .../BedrockAdventureSettingsTranslator.java | 42 ------------------- .../BedrockRequestAbilityTranslator.java | 38 +++++++---------- .../java/JavaKeepAliveTranslator.java | 5 +++ .../protocol/java/JavaLoginTranslator.java | 7 ---- 5 files changed, 19 insertions(+), 77 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAdventureSettingsTranslator.java diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 16f4abd04..083bc5b58 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -96,10 +96,6 @@ public final class GameProtocol { /* Bedrock convenience methods to gatekeep features and easily remove the check on version removal */ - public static boolean supports1_19_30(GeyserSession session) { - return session.getUpstream().getProtocolVersion() >= Bedrock_v554.V554_CODEC.getProtocolVersion(); - } - public static boolean supports1_19_50(GeyserSession session) { return session.getUpstream().getProtocolVersion() >= Bedrock_v560.V560_CODEC.getProtocolVersion(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAdventureSettingsTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAdventureSettingsTranslator.java deleted file mode 100644 index aabc39e12..000000000 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAdventureSettingsTranslator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.translator.protocol.bedrock; - -import com.nukkitx.protocol.bedrock.data.AdventureSetting; -import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; -import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.translator.protocol.PacketTranslator; -import org.geysermc.geyser.translator.protocol.Translator; - -@Translator(packet = AdventureSettingsPacket.class) -public class BedrockAdventureSettingsTranslator extends PacketTranslator { - - @Override - public void translate(GeyserSession session, AdventureSettingsPacket packet) { - boolean isFlying = packet.getSettings().contains(AdventureSetting.FLYING); - BedrockRequestAbilityTranslator.handle(session, isFlying); - } -} diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java index fe8150d40..bf268fd0e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockRequestAbilityTranslator.java @@ -30,7 +30,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.Server import com.nukkitx.protocol.bedrock.data.Ability; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.packet.RequestAbilityPacket; -import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; @@ -43,31 +42,22 @@ public class BedrockRequestAbilityTranslator extends PacketTranslator Date: Fri, 17 Mar 2023 13:41:13 -0400 Subject: [PATCH 4/6] Fix player nametags always appearing --- .../org/geysermc/geyser/scoreboard/Team.java | 17 ++++++++--------- gradle/libs.versions.toml | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java index b2e9043b5..e985ca803 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java @@ -33,9 +33,9 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.HashSet; -import java.util.Objects; import java.util.Set; @Getter @@ -46,7 +46,7 @@ public final class Team { @Getter(AccessLevel.PACKAGE) private final Set entities; - @Setter @Nullable private NameTagVisibility nameTagVisibility; + @Nonnull private NameTagVisibility nameTagVisibility = NameTagVisibility.ALWAYS; @Setter private TeamColor color; private final TeamData currentData; @@ -189,11 +189,6 @@ public final class Team { } public boolean isVisibleFor(String entity) { - if (nameTagVisibility == null) { - // Null - normal behavior - return true; - } - return switch (nameTagVisibility) { case HIDE_FOR_OTHER_TEAMS -> { // Player must be in a team in order for HIDE_FOR_OTHER_TEAMS to be triggered @@ -206,8 +201,12 @@ public final class Team { }; } - public NameTagVisibility getNameTagVisibility() { - return Objects.requireNonNullElse(this.nameTagVisibility, NameTagVisibility.ALWAYS); + public Team setNameTagVisibility(@Nullable NameTagVisibility nameTagVisibility) { + if (nameTagVisibility != null) { + // Null check like this (and this.nameTagVisibility defaults to ALWAYS) as of Java 1.19.4 + this.nameTagVisibility = nameTagVisibility; + } + return this; } @Override diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ddd3c38bf..7e8ddb2ad 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ websocket = "1.5.1" protocol = "2.9.17-20230217.002312-1" raknet = "1.6.28-20220125.214016-6" mcauthlib = "d9d773e" -mcprotocollib = "1.19.4-20230315.153350-3" +mcprotocollib = "1.19.4-20230317.173631-4" adventure = "4.12.0-20220629.025215-9" adventure-platform = "4.1.2" junit = "5.9.2" From 9609686eb34960937fe514d06d467ffd7fc57bcc Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 17 Mar 2023 19:07:31 -0400 Subject: [PATCH 5/6] Version out potion registry The ID of (for example) redstone dust has shifted, meaning that our hack of re-using IDs no longer works. Fixes #3620 --- .../geysermc/geyser/registry/Registries.java | 4 +- .../loader/PotionMixRegistryLoader.java | 101 ++++++++++-------- .../geyser/session/GeyserSession.java | 2 +- .../java/JavaUpdateRecipesTranslator.java | 2 +- 4 files changed, 59 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 866cbd291..b4afd7d2f 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -135,7 +135,7 @@ public final class Registries { /** * A registry holding all the potion mixes. */ - public static final SimpleRegistry> POTION_MIXES; + public static final VersionedRegistry> POTION_MIXES; /** * A registry holding all the @@ -178,7 +178,7 @@ public final class Registries { RecipeRegistryPopulator.populate(); // Create registries that require other registries to load first - POTION_MIXES = SimpleRegistry.create(PotionMixRegistryLoader::new); + POTION_MIXES = VersionedRegistry.create(PotionMixRegistryLoader::new); ENCHANTMENTS = SimpleMappedRegistry.create("mappings/enchantments.json", EnchantmentRegistryLoader::new); // Remove unneeded client generation data from NbtMapBuilder diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java index 8d40edac3..694aeba9c 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java @@ -26,17 +26,18 @@ package org.geysermc.geyser.registry.loader; import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.geysermc.geyser.inventory.item.Potion; -import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.registry.type.ItemMapping; +import org.geysermc.geyser.registry.type.ItemMappings; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -//TODO this needs to be versioned, but the runtime item states between 1.17 and 1.17.10 are identical except for new blocks so this works for both /** * Generates a collection of {@link PotionMixData} that enables the * Bedrock client to place brewing items into the brewing stand. @@ -46,64 +47,72 @@ import java.util.Set; * (Ex: Bedrock cannot normally place glass bottles or fully upgraded * potions into the brewing stand, but Java can.) */ -public class PotionMixRegistryLoader implements RegistryLoader> { +public class PotionMixRegistryLoader implements RegistryLoader>> { @Override - public Set load(Object input) { - List ingredients = new ArrayList<>(); - ingredients.add(getNonNull("minecraft:nether_wart")); - ingredients.add(getNonNull("minecraft:redstone")); - ingredients.add(getNonNull("minecraft:glowstone_dust")); - ingredients.add(getNonNull("minecraft:fermented_spider_eye")); - ingredients.add(getNonNull("minecraft:gunpowder")); - ingredients.add(getNonNull("minecraft:dragon_breath")); - ingredients.add(getNonNull("minecraft:sugar")); - ingredients.add(getNonNull("minecraft:rabbit_foot")); - ingredients.add(getNonNull("minecraft:glistering_melon_slice")); - ingredients.add(getNonNull("minecraft:spider_eye")); - ingredients.add(getNonNull("minecraft:pufferfish")); - ingredients.add(getNonNull("minecraft:magma_cream")); - ingredients.add(getNonNull("minecraft:golden_carrot")); - ingredients.add(getNonNull("minecraft:blaze_powder")); - ingredients.add(getNonNull("minecraft:ghast_tear")); - ingredients.add(getNonNull("minecraft:turtle_helmet")); - ingredients.add(getNonNull("minecraft:phantom_membrane")); + public Int2ObjectMap> load(Object input) { + var allPotionMixes = new Int2ObjectOpenHashMap>(Registries.ITEMS.get().size()); + for (var entry : Registries.ITEMS.get().int2ObjectEntrySet()) { + ItemMappings mappings = entry.getValue(); + List ingredients = new ArrayList<>(); + ingredients.add(getNonNull(mappings, "minecraft:nether_wart")); + ingredients.add(getNonNull(mappings, "minecraft:redstone")); + ingredients.add(getNonNull(mappings, "minecraft:glowstone_dust")); + ingredients.add(getNonNull(mappings, "minecraft:fermented_spider_eye")); + ingredients.add(getNonNull(mappings, "minecraft:gunpowder")); + ingredients.add(getNonNull(mappings, "minecraft:dragon_breath")); + ingredients.add(getNonNull(mappings, "minecraft:sugar")); + ingredients.add(getNonNull(mappings, "minecraft:rabbit_foot")); + ingredients.add(getNonNull(mappings, "minecraft:glistering_melon_slice")); + ingredients.add(getNonNull(mappings, "minecraft:spider_eye")); + ingredients.add(getNonNull(mappings, "minecraft:pufferfish")); + ingredients.add(getNonNull(mappings, "minecraft:magma_cream")); + ingredients.add(getNonNull(mappings, "minecraft:golden_carrot")); + ingredients.add(getNonNull(mappings, "minecraft:blaze_powder")); + ingredients.add(getNonNull(mappings, "minecraft:ghast_tear")); + ingredients.add(getNonNull(mappings, "minecraft:turtle_helmet")); + ingredients.add(getNonNull(mappings, "minecraft:phantom_membrane")); - List inputs = new ArrayList<>(); - inputs.add(getNonNull("minecraft:potion")); - inputs.add(getNonNull("minecraft:splash_potion")); - inputs.add(getNonNull("minecraft:lingering_potion")); + List inputs = List.of( + getNonNull(mappings, "minecraft:potion"), + getNonNull(mappings, "minecraft:splash_potion"), + getNonNull(mappings, "minecraft:lingering_potion") + ); - ItemMapping glassBottle = getNonNull("minecraft:glass_bottle"); + ItemMapping glassBottle = getNonNull(mappings, "minecraft:glass_bottle"); - Set potionMixes = new HashSet<>(); + Set potionMixes = new HashSet<>(); - // Add all types of potions as inputs - ItemMapping fillerIngredient = ingredients.get(0); - for (ItemMapping entryInput : inputs) { - for (Potion potion : Potion.values()) { + // Add all types of potions as inputs + ItemMapping fillerIngredient = ingredients.get(0); + for (ItemMapping entryInput : inputs) { + for (Potion potion : Potion.VALUES) { + potionMixes.add(new PotionMixData( + entryInput.getBedrockId(), potion.getBedrockId(), + fillerIngredient.getBedrockId(), fillerIngredient.getBedrockData(), + glassBottle.getBedrockId(), glassBottle.getBedrockData()) + ); + } + } + + // Add all brewing ingredients + // Also adds glass bottle as input + for (ItemMapping ingredient : ingredients) { potionMixes.add(new PotionMixData( - entryInput.getBedrockId(), potion.getBedrockId(), - fillerIngredient.getBedrockId(), fillerIngredient.getBedrockData(), + glassBottle.getBedrockId(), glassBottle.getBedrockData(), + ingredient.getBedrockId(), ingredient.getBedrockData(), glassBottle.getBedrockId(), glassBottle.getBedrockData()) ); } - } - // Add all brewing ingredients - // Also adds glass bottle as input - for (ItemMapping ingredient : ingredients) { - potionMixes.add(new PotionMixData( - glassBottle.getBedrockId(), glassBottle.getBedrockData(), - ingredient.getBedrockId(), ingredient.getBedrockData(), - glassBottle.getBedrockId(), glassBottle.getBedrockData()) - ); + allPotionMixes.put(entry.getIntKey(), potionMixes); } - return potionMixes; + allPotionMixes.trim(); + return allPotionMixes; } - private static ItemMapping getNonNull(String javaIdentifier) { - ItemMapping itemMapping = Registries.ITEMS.forVersion(GameProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()).getMapping(javaIdentifier); + private static ItemMapping getNonNull(ItemMappings mappings, String javaIdentifier) { + ItemMapping itemMapping = mappings.getMapping(javaIdentifier); if (itemMapping == null) throw new NullPointerException("No item entry exists for java identifier: " + javaIdentifier); 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 9b7d334fc..fa0db15f2 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -640,7 +640,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { // Potion mixes are registered by default, as they are needed to be able to put ingredients into the brewing stand. CraftingDataPacket craftingDataPacket = new CraftingDataPacket(); craftingDataPacket.setCleanRecipes(true); - craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.get()); + craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.forVersion(this.upstream.getProtocolVersion())); upstream.sendPacket(craftingDataPacket); PlayStatusPacket playStatusPacket = new PlayStatusPacket(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java index 9923c0a16..e665d5424 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java @@ -167,7 +167,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator stonecutterRecipeMap = new Int2ObjectOpenHashMap<>(); for (Int2ObjectMap.Entry> data : unsortedStonecutterData.int2ObjectEntrySet()) { From a330c9a5db69d12a2df3ac351ac69c8ae6367a3d Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sat, 18 Mar 2023 17:40:51 -0400 Subject: [PATCH 6/6] Fix lecterns Huge thanks to Dylan from PocketMine for the idea here. Fixes #3138 --- .../main/java/org/geysermc/geyser/session/GeyserSession.java | 2 ++ 1 file changed, 2 insertions(+) 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 fa0db15f2..d76cc4b97 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1688,6 +1688,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { abilities.add(Ability.MINE); // Needed so you can drop items abilities.add(Ability.DOORS_AND_SWITCHES); + // Required for lecterns to work (likely started around 1.19.10; confirmed on 1.19.70) + abilities.add(Ability.OPEN_CONTAINERS); if (gameMode == GameMode.CREATIVE) { // Needed so the client doesn't attempt to take away items abilities.add(Ability.INSTABUILD);