From 36ccb3bbfec293e388d11b04053805aa2ec0c5b3 Mon Sep 17 00:00:00 2001 From: cpw Date: Fri, 15 Feb 2019 20:00:41 -0500 Subject: [PATCH] Fix serverlang loading issue, by frontloading MC and Forge langs, so error messaging works. Signed-off-by: cpw --- .../minecraftforge/fml/loading/LoadingModList.java | 5 ++++- .../minecraftforge/fml/server/LanguageHook.java | 14 +++++++++++++- .../minecraftforge/fml/server/ServerModLoader.java | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/LoadingModList.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/LoadingModList.java index 160c4bf61..e0db81296 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/LoadingModList.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/LoadingModList.java @@ -105,8 +105,11 @@ public class LoadingModList return null; } - public URL findURLForResource(final String resourceName) { + public URL findURLForResource(String resourceName) { for (ModFileInfo mf : modFiles) { + // strip a leading slash + if (resourceName.startsWith("/")) resourceName = resourceName.substring(1); + final Path resource = mf.getFile().findResource(resourceName); if (Files.exists(resource)) { try { diff --git a/src/main/java/net/minecraftforge/fml/server/LanguageHook.java b/src/main/java/net/minecraftforge/fml/server/LanguageHook.java index 295a6655e..ebc324d8e 100644 --- a/src/main/java/net/minecraftforge/fml/server/LanguageHook.java +++ b/src/main/java/net/minecraftforge/fml/server/LanguageHook.java @@ -26,7 +26,7 @@ import net.minecraft.resources.IResource; import net.minecraft.server.MinecraftServer; import net.minecraft.util.JsonUtils; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.packs.ResourcePackLoader; +import net.minecraftforge.fml.ForgeI18n; import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -91,6 +91,17 @@ public class LanguageHook }); } + + static void loadForgeAndMCLangs() { + modTable = new HashMap<>(5000); + final InputStream mc = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/minecraft/lang/en_us.json"); + final InputStream forge = Thread.currentThread().getContextClassLoader().getResourceAsStream("assets/forge/lang/en_us.json"); + loadLocaleData(mc); + loadLocaleData(forge); + capturedTables.forEach(t->t.putAll(modTable)); + ForgeI18n.loadLanguageData(modTable); + } + static void loadLanguagesOnServer(MinecraftServer server) { modTable = new HashMap<>(5000); // Possible multi-language server support? @@ -98,5 +109,6 @@ public class LanguageHook loadLanguage(lang, server); } capturedTables.forEach(t->t.putAll(modTable)); + ForgeI18n.loadLanguageData(modTable); } } diff --git a/src/main/java/net/minecraftforge/fml/server/ServerModLoader.java b/src/main/java/net/minecraftforge/fml/server/ServerModLoader.java index 7092d7057..5222103dc 100644 --- a/src/main/java/net/minecraftforge/fml/server/ServerModLoader.java +++ b/src/main/java/net/minecraftforge/fml/server/ServerModLoader.java @@ -23,7 +23,6 @@ import net.minecraft.server.dedicated.DedicatedServer; import net.minecraftforge.fml.LogicalSidedProvider; import net.minecraftforge.fml.ModLoader; import net.minecraftforge.fml.SidedProvider; -import net.minecraftforge.fml.packs.ResourcePackLoader; public class ServerModLoader { @@ -32,6 +31,7 @@ public class ServerModLoader ServerModLoader.server = dedicatedServer; SidedProvider.setServer(()->dedicatedServer); LogicalSidedProvider.setServer(()->dedicatedServer); + LanguageHook.loadForgeAndMCLangs(); ModLoader.get().loadMods(); }