From 064ff31830f3060a6ba5815146591753dc835ac9 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 31 Oct 2024 09:33:22 +0000 Subject: [PATCH] Don't reset client pocket state when changing level As part of the multi-loader work, we unified some of our event listening code (0908acbe9bbb63d9c1be513d098e9a14d5bb68e3). This incorrectly caused client pocket computer state to be reset when the player changes dimension, rather than when the player (dis)connects. The server code isn't aware of this behaviour, and so does not resend pocket computer state when the player moves level. We could change this, but just fixing when we clear the pocket computer state is a much nicer fix! Fixes #2004 --- .../client/java/dan200/computercraft/client/ClientHooks.java | 3 +++ .../dan200/computercraft/mixin/client/MinecraftMixin.java | 1 + .../java/dan200/computercraft/client/ForgeClientHooks.java | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/projects/common/src/client/java/dan200/computercraft/client/ClientHooks.java b/projects/common/src/client/java/dan200/computercraft/client/ClientHooks.java index 36b331939..3ecd0bdc6 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/ClientHooks.java +++ b/projects/common/src/client/java/dan200/computercraft/client/ClientHooks.java @@ -64,6 +64,9 @@ public final class ClientHooks { public static void onWorldUnload() { MonitorRenderState.destroyAll(); SpeakerManager.reset(); + } + + public static void onDisconnect() { ClientPocketComputers.reset(); } diff --git a/projects/fabric/src/client/java/dan200/computercraft/mixin/client/MinecraftMixin.java b/projects/fabric/src/client/java/dan200/computercraft/mixin/client/MinecraftMixin.java index 23244e8b9..e413c3a40 100644 --- a/projects/fabric/src/client/java/dan200/computercraft/mixin/client/MinecraftMixin.java +++ b/projects/fabric/src/client/java/dan200/computercraft/mixin/client/MinecraftMixin.java @@ -28,6 +28,7 @@ class MinecraftMixin { @SuppressWarnings("unused") private void clearLevel(Screen screen, CallbackInfo ci) { ClientHooks.onWorldUnload(); + ClientHooks.onDisconnect(); } @Inject(method = "setLevel", at = @At("HEAD")) diff --git a/projects/forge/src/client/java/dan200/computercraft/client/ForgeClientHooks.java b/projects/forge/src/client/java/dan200/computercraft/client/ForgeClientHooks.java index ea97bf120..7aa52b03a 100644 --- a/projects/forge/src/client/java/dan200/computercraft/client/ForgeClientHooks.java +++ b/projects/forge/src/client/java/dan200/computercraft/client/ForgeClientHooks.java @@ -38,6 +38,10 @@ public final class ForgeClientHooks { if (event.getLevel().isClientSide()) ClientHooks.onWorldUnload(); } + @SubscribeEvent + public static void onDisconnect(ClientPlayerNetworkEvent.LoggingOut event) { + ClientHooks.onDisconnect(); + } @SubscribeEvent public static void drawHighlight(RenderHighlightEvent.Block event) {