From 6f0eba89bdfff88293eaa20ae8a693571f7d917b Mon Sep 17 00:00:00 2001 From: Aeltumn Date: Sun, 28 Jul 2024 17:09:39 +0200 Subject: [PATCH] Don't trigger reconnection when being transferred --- gradle.properties | 2 +- src/main/java/autoreconnect/AutoReconnect.java | 8 ++++++++ .../mixin/ClientCommonPacketListenerImplExt.java | 12 ++++++++++++ src/main/resources/autoreconnect.mixins.json | 3 ++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/main/java/autoreconnect/mixin/ClientCommonPacketListenerImplExt.java diff --git a/gradle.properties b/gradle.properties index c2efb14..50386e7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ fabric_version=0.100.1+1.21 # Mod Properties mod_id=autoreconnect mod_name=AutoReconnect -mod_version=1.21-2.3.0 +mod_version=1.21-2.4.0 maven_group=autoreconnect archives_base_name=autoreconnect diff --git a/src/main/java/autoreconnect/AutoReconnect.java b/src/main/java/autoreconnect/AutoReconnect.java index 04a317d..1c06945 100644 --- a/src/main/java/autoreconnect/AutoReconnect.java +++ b/src/main/java/autoreconnect/AutoReconnect.java @@ -1,6 +1,7 @@ package autoreconnect; import autoreconnect.config.AutoReconnectConfig; +import autoreconnect.mixin.ClientCommonPacketListenerImplExt; import autoreconnect.reconnect.ReconnectStrategy; import autoreconnect.reconnect.SingleplayerReconnectStrategy; import com.mojang.logging.LogUtils; @@ -14,6 +15,7 @@ import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; +import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.world.entity.player.Player; @@ -71,6 +73,12 @@ public void reconnect() { } public void startCountdown(final IntConsumer callback) { + // don't reconnect when being transferred + var packetListener = Minecraft.getInstance().getConnection().getConnection().getPacketListener(); + if (packetListener instanceof ClientCommonPacketListenerImpl) { + if (((ClientCommonPacketListenerImplExt) packetListener).autoreconnect$isTransferring()) return; + } + // if (countdown.get() != null) return; // should not happen if (reconnectStrategy == null) { // TODO fix issue appropriately, logging error for now diff --git a/src/main/java/autoreconnect/mixin/ClientCommonPacketListenerImplExt.java b/src/main/java/autoreconnect/mixin/ClientCommonPacketListenerImplExt.java new file mode 100644 index 0000000..909ca57 --- /dev/null +++ b/src/main/java/autoreconnect/mixin/ClientCommonPacketListenerImplExt.java @@ -0,0 +1,12 @@ +package autoreconnect.mixin; + +import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ClientCommonPacketListenerImpl.class) +public interface ClientCommonPacketListenerImplExt { + + @Accessor("isTransferring") + public boolean autoreconnect$isTransferring(); +} diff --git a/src/main/resources/autoreconnect.mixins.json b/src/main/resources/autoreconnect.mixins.json index 59aa695..6e66cf2 100644 --- a/src/main/resources/autoreconnect.mixins.json +++ b/src/main/resources/autoreconnect.mixins.json @@ -5,10 +5,11 @@ "compatibilityLevel": "JAVA_17", "mixins": [], "client": [ + "ClientCommonPacketListenerImplExt", "ClientPacketListenerMixin", "ConnectScreenMixin", - "DisconnectedScreenMixin", "DisconnectedRealmsScreenMixin", + "DisconnectedScreenMixin", "MinecraftMixin", "RealmsConnectMixin" ],