Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
Reset state when disconnected during handshaking
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Jul 15, 2022
1 parent 66d4686 commit 74c5b76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'

group = 'io.izzel.lightfall'
version = '1.0.2'
version = '1.0.3'
archivesBaseName = 'lightfallclient'

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ protected void init() {
this.addRenderableWidget(
new Button(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20, CommonComponents.GUI_CANCEL,
button -> {
this.networkManager.disconnect(new TranslatableComponent("connect.aborted"));
if (this.networkManager.isConnected()) {
this.networkManager.disconnect(new TranslatableComponent("connect.aborted"));
}
this.minecraft.setScreen(new JoinMultiplayerScreen(new TitleScreen()));
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.PacketListener;
import net.minecraft.network.chat.Component;
import net.minecraftforge.registries.GameData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientHandshakePacketListenerImpl.class)
public class ClientLoginNetHandlerMixin implements ClientLoginNetHandlerBridge {
Expand All @@ -30,4 +34,14 @@ public class ClientLoginNetHandlerMixin implements ClientLoginNetHandlerBridge {
}
return lightfall$reuse == null ? origin : lightfall$reuse;
}

@Inject(method = "onDisconnect", at = @At("HEAD"))
private void lightfall$resetState(Component p_104543_, CallbackInfo ci) {
if (lightfall$reuse != null && lightfall$reuse.getLevel() != null) {
this.minecraft.level = lightfall$reuse.getLevel();
this.minecraft.clearLevel();
} else {
GameData.revertToFrozen();
}
}
}

0 comments on commit 74c5b76

Please sign in to comment.