Skip to content

Commit

Permalink
Fix mixin error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jun 21, 2024
1 parent 0f1ae7d commit 1ec4368
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1ec4368

Please sign in to comment.