diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d1ab2b..3f28e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +## Unreleased + +### Added +- more materials and another tag to defaults + - back up your `unify.json` config and let it regenerate to get the new default or add it yourself + +### Changed +- ignore lists in `unify.json` and `duplicates.json` now support regular expressions + +### Fixed +- a compat issue on Fabric when REI is present + ## [0.0.6] - 2022-09-02 ### Added diff --git a/Common/src/main/java/com/almostreliable/unified/config/Config.java b/Common/src/main/java/com/almostreliable/unified/config/Config.java index 2696ec9..9abf5c7 100644 --- a/Common/src/main/java/com/almostreliable/unified/config/Config.java +++ b/Common/src/main/java/com/almostreliable/unified/config/Config.java @@ -6,7 +6,6 @@ import com.almostreliable.unified.utils.JsonUtils; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import net.minecraft.resources.ResourceLocation; import java.io.BufferedReader; import java.io.IOException; @@ -17,6 +16,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.function.Supplier; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class Config { @@ -89,20 +89,20 @@ public class Config { return defaultValue; } - protected Set deserializeResourceLocations(JsonObject json, String configKey, List defaultValue) { + protected Set deserializePatterns(JsonObject json, String configKey, List defaultValue) { return safeGet(() -> JsonUtils .toList(json.getAsJsonArray(configKey)) .stream() - .map(ResourceLocation::new) + .map(Pattern::compile) .collect(Collectors.toSet()), - new HashSet<>(defaultValue.stream().map(ResourceLocation::new).toList())); + new HashSet<>(defaultValue.stream().map(Pattern::compile).toList())); } - protected void serializeResourceLocations(JsonObject json, String configKey, Set resourceLocations) { + protected void serializePatterns(JsonObject json, String configKey, Set patterns) { json.add(configKey, - JsonUtils.toArray(resourceLocations + JsonUtils.toArray(patterns .stream() - .map(ResourceLocation::toString) + .map(Pattern::pattern) .toList())); } diff --git a/Common/src/main/java/com/almostreliable/unified/config/DuplicationConfig.java b/Common/src/main/java/com/almostreliable/unified/config/DuplicationConfig.java index 7539179..0664372 100644 --- a/Common/src/main/java/com/almostreliable/unified/config/DuplicationConfig.java +++ b/Common/src/main/java/com/almostreliable/unified/config/DuplicationConfig.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class DuplicationConfig extends Config { @@ -15,11 +16,11 @@ public class DuplicationConfig extends Config { private final JsonCompare.CompareSettings defaultRules; private final LinkedHashMap overrideRules; - private final Set ignoreRecipeTypes; - private final Set ignoreRecipes; + private final Set ignoreRecipeTypes; + private final Set ignoreRecipes; private final boolean strictMode; - public DuplicationConfig(JsonCompare.CompareSettings defaultRules, LinkedHashMap overrideRules, Set ignoreRecipeTypes, Set ignoreRecipes, boolean strictMode) { + public DuplicationConfig(JsonCompare.CompareSettings defaultRules, LinkedHashMap overrideRules, Set ignoreRecipeTypes, Set ignoreRecipes, boolean strictMode) { this.defaultRules = defaultRules; this.overrideRules = overrideRules; this.ignoreRecipeTypes = ignoreRecipeTypes; @@ -28,7 +29,8 @@ public class DuplicationConfig extends Config { } public boolean shouldIgnoreRecipe(RecipeLink recipe) { - return ignoreRecipeTypes.contains(recipe.getType()) || ignoreRecipes.contains(recipe.getId()); + return ignoreRecipeTypes.stream().anyMatch(pattern -> pattern.matcher(recipe.getType().toString()).matches()) || + ignoreRecipes.stream().anyMatch(pattern -> pattern.matcher(recipe.getId().toString()).matches()); } public JsonCompare.CompareSettings getCompareSettings(ResourceLocation type) { @@ -48,10 +50,10 @@ public class DuplicationConfig extends Config { @Override public DuplicationConfig deserialize(JsonObject json) { - Set ignoreRecipeTypes = deserializeResourceLocations(json, + Set ignoreRecipeTypes = deserializePatterns(json, IGNORED_RECIPE_TYPES, Defaults.IGNORED_RECIPE_TYPES); - Set ignoreRecipes = deserializeResourceLocations(json, IGNORED_RECIPES, List.of()); + Set ignoreRecipes = deserializePatterns(json, IGNORED_RECIPES, List.of()); JsonCompare.CompareSettings defaultRules = safeGet(() -> createCompareSet(json.getAsJsonObject( DEFAULT_DUPLICATE_RULES)), @@ -100,8 +102,8 @@ public class DuplicationConfig extends Config { public JsonObject serialize(DuplicationConfig config) { JsonObject json = new JsonObject(); - serializeResourceLocations(json, IGNORED_RECIPE_TYPES, config.ignoreRecipeTypes); - serializeResourceLocations(json, IGNORED_RECIPES, config.ignoreRecipes); + serializePatterns(json, IGNORED_RECIPE_TYPES, config.ignoreRecipeTypes); + serializePatterns(json, IGNORED_RECIPES, config.ignoreRecipes); json.add(DEFAULT_DUPLICATE_RULES, config.defaultRules.serialize()); JsonObject overrides = new JsonObject(); config.overrideRules.forEach((rl, compareSettings) -> { diff --git a/Common/src/main/java/com/almostreliable/unified/config/UnifyConfig.java b/Common/src/main/java/com/almostreliable/unified/config/UnifyConfig.java index a7c2082..889ba62 100644 --- a/Common/src/main/java/com/almostreliable/unified/config/UnifyConfig.java +++ b/Common/src/main/java/com/almostreliable/unified/config/UnifyConfig.java @@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; public class UnifyConfig extends Config { @@ -20,11 +21,11 @@ public class UnifyConfig extends Config { private final List unbakedTags; private final List modPriorities; private final Set> ignoredTags; - private final Set ignoredRecipeTypes; - private final Set ignoredRecipes; + private final Set ignoredRecipeTypes; + private final Set ignoredRecipes; private final boolean hideJeiRei; - public UnifyConfig(List stoneStrata, List materials, List unbakedTags, List modPriorities, Set> ignoredTags, Set ignoredRecipeTypes, Set ignoredRecipes, boolean hideJeiRei) { + public UnifyConfig(List stoneStrata, List materials, List unbakedTags, List modPriorities, Set> ignoredTags, Set ignoredRecipeTypes, Set ignoredRecipes, boolean hideJeiRei) { this.stoneStrata = stoneStrata; this.materials = materials; this.unbakedTags = unbakedTags; @@ -44,11 +45,11 @@ public class UnifyConfig extends Config { } public boolean includeRecipe(ResourceLocation recipe) { - return !ignoredRecipes.contains(recipe); + return ignoredRecipes.stream().noneMatch(pattern -> pattern.matcher(recipe.toString()).matches()); } public boolean includeRecipeType(ResourceLocation type) { - return !ignoredRecipeTypes.contains(type); + return ignoredRecipeTypes.stream().noneMatch(pattern -> pattern.matcher(type.toString()).matches()); } public List> bakeTags() { @@ -102,10 +103,10 @@ public class UnifyConfig extends Config { .stream() .map(s -> UnifyTag.item(new ResourceLocation(s))) .collect(Collectors.toSet()), new HashSet<>()); - Set ignoredRecipeTypes = deserializeResourceLocations(json, + Set ignoredRecipeTypes = deserializePatterns(json, IGNORED_RECIPE_TYPES, Defaults.IGNORED_RECIPE_TYPES); - Set ignoredRecipes = deserializeResourceLocations(json, IGNORED_RECIPES, List.of()); + Set ignoredRecipes = deserializePatterns(json, IGNORED_RECIPES, List.of()); boolean hideJeiRei = safeGet(() -> json.getAsJsonPrimitive(HIDE_JEI_REI).getAsBoolean(), true); return new UnifyConfig(stoneStrata, @@ -131,8 +132,8 @@ public class UnifyConfig extends Config { .map(UnifyTag::location) .map(ResourceLocation::toString) .toList())); - serializeResourceLocations(json, IGNORED_RECIPE_TYPES, config.ignoredRecipeTypes); - serializeResourceLocations(json, IGNORED_RECIPES, config.ignoredRecipes); + serializePatterns(json, IGNORED_RECIPE_TYPES, config.ignoredRecipeTypes); + serializePatterns(json, IGNORED_RECIPES, config.ignoredRecipes); json.add(HIDE_JEI_REI, new JsonPrimitive(config.hideJeiRei)); return json; }