From 45f96a03e79b8227f8cd661ad08b423dda237042 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:56:41 -0400 Subject: [PATCH] Fix online mode no auth token dimension setting on login --- .../protocol/java/JavaLoginTranslator.java | 22 +++++++++++-------- .../geysermc/geyser/util/DimensionUtils.java | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java index 641313ee428..cf4b7058b0e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java @@ -26,28 +26,25 @@ package org.geysermc.geyser.translator.protocol.java; import net.kyori.adventure.key.Key; -import org.geysermc.erosion.Constants; -import org.geysermc.geyser.level.JavaDimension; -import org.geysermc.geyser.util.MinecraftKey; -import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo; -import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket; -import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.GameRuleData; -import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.packet.GameRulesChangedPacket; -import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket; +import org.geysermc.erosion.Constants; import org.geysermc.floodgate.pluginmessage.PluginMessageChannels; import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler; +import org.geysermc.geyser.level.JavaDimension; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.ChunkUtils; import org.geysermc.geyser.util.DimensionUtils; import org.geysermc.geyser.util.EntityUtils; +import org.geysermc.geyser.util.MinecraftKey; +import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo; +import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket; +import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -83,6 +80,13 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) { // Remove extra hearts, hunger, etc. entity.resetAttributes(); entity.resetMetadata(); + } else if (session.getUpstream().isInitialized()) { + if (newDimension.bedrockId() == 0) { + // A dimension switch will not happen, so make sure we initialized the dimension choice. + // Otherwise, the dimension switch will fill these values in. + session.setDimensionType(newDimension); + DimensionUtils.setBedrockDimension(session, newDimension.bedrockId()); + } } session.setWorldName(spawnInfo.getWorldName()); diff --git a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java index b1408b817a0..821358bd818 100644 --- a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.util; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; @@ -61,7 +62,7 @@ public static void switchDimension(GeyserSession session, JavaDimension javaDime } public static void switchDimension(GeyserSession session, JavaDimension javaDimension, int bedrockDimension) { - JavaDimension previousDimension = session.getDimensionType(); // previous java dimension + @Nullable JavaDimension previousDimension = session.getDimensionType(); // previous java dimension; can be null if an online player with no saved auth token logs in. Entity player = session.getPlayerEntity(); @@ -109,7 +110,7 @@ public static void switchDimension(GeyserSession session, JavaDimension javaDime if (isCustomBedrockNetherId()) { if (javaDimension.isNetherLike()) { session.camera().sendFog(BEDROCK_FOG_HELL); - } else if (previousDimension.isNetherLike()) { + } else if (previousDimension != null && previousDimension.isNetherLike()) { session.camera().removeFog(BEDROCK_FOG_HELL); } }