package me.deftware.client.framework.gui;

import me.deftware.client.framework.helper.ScreenHelper;
import me.deftware.client.framework.util.ResourceUtils;
import me.deftware.mixin.imp.IMixinTitleScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.util.Pair;

import java.util.Objects;
import java.util.function.Function;

/**
 * @author Deftware
 */
public enum MinecraftScreens {

	Multiplayer(MultiplayerScreen::new), WorldSelection(SelectWorldScreen::new),
	Options(parent -> new OptionsScreen(parent, MinecraftClient.getInstance().options)), MainMenu(parent -> new TitleScreen()),
	Mods(parent -> {
		// Important: Change "modmenu" to what's relevant on this mc version
		if (ResourceUtils.hasSpecificMod("modmenu")) {
			return Objects.requireNonNull(ScreenHelper.createScreenInstance("io.github.prospector.modmenu.gui.ModsScreen", new Pair<>(Screen.class, parent)));
		}
		return null;
	});

	private final Function<GuiScreen, Screen> screenFunction;

	MinecraftScreens(Function<GuiScreen, Screen> screenFunction) {
		this.screenFunction = screenFunction;
	}

	public void open(GuiScreen parent) {
		MinecraftClient.getInstance().openScreen(screenFunction.apply(parent));
	}

	@SuppressWarnings("ConstantConditions")
	public static void openRealms() {
		((IMixinTitleScreen) new TitleScreen()).switchToRealmsPub();
	}

}

@@ -133,26 +133,27 @@
 ork.
-util.ResourceUtils
+minecraft.Minecraft
 ;%0Aim
@@ -173,35 +173,43 @@
 are.
-mixin.imp.IMixinTitleScreen
+client.framework.util.ResourceUtils
 ;%0Aim
@@ -537,32 +537,96 @@
 ectWorldScreen;%0A
+import net.minecraft.client.realms.gui.screen.RealmsMainScreen;%0A
 import net.minec
@@ -1569,49 +1569,8 @@
 %09%7D%0A%0A
-%09@SuppressWarnings(%22ConstantConditions%22)%0A
 %09pub
@@ -1606,66 +1606,92 @@
 %7B%0A%09%09
-((IMixinTitle
+MinecraftClient.getInstance().open
 Screen
-) 
+(
 new 
-TitleScreen()).switchToRealmsPub(
+RealmsMainScreen(Minecraft.getScreen())
 );%0A%09

Fix openRealms