From 8c7a3d1822c3a926e395e3919836dad33503919b Mon Sep 17 00:00:00 2001 From: Luke <32024335+lukeeey@users.noreply.github.com> Date: Wed, 8 Dec 2021 18:23:05 +0000 Subject: [PATCH] Show the nether fog when using the nether height workaround (#2663) --- .../geyser/session/GeyserSession.java | 38 ++++++++++++++++++- .../geyser/session/cache/WorldBorder.java | 17 --------- .../protocol/java/JavaLoginTranslator.java | 3 ++ .../geysermc/geyser/util/DimensionUtils.java | 17 +++++++++ core/src/main/resources/config.yml | 7 ++-- 5 files changed, 59 insertions(+), 23 deletions(-) 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 a58d57503..2e3368356 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -461,6 +461,8 @@ public class GeyserSession implements GeyserConnection, CommandSender { @Setter private boolean waitingForStatistics = false; + private final Set fogNameSpaces = new HashSet<>(); + private final Set emotes; /** @@ -1006,11 +1008,11 @@ public class GeyserSession implements GeyserConnection, CommandSender { // Set the mood if (!isInWorldBorderWarningArea) { isInWorldBorderWarningArea = true; - WorldBorder.sendFog(this, "minecraft:fog_crimson_forest"); + sendFog("minecraft:fog_crimson_forest"); } } else if (isInWorldBorderWarningArea) { // Clear fog as we are outside the world border now - WorldBorder.removeFog(this); + removeFog("minecraft:fog_crimson_forest"); isInWorldBorderWarningArea = false; } @@ -1490,4 +1492,36 @@ public class GeyserSession implements GeyserConnection, CommandSender { player.sendUpstreamPacket(emoteList); } } + + /** + * Send the following fog IDs, as well as the cached ones, to the client. + * + * Fog IDs can be found here: + * https://wiki.bedrock.dev/documentation/fog-ids.html + * + * @param fogNameSpaces the fog ids to add + */ + public void sendFog(String... fogNameSpaces) { + this.fogNameSpaces.addAll(Arrays.asList(fogNameSpaces)); + + PlayerFogPacket packet = new PlayerFogPacket(); + packet.getFogStack().addAll(this.fogNameSpaces); + sendUpstreamPacket(packet); + } + + /** + * Removes the following fog IDs from the client and the cache. + * + * @param fogNameSpaces the fog ids to remove + */ + public void removeFog(String... fogNameSpaces) { + if (fogNameSpaces.length == 0) { + this.fogNameSpaces.clear(); + } else { + this.fogNameSpaces.removeAll(Arrays.asList(fogNameSpaces)); + } + PlayerFogPacket packet = new PlayerFogPacket(); + packet.getFogStack().addAll(this.fogNameSpaces); + sendUpstreamPacket(packet); + } } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 5c486af49..01c5949c7 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -296,21 +296,4 @@ public class WorldBorder { effectPacket.setType(WORLD_BORDER_PARTICLE); session.getUpstream().sendPacket(effectPacket); } - - /** - * Send the following fog IDs to the client - */ - public static void sendFog(GeyserSession session, String... fogNameSpaces) { - PlayerFogPacket packet = new PlayerFogPacket(); - Collections.addAll(packet.getFogStack(), fogNameSpaces); - session.sendUpstreamPacket(packet); - } - - /** - * Clear any additional fog sent to the client - */ - public static void removeFog(GeyserSession session) { - session.sendUpstreamPacket(new PlayerFogPacket()); - } - } 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 855f5b144..76a867e30 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 @@ -116,6 +116,9 @@ public class JavaLoginTranslator extends PacketTranslator