From 9edea34dc7c0b7871c29f415a5314327a7021943 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Fri, 30 Jun 2023 20:58:54 +0200 Subject: [PATCH] Store serialhandlers.cfg as an internal asset instead of an array of strings Is copied into the config directory upon first launch. Also, comments are now allowed (only from the beginning of the file). Removes GTNH-specific code to be replaced with a configuration file. --- .../java/codechicken/nei/ClientHandler.java | 17 +++++++---------- .../resources/assets/nei/cfg/serialhandlers.cfg | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/assets/nei/cfg/serialhandlers.cfg diff --git a/src/main/java/codechicken/nei/ClientHandler.java b/src/main/java/codechicken/nei/ClientHandler.java index bcac4a38..aebd60e0 100644 --- a/src/main/java/codechicken/nei/ClientHandler.java +++ b/src/main/java/codechicken/nei/ClientHandler.java @@ -9,9 +9,6 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -48,15 +45,12 @@ import codechicken.nei.recipe.GuiRecipeTab; import codechicken.nei.recipe.StackInfo; import cpw.mods.fml.client.CustomModLoadingErrorDisplayException; import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; public class ClientHandler { - private static String[] defaultSerialHandlers = { - "WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler" }; private static String[] defaultHandlerOrdering = { "# Each line in this file should either be a comment (starts with '#') or an ordering.", "# Ordering lines are ,.", @@ -160,16 +154,19 @@ public class ClientHandler { if (!file.exists()) { try (FileWriter writer = new FileWriter(file)) { NEIClientConfig.logger.info("Creating default serial handlers list {}", file); - Collection toSave = Loader.isModLoaded("dreamcraft") ? Collections.singletonList("") - : Arrays.asList(defaultSerialHandlers); - IOUtils.writeLines(toSave, "\n", writer); + URL defaultSerialHandlersResource = ClientHandler.class + .getResource("/assets/nei/cfg/serialhandlers.cfg"); + if (defaultSerialHandlersResource != null) { + IOUtils.copy(defaultSerialHandlersResource.openStream(), writer); + } } catch (IOException e) { NEIClientConfig.logger.error("Failed to save default serial handlers list to file {}", file, e); } } try (FileReader reader = new FileReader(file)) { NEIClientConfig.logger.info("Loading serial handlers from file {}", file); - NEIClientConfig.serialHandlers = new HashSet<>(IOUtils.readLines(reader)); + NEIClientConfig.serialHandlers = IOUtils.readLines(reader).stream().filter((line) -> !line.startsWith("#")) + .collect(Collectors.toCollection(HashSet::new)); } catch (IOException e) { NEIClientConfig.logger.error("Failed to load serial handlers from file {}", file, e); } diff --git a/src/main/resources/assets/nei/cfg/serialhandlers.cfg b/src/main/resources/assets/nei/cfg/serialhandlers.cfg new file mode 100644 index 00000000..e5027356 --- /dev/null +++ b/src/main/resources/assets/nei/cfg/serialhandlers.cfg @@ -0,0 +1,6 @@ +# This version of NEI loads recipes in parallel. Some recipe handlers have not been designed with that in mind and might +# crash. List these handlers in this file to force them to be loaded a single thread. Each line in this file should +# either be a comment (starts with '#') or a fully qualified class name (that includes the package name) for a recipe +# handler. +# If you delete this file, it will be regenerated with the default height hacked handlers list. +WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler