From 1ec4368ae134ee2f9b0c89840547775862c004a9 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Fri, 21 Jun 2024 11:57:56 -0500 Subject: [PATCH] Fix mixin error --- .../worldhost/mixin/DisconnectedScreenAccessor.java | 13 +++++++++++-- .../worldhost/testing/WorldHostTesting.java | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/DisconnectedScreenAccessor.java b/src/main/java/io/github/gaming32/worldhost/mixin/DisconnectedScreenAccessor.java index e8269070..51e0d5c2 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/DisconnectedScreenAccessor.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/DisconnectedScreenAccessor.java @@ -1,12 +1,21 @@ package io.github.gaming32.worldhost.mixin; import net.minecraft.client.gui.screens.DisconnectedScreen; -import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +//#if MC >= 1.21 +import net.minecraft.network.DisconnectionDetails; +//#else +//$$ import net.minecraft.network.chat.Component; +//#endif + @Mixin(DisconnectedScreen.class) public interface DisconnectedScreenAccessor { @Accessor - Component getReason(); + //#if MC >= 1.21 + DisconnectionDetails getDetails(); + //#else + //$$ Component getReason(); + //#endif } diff --git a/src/main/java/io/github/gaming32/worldhost/testing/WorldHostTesting.java b/src/main/java/io/github/gaming32/worldhost/testing/WorldHostTesting.java index 1e2f2214..d19100c0 100644 --- a/src/main/java/io/github/gaming32/worldhost/testing/WorldHostTesting.java +++ b/src/main/java/io/github/gaming32/worldhost/testing/WorldHostTesting.java @@ -21,6 +21,7 @@ import net.minecraft.client.gui.screens.multiplayer.SafetyScreen; import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; +import net.minecraft.network.chat.Component; import java.util.function.Supplier; @@ -95,7 +96,12 @@ private static ScreenChain tryToJoinServer() { .maybe(DisconnectedScreen.class, () -> { final var screen = (DisconnectedScreenAccessor)Minecraft.getInstance().screen; assert screen != null; - throw new IllegalStateException("Unexpected disconnect trying to join server: " + screen.getReason().getString()); + //#if MC >= 1.21 + final Component reason = screen.getDetails().reason(); + //#else + //$$ final Component reason = screen.getReason(); + //#endif + throw new IllegalStateException("Unexpected disconnect trying to join server: " + reason.getString()); }) .skip(ReceivingLevelScreen.class); }