mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-28 10:35:38 -05:00
regular expression support for config ignore lists
This commit is contained in:
parent
75ba0e72db
commit
f730fa0929
4 changed files with 39 additions and 24 deletions
12
CHANGELOG.md
12
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
|
||||
|
|
|
@ -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<ResourceLocation> deserializeResourceLocations(JsonObject json, String configKey, List<String> defaultValue) {
|
||||
protected Set<Pattern> deserializePatterns(JsonObject json, String configKey, List<String> 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<ResourceLocation> resourceLocations) {
|
||||
protected void serializePatterns(JsonObject json, String configKey, Set<Pattern> patterns) {
|
||||
json.add(configKey,
|
||||
JsonUtils.toArray(resourceLocations
|
||||
JsonUtils.toArray(patterns
|
||||
.stream()
|
||||
.map(ResourceLocation::toString)
|
||||
.map(Pattern::pattern)
|
||||
.toList()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ResourceLocation, JsonCompare.CompareSettings> overrideRules;
|
||||
private final Set<ResourceLocation> ignoreRecipeTypes;
|
||||
private final Set<ResourceLocation> ignoreRecipes;
|
||||
private final Set<Pattern> ignoreRecipeTypes;
|
||||
private final Set<Pattern> ignoreRecipes;
|
||||
private final boolean strictMode;
|
||||
|
||||
public DuplicationConfig(JsonCompare.CompareSettings defaultRules, LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> overrideRules, Set<ResourceLocation> ignoreRecipeTypes, Set<ResourceLocation> ignoreRecipes, boolean strictMode) {
|
||||
public DuplicationConfig(JsonCompare.CompareSettings defaultRules, LinkedHashMap<ResourceLocation, JsonCompare.CompareSettings> overrideRules, Set<Pattern> ignoreRecipeTypes, Set<Pattern> 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<ResourceLocation> ignoreRecipeTypes = deserializeResourceLocations(json,
|
||||
Set<Pattern> ignoreRecipeTypes = deserializePatterns(json,
|
||||
IGNORED_RECIPE_TYPES,
|
||||
Defaults.IGNORED_RECIPE_TYPES);
|
||||
Set<ResourceLocation> ignoreRecipes = deserializeResourceLocations(json, IGNORED_RECIPES, List.of());
|
||||
Set<Pattern> 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) -> {
|
||||
|
|
|
@ -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<String> unbakedTags;
|
||||
private final List<String> modPriorities;
|
||||
private final Set<UnifyTag<Item>> ignoredTags;
|
||||
private final Set<ResourceLocation> ignoredRecipeTypes;
|
||||
private final Set<ResourceLocation> ignoredRecipes;
|
||||
private final Set<Pattern> ignoredRecipeTypes;
|
||||
private final Set<Pattern> ignoredRecipes;
|
||||
private final boolean hideJeiRei;
|
||||
|
||||
public UnifyConfig(List<String> stoneStrata, List<String> materials, List<String> unbakedTags, List<String> modPriorities, Set<UnifyTag<Item>> ignoredTags, Set<ResourceLocation> ignoredRecipeTypes, Set<ResourceLocation> ignoredRecipes, boolean hideJeiRei) {
|
||||
public UnifyConfig(List<String> stoneStrata, List<String> materials, List<String> unbakedTags, List<String> modPriorities, Set<UnifyTag<Item>> ignoredTags, Set<Pattern> ignoredRecipeTypes, Set<Pattern> 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<UnifyTag<Item>> bakeTags() {
|
||||
|
@ -102,10 +103,10 @@ public class UnifyConfig extends Config {
|
|||
.stream()
|
||||
.map(s -> UnifyTag.item(new ResourceLocation(s)))
|
||||
.collect(Collectors.toSet()), new HashSet<>());
|
||||
Set<ResourceLocation> ignoredRecipeTypes = deserializeResourceLocations(json,
|
||||
Set<Pattern> ignoredRecipeTypes = deserializePatterns(json,
|
||||
IGNORED_RECIPE_TYPES,
|
||||
Defaults.IGNORED_RECIPE_TYPES);
|
||||
Set<ResourceLocation> ignoredRecipes = deserializeResourceLocations(json, IGNORED_RECIPES, List.of());
|
||||
Set<Pattern> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue