Skip to content

Commit

Permalink
Don't trigger reconnection when being transferred
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Jul 28, 2024
1 parent 44f29fb commit 6f0eba8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/autoreconnect/AutoReconnect.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
3 changes: 2 additions & 1 deletion src/main/resources/autoreconnect.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"compatibilityLevel": "JAVA_17",
"mixins": [],
"client": [
"ClientCommonPacketListenerImplExt",
"ClientPacketListenerMixin",
"ConnectScreenMixin",
"DisconnectedScreenMixin",
"DisconnectedRealmsScreenMixin",
"DisconnectedScreenMixin",
"MinecraftMixin",
"RealmsConnectMixin"
],
Expand Down

0 comments on commit 6f0eba8

Please sign in to comment.