From cc45187384d925a41b3b8d7f6bc446dba4cc83bc Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Thu, 9 May 2024 10:03:35 -0500 Subject: [PATCH] NeoForge 1.20.6 runs --- .../github/gaming32/worldhost/WorldHost.java | 33 +++++++++++++------ .../worldhost/mixin/MixinConnectScreen_1.java | 7 ++++ src/main/resources/world-host.mixins.json | 2 ++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHost.java b/src/main/java/io/github/gaming32/worldhost/WorldHost.java index 5e35c38..c7004fb 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHost.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHost.java @@ -106,6 +106,7 @@ //$$ import net.minecraftforge.fml.ModLoadingContext; //$$ import net.minecraftforge.fml.common.Mod; //$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +//$$ import net.minecraftforge.fml.loading.FMLPaths; //#else //$$ import net.neoforged.api.distmarker.Dist; //$$ import net.neoforged.bus.api.SubscribeEvent; @@ -113,6 +114,7 @@ //$$ import net.neoforged.fml.ModLoadingContext; //$$ import net.neoforged.fml.common.Mod; //$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +//$$ import net.neoforged.fml.loading.FMLPaths; //#endif //$$ import java.util.function.BiFunction; //#if MC >= 1.20.5 @@ -173,13 +175,13 @@ public class WorldHost 300 * 20 }; - public static final File GAME_DIR = Minecraft.getInstance().gameDirectory; - public static final File CACHE_DIR = new File(GAME_DIR, ".world-host-cache"); + public static final Path GAME_DIR = getGameDir(); + public static final Path CACHE_DIR = GAME_DIR.resolve(".world-host-cache"); - public static final File CONFIG_DIR = new File(GAME_DIR, "config"); - public static final Path CONFIG_FILE = new File(CONFIG_DIR, "world-host.json5").toPath(); - public static final Path FRIENDS_FILE = new File(CONFIG_DIR, "world-host-friends.json").toPath(); - public static final Path OLD_CONFIG_FILE = new File(CONFIG_DIR, "world-host.json").toPath(); + public static final Path CONFIG_DIR = GAME_DIR.resolve("config"); + public static final Path CONFIG_FILE = CONFIG_DIR.resolve("world-host.json5"); + public static final Path FRIENDS_FILE = CONFIG_DIR.resolve("world-host-friends.json"); + public static final Path OLD_CONFIG_FILE = CONFIG_DIR.resolve("world-host.json"); public static final WorldHostConfig CONFIG = new WorldHostConfig(); private static List wordsForCid; @@ -245,17 +247,20 @@ private static void init() { loadConfig(); - //noinspection ResultOfMethodCallIgnored - CACHE_DIR.mkdirs(); + try { + Files.createDirectories(CACHE_DIR); + } catch (IOException e) { + LOGGER.error("Failed to create cache directory", e); + } //#if MC >= 1.19.2 profileCache = Services.create( ((MinecraftAccessor)Minecraft.getInstance()).getAuthenticationService(), - CACHE_DIR + CACHE_DIR.toFile() ).profileCache(); //#else //$$ profileCache = new GameProfileCache( //$$ new YggdrasilAuthenticationService(Minecraft.getInstance().getProxy()).createProfileRepository(), - //$$ new File(CACHE_DIR, "usercache.json") + //$$ CACHE_DIR.resolve("usercache.json").toFile() //$$ ); //#endif profileCache.setExecutor(Util.backgroundExecutor()); @@ -840,6 +845,14 @@ public static CompletableFuture> checkForUpdates() { }); } + private static Path getGameDir() { + //#if FABRIC + return FabricLoader.getInstance().getGameDir(); + //#else + //$$ return FMLPaths.GAMEDIR.get(); + //#endif + } + //#if FORGELIKE //#if MC >= 1.20.5 //$$ @EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java index f998195..7b6635c 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java @@ -15,6 +15,10 @@ //$$ import java.util.concurrent.CompletableFuture; //#endif +//#if MC >= 1.20.5 +import net.minecraft.client.multiplayer.TransferState; +//#endif + @Mixin(targets = "net.minecraft.client.gui.screens.ConnectScreen$1") public class MixinConnectScreen_1 { @Unique @@ -32,6 +36,9 @@ private void initRefs( //#elseif MC > 1.18.2 //$$ CompletableFuture completableFuture, //#endif + //#if MC >= 1.20.5 + TransferState transferState, + //#endif CallbackInfo ci ) { wh$parent = connectScreen; diff --git a/src/main/resources/world-host.mixins.json b/src/main/resources/world-host.mixins.json index 47a3ac2..015ee37 100644 --- a/src/main/resources/world-host.mixins.json +++ b/src/main/resources/world-host.mixins.json @@ -24,7 +24,9 @@ "MixinWorldSelectionList_WorldListEntry", "PlainTextButtonAccessor", "ServerStatusPingerAccessor", + //#if FABRIC "modmenu.MixinModMenuEventHandler" + //#endif ], "injectors": { "defaultRequire": 1