From 282b0d45da102e6d80974afb8a052f81d25e5fd9 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Fri, 30 Jun 2023 20:30:59 +0200 Subject: [PATCH] Store heighthackhandlers.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). --- src/main/java/codechicken/nei/ClientHandler.java | 15 +++++++-------- .../assets/nei/cfg/heighthackhandlers.cfg | 13 +++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/assets/nei/cfg/heighthackhandlers.cfg diff --git a/src/main/java/codechicken/nei/ClientHandler.java b/src/main/java/codechicken/nei/ClientHandler.java index 42cd90ba..bcac4a38 100644 --- a/src/main/java/codechicken/nei/ClientHandler.java +++ b/src/main/java/codechicken/nei/ClientHandler.java @@ -57,11 +57,6 @@ public class ClientHandler { private static String[] defaultSerialHandlers = { "WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler" }; - private static String[] defaultHeightHackHandlerRegex = { "buildcraft.compat.nei.*", - "cofh.thermalexpansion.plugins.nei.handlers.*", "crazypants.enderio.nei.*", - "forestry.factory.recipes.nei.*", "ic2.neiIntegration.core.recipehandler.*", "mariculture.plugins.nei.*", - "redgear.brewcraft.plugins.nei.*", "tconstruct.plugins.nei.*", - "WayofTime.alchemicalWizardry.client.nei.*", }; private static String[] defaultHandlerOrdering = { "# Each line in this file should either be a comment (starts with '#') or an ordering.", "# Ordering lines are ,.", @@ -185,8 +180,11 @@ public class ClientHandler { if (!file.exists()) { try (FileWriter writer = new FileWriter(file)) { NEIClientConfig.logger.info("Creating default height hack handlers list {}", file); - Collection toSave = Arrays.asList(defaultHeightHackHandlerRegex); - IOUtils.writeLines(toSave, "\n", writer); + URL defaultHeightHackHandlersResource = ClientHandler.class + .getResource("/assets/nei/cfg/heighthackhandlers.cfg"); + if (defaultHeightHackHandlersResource != null) { + IOUtils.copy(defaultHeightHackHandlersResource.openStream(), writer); + } } catch (IOException e) { NEIClientConfig.logger.error("Failed to save default height hack handlers list to file {}", file, e); } @@ -194,7 +192,8 @@ public class ClientHandler { try (FileReader reader = new FileReader(file)) { NEIClientConfig.logger.info("Loading height hack handlers from file {}", file); - NEIClientConfig.heightHackHandlerRegex = IOUtils.readLines(reader).stream().map(Pattern::compile) + NEIClientConfig.heightHackHandlerRegex = IOUtils.readLines(reader).stream() + .filter((line) -> !line.startsWith("#")).map(Pattern::compile) .collect(Collectors.toCollection(HashSet::new)); } catch (IOException e) { NEIClientConfig.logger.error("Failed to load height hack handlers from file {}", file, e); diff --git a/src/main/resources/assets/nei/cfg/heighthackhandlers.cfg b/src/main/resources/assets/nei/cfg/heighthackhandlers.cfg new file mode 100644 index 00000000..68fb6ed8 --- /dev/null +++ b/src/main/resources/assets/nei/cfg/heighthackhandlers.cfg @@ -0,0 +1,13 @@ +# 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. Wildcard patterns ('*') can be used to catch multiple classes with a single entry. +# If you delete this file, it will be regenerated with the default height hacked handlers list. +buildcraft.compat.nei.* +cofh.thermalexpansion.plugins.nei.handlers.* +crazypants.enderio.nei.* +forestry.factory.recipes.nei.* +ic2.neiIntegration.core.recipehandler.* +mariculture.plugins.nei.* +redgear.brewcraft.plugins.nei.* +tconstruct.plugins.nei.* +WayofTime.alchemicalWizardry.client.nei.* +exnihilo.compatibility.nei.*