mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
port 1.18 changes
Co-authored-by: LLytho <main@lytho.dev>
This commit is contained in:
parent
b1c86ac20c
commit
6aab5ed5cf
12 changed files with 198 additions and 66 deletions
|
@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog],
|
The format is based on [Keep a Changelog],
|
||||||
and this project adheres to [Semantic Versioning].
|
and this project adheres to [Semantic Versioning].
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
- updated to JEI 10 as it's no longer alpha
|
||||||
|
- minimum version 10.2.1.278
|
||||||
|
- JEI 9 is not supported anymore since it's not possible with some internals we use
|
||||||
|
- added config option to completely ignore items from unification and hiding
|
||||||
|
- improved stone strata detection by making use of `forge:ores_in_ground` tag
|
||||||
|
|
||||||
## [0.2.1] - 2022-10-28
|
## [0.2.1] - 2022-10-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface AlmostUnifiedPlatform {
|
public interface AlmostUnifiedPlatform {
|
||||||
|
|
||||||
|
@ -37,4 +41,6 @@ public interface AlmostUnifiedPlatform {
|
||||||
Path getLogPath();
|
Path getLogPath();
|
||||||
|
|
||||||
void bindRecipeHandlers(RecipeHandlerFactory factory);
|
void bindRecipeHandlers(RecipeHandlerFactory factory);
|
||||||
|
|
||||||
|
Set<UnifyTag<Item>> getStoneStrataTags(List<String> stoneStrataIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
|
import com.almostreliable.unified.api.StoneStrataHandler;
|
||||||
import com.almostreliable.unified.config.Config;
|
import com.almostreliable.unified.config.Config;
|
||||||
import com.almostreliable.unified.config.DebugConfig;
|
import com.almostreliable.unified.config.DebugConfig;
|
||||||
import com.almostreliable.unified.config.DuplicationConfig;
|
import com.almostreliable.unified.config.DuplicationConfig;
|
||||||
|
@ -24,7 +25,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
public final class AlmostUnifiedRuntime {
|
public final class AlmostUnifiedRuntime {
|
||||||
private final RecipeHandlerFactory recipeHandlerFactory;
|
private final RecipeHandlerFactory recipeHandlerFactory;
|
||||||
private final TagMap tagMap;
|
private final TagMap filteredTagMap;
|
||||||
private final DuplicationConfig dupConfig;
|
private final DuplicationConfig dupConfig;
|
||||||
private final UnifyConfig unifyConfig;
|
private final UnifyConfig unifyConfig;
|
||||||
private final DebugConfig debugConfig;
|
private final DebugConfig debugConfig;
|
||||||
|
@ -32,11 +33,15 @@ public final class AlmostUnifiedRuntime {
|
||||||
|
|
||||||
private AlmostUnifiedRuntime(RecipeHandlerFactory recipeHandlerFactory, TagMap tagMap, DuplicationConfig dupConfig, UnifyConfig unifyConfig, DebugConfig debugConfig) {
|
private AlmostUnifiedRuntime(RecipeHandlerFactory recipeHandlerFactory, TagMap tagMap, DuplicationConfig dupConfig, UnifyConfig unifyConfig, DebugConfig debugConfig) {
|
||||||
this.recipeHandlerFactory = recipeHandlerFactory;
|
this.recipeHandlerFactory = recipeHandlerFactory;
|
||||||
this.tagMap = tagMap;
|
|
||||||
this.dupConfig = dupConfig;
|
this.dupConfig = dupConfig;
|
||||||
this.unifyConfig = unifyConfig;
|
this.unifyConfig = unifyConfig;
|
||||||
this.debugConfig = debugConfig;
|
this.debugConfig = debugConfig;
|
||||||
this.replacementMap = new ReplacementMap(this.tagMap, this.unifyConfig);
|
List<UnifyTag<Item>> allowedTags = unifyConfig.bakeTags();
|
||||||
|
this.filteredTagMap = tagMap.filtered(allowedTags::contains, unifyConfig::includeItem);
|
||||||
|
StoneStrataHandler stoneStrataHandler = StoneStrataHandler.create(unifyConfig.getStoneStrata(),
|
||||||
|
AlmostUnifiedPlatform.INSTANCE.getStoneStrataTags(unifyConfig.getStoneStrata()),
|
||||||
|
tagMap);
|
||||||
|
this.replacementMap = new ReplacementMap(filteredTagMap, stoneStrataHandler, unifyConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AlmostUnifiedRuntime create(TagManager tagManager) {
|
public static AlmostUnifiedRuntime create(TagManager tagManager) {
|
||||||
|
@ -50,15 +55,22 @@ public final class AlmostUnifiedRuntime {
|
||||||
RecipeHandlerFactory factory = new RecipeHandlerFactory();
|
RecipeHandlerFactory factory = new RecipeHandlerFactory();
|
||||||
AlmostUnifiedPlatform.INSTANCE.bindRecipeHandlers(factory);
|
AlmostUnifiedPlatform.INSTANCE.bindRecipeHandlers(factory);
|
||||||
|
|
||||||
List<UnifyTag<Item>> allowedTags = unifyConfig.bakeTags();
|
TagMap tagMap = TagMap.create(tagManager);
|
||||||
TagMap tagMap = TagMap.create(tagManager, allowedTags::contains);
|
|
||||||
|
|
||||||
return new AlmostUnifiedRuntime(factory, tagMap, dupConfig, unifyConfig, debugConfig);
|
return new AlmostUnifiedRuntime(factory, tagMap, dupConfig, unifyConfig, debugConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createGitIgnoreIfNotExists() {
|
||||||
|
Path path = AlmostUnifiedPlatform.INSTANCE.getConfigPath();
|
||||||
|
if (!(Files.exists(path) && Files.isDirectory(path))) {
|
||||||
|
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getConfigPath(),
|
||||||
|
".gitignore",
|
||||||
|
sb -> sb.append(DebugConfig.NAME).append(".json").append("\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void run(Map<ResourceLocation, JsonElement> recipes, boolean skipClientTracking) {
|
public void run(Map<ResourceLocation, JsonElement> recipes, boolean skipClientTracking) {
|
||||||
debugConfig.logRecipes(recipes, "recipes_before_unification.txt");
|
debugConfig.logRecipes(recipes, "recipes_before_unification.txt");
|
||||||
debugConfig.logUnifyTagDump(tagMap);
|
debugConfig.logUnifyTagDump(filteredTagMap);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
RecipeTransformer.Result result = new RecipeTransformer(recipeHandlerFactory,
|
RecipeTransformer.Result result = new RecipeTransformer(recipeHandlerFactory,
|
||||||
|
@ -71,20 +83,11 @@ public final class AlmostUnifiedRuntime {
|
||||||
debugConfig.logRecipes(recipes, "recipes_after_unification.txt");
|
debugConfig.logRecipes(recipes, "recipes_after_unification.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagMap getTagMap() {
|
public TagMap getFilteredTagMap() {
|
||||||
return tagMap;
|
return filteredTagMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReplacementMap getReplacementMap() {
|
public ReplacementMap getReplacementMap() {
|
||||||
return replacementMap;
|
return replacementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createGitIgnoreIfNotExists() {
|
|
||||||
Path path = AlmostUnifiedPlatform.INSTANCE.getConfigPath();
|
|
||||||
if (!(Files.exists(path) && Files.isDirectory(path))) {
|
|
||||||
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getConfigPath(),
|
|
||||||
".gitignore",
|
|
||||||
sb -> sb.append(DebugConfig.NAME).append(".json").append("\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.almostreliable.unified.api;
|
||||||
|
|
||||||
|
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
||||||
|
import com.almostreliable.unified.utils.TagMap;
|
||||||
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class StoneStrataHandler {
|
||||||
|
|
||||||
|
private final List<String> stoneStrata;
|
||||||
|
private final Pattern tagMatcher;
|
||||||
|
private final TagMap stoneStrataTagMap;
|
||||||
|
|
||||||
|
private StoneStrataHandler(List<String> stoneStrata, Pattern tagMatcher, TagMap stoneStrataTagMap) {
|
||||||
|
this.stoneStrata = stoneStrata;
|
||||||
|
this.tagMatcher = tagMatcher;
|
||||||
|
this.stoneStrataTagMap = stoneStrataTagMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StoneStrataHandler create(List<String> stoneStrataIds, Set<UnifyTag<Item>> stoneStrataTags, TagMap tagMap) {
|
||||||
|
TagMap stoneStrataTagMap = tagMap.filtered(stoneStrataTags::contains, item -> true);
|
||||||
|
Pattern tagMatcher = switch (AlmostUnifiedPlatform.INSTANCE.getPlatform()) {
|
||||||
|
case FORGE -> Pattern.compile("forge:ores/.+");
|
||||||
|
case FABRIC -> Pattern.compile("(c:ores/.+|c:.+_ore)");
|
||||||
|
};
|
||||||
|
return new StoneStrataHandler(stoneStrataIds, tagMatcher, stoneStrataTagMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the stone strata from given item. Method works on the requirement that it's an item which has a stone strata.
|
||||||
|
* Use {@link #isStoneStrataTag(UnifyTag)} to fill this requirement.
|
||||||
|
*
|
||||||
|
* @param item The item to get the stone strata from.
|
||||||
|
* @return The stone strata of the item. Returning empty string means clean-stone strata.
|
||||||
|
*/
|
||||||
|
public String getStoneStrata(ResourceLocation item) {
|
||||||
|
String strata = stoneStrataTagMap
|
||||||
|
.getTags(item)
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.map(UnifyTag::location)
|
||||||
|
.map(ResourceLocation::toString)
|
||||||
|
.map(s -> {
|
||||||
|
int i = s.lastIndexOf('/');
|
||||||
|
return i == -1 ? null : s.substring(i + 1);
|
||||||
|
})
|
||||||
|
.orElse(null);
|
||||||
|
if (strata != null) {
|
||||||
|
return strata;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String stone : stoneStrata) {
|
||||||
|
if (item.getPath().contains(stone + "_")) {
|
||||||
|
return stone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStoneStrataTag(UnifyTag<Item> tag) {
|
||||||
|
return tagMatcher.matcher(tag.location().toString()).matches();
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,7 +56,7 @@ public class AlmostKube extends KubeJSPlugin {
|
||||||
public static Set<String> getTags() {
|
public static Set<String> getTags() {
|
||||||
return AlmostUnified
|
return AlmostUnified
|
||||||
.getRuntime()
|
.getRuntime()
|
||||||
.getTagMap()
|
.getFilteredTagMap()
|
||||||
.getTags()
|
.getTags()
|
||||||
.stream()
|
.stream()
|
||||||
.map(tag -> tag.location().toString())
|
.map(tag -> tag.location().toString())
|
||||||
|
@ -67,7 +67,7 @@ public class AlmostKube extends KubeJSPlugin {
|
||||||
UnifyTag<Item> asUnifyTag = UnifyTag.item(tag);
|
UnifyTag<Item> asUnifyTag = UnifyTag.item(tag);
|
||||||
return AlmostUnified
|
return AlmostUnified
|
||||||
.getRuntime()
|
.getRuntime()
|
||||||
.getTagMap()
|
.getFilteredTagMap()
|
||||||
.getItems(asUnifyTag)
|
.getItems(asUnifyTag)
|
||||||
.stream()
|
.stream()
|
||||||
.map(ResourceLocation::toString)
|
.map(ResourceLocation::toString)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.almostreliable.unified.compat;
|
package com.almostreliable.unified.compat;
|
||||||
|
|
||||||
import com.almostreliable.unified.AlmostUnified;
|
import com.almostreliable.unified.AlmostUnified;
|
||||||
|
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
||||||
|
import com.almostreliable.unified.api.StoneStrataHandler;
|
||||||
import com.almostreliable.unified.config.UnifyConfig;
|
import com.almostreliable.unified.config.UnifyConfig;
|
||||||
import com.almostreliable.unified.utils.ReplacementMap;
|
import com.almostreliable.unified.utils.ReplacementMap;
|
||||||
import com.almostreliable.unified.utils.TagMap;
|
import com.almostreliable.unified.utils.TagMap;
|
||||||
|
@ -17,11 +19,12 @@ public class HideHelper {
|
||||||
|
|
||||||
public static Collection<ItemStack> createHidingList(UnifyConfig config) {
|
public static Collection<ItemStack> createHidingList(UnifyConfig config) {
|
||||||
List<UnifyTag<Item>> unifyTags = config.bakeTags();
|
List<UnifyTag<Item>> unifyTags = config.bakeTags();
|
||||||
TagMap tagMap = TagMap.create(unifyTags);
|
TagMap filteredTagMap = TagMap.create(unifyTags).filtered($ -> true, config::includeItem);
|
||||||
ReplacementMap repMap = new ReplacementMap(tagMap, config);
|
StoneStrataHandler stoneStrataHandler = getStoneStrataHandler(config);
|
||||||
|
ReplacementMap repMap = new ReplacementMap(filteredTagMap, stoneStrataHandler, config);
|
||||||
|
|
||||||
return tagMap.getTags().stream().map(unifyTag -> {
|
return filteredTagMap.getTags().stream().map(unifyTag -> {
|
||||||
Collection<ResourceLocation> itemsByTag = tagMap.getItems(unifyTag);
|
Collection<ResourceLocation> itemsByTag = filteredTagMap.getItems(unifyTag);
|
||||||
if (itemsByTag.size() <= 1) return new ArrayList<ItemStack>();
|
if (itemsByTag.size() <= 1) return new ArrayList<ItemStack>();
|
||||||
|
|
||||||
Set<ResourceLocation> replacements = itemsByTag
|
Set<ResourceLocation> replacements = itemsByTag
|
||||||
|
@ -42,4 +45,10 @@ public class HideHelper {
|
||||||
return toHide.stream().flatMap(rl -> Registry.ITEM.getOptional(rl).stream()).map(ItemStack::new).toList();
|
return toHide.stream().flatMap(rl -> Registry.ITEM.getOptional(rl).stream()).map(ItemStack::new).toList();
|
||||||
}).flatMap(Collection::stream).toList();
|
}).flatMap(Collection::stream).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static StoneStrataHandler getStoneStrataHandler(UnifyConfig config) {
|
||||||
|
Set<UnifyTag<Item>> stoneStrataTags = AlmostUnifiedPlatform.INSTANCE.getStoneStrataTags(config.getStoneStrata());
|
||||||
|
TagMap stoneStrataTagMap = TagMap.create(stoneStrataTags);
|
||||||
|
return StoneStrataHandler.create(config.getStoneStrata(), stoneStrataTags, stoneStrataTagMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,19 @@ public class UnifyConfig extends Config {
|
||||||
private final List<String> materials;
|
private final List<String> materials;
|
||||||
private final Map<ResourceLocation, String> priorityOverrides;
|
private final Map<ResourceLocation, String> priorityOverrides;
|
||||||
private final Set<UnifyTag<Item>> ignoredTags;
|
private final Set<UnifyTag<Item>> ignoredTags;
|
||||||
|
private final Set<Pattern> ignoredItems;
|
||||||
private final Set<Pattern> ignoredRecipeTypes;
|
private final Set<Pattern> ignoredRecipeTypes;
|
||||||
private final Set<Pattern> ignoredRecipes;
|
private final Set<Pattern> ignoredRecipes;
|
||||||
private final boolean hideJeiRei;
|
private final boolean hideJeiRei;
|
||||||
|
|
||||||
public UnifyConfig(List<String> modPriorities, List<String> stoneStrata, List<String> unbakedTags, List<String> materials, Map<ResourceLocation, String> priorityOverrides, Set<UnifyTag<Item>> ignoredTags, Set<Pattern> ignoredRecipeTypes, Set<Pattern> ignoredRecipes, boolean hideJeiRei) {
|
public UnifyConfig(List<String> modPriorities, List<String> stoneStrata, List<String> unbakedTags, List<String> materials, Map<ResourceLocation, String> priorityOverrides, Set<UnifyTag<Item>> ignoredTags, Set<Pattern> ignoredItems, Set<Pattern> ignoredRecipeTypes, Set<Pattern> ignoredRecipes, boolean hideJeiRei) {
|
||||||
this.modPriorities = modPriorities;
|
this.modPriorities = modPriorities;
|
||||||
this.stoneStrata = stoneStrata;
|
this.stoneStrata = stoneStrata;
|
||||||
this.unbakedTags = unbakedTags;
|
this.unbakedTags = unbakedTags;
|
||||||
this.materials = materials;
|
this.materials = materials;
|
||||||
this.priorityOverrides = priorityOverrides;
|
this.priorityOverrides = priorityOverrides;
|
||||||
this.ignoredTags = ignoredTags;
|
this.ignoredTags = ignoredTags;
|
||||||
|
this.ignoredItems = ignoredItems;
|
||||||
this.ignoredRecipeTypes = ignoredRecipeTypes;
|
this.ignoredRecipeTypes = ignoredRecipeTypes;
|
||||||
this.ignoredRecipes = ignoredRecipes;
|
this.ignoredRecipes = ignoredRecipes;
|
||||||
this.hideJeiRei = hideJeiRei;
|
this.hideJeiRei = hideJeiRei;
|
||||||
|
@ -71,6 +73,10 @@ public class UnifyConfig extends Config {
|
||||||
return Collections.unmodifiableMap(priorityOverrides);
|
return Collections.unmodifiableMap(priorityOverrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean includeItem(ResourceLocation item) {
|
||||||
|
return ignoredItems.stream().noneMatch(pattern -> pattern.matcher(item.toString()).matches());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean includeRecipe(ResourceLocation recipe) {
|
public boolean includeRecipe(ResourceLocation recipe) {
|
||||||
return ignoredRecipes.stream().noneMatch(pattern -> pattern.matcher(recipe.toString()).matches());
|
return ignoredRecipes.stream().noneMatch(pattern -> pattern.matcher(recipe.toString()).matches());
|
||||||
}
|
}
|
||||||
|
@ -91,6 +97,7 @@ public class UnifyConfig extends Config {
|
||||||
public static final String MATERIALS = "materials";
|
public static final String MATERIALS = "materials";
|
||||||
public static final String PRIORITY_OVERRIDES = "priorityOverrides";
|
public static final String PRIORITY_OVERRIDES = "priorityOverrides";
|
||||||
public static final String IGNORED_TAGS = "ignoredTags";
|
public static final String IGNORED_TAGS = "ignoredTags";
|
||||||
|
public static final String IGNORED_ITEMS = "ignoredItems";
|
||||||
public static final String IGNORED_RECIPE_TYPES = "ignoredRecipeTypes";
|
public static final String IGNORED_RECIPE_TYPES = "ignoredRecipeTypes";
|
||||||
public static final String IGNORED_RECIPES = "ignoredRecipes";
|
public static final String IGNORED_RECIPES = "ignoredRecipes";
|
||||||
public static final String HIDE_JEI_REI = "itemsHidingJeiRei";
|
public static final String HIDE_JEI_REI = "itemsHidingJeiRei";
|
||||||
|
@ -118,6 +125,7 @@ public class UnifyConfig extends Config {
|
||||||
.stream()
|
.stream()
|
||||||
.map(s -> UnifyTag.item(new ResourceLocation(s)))
|
.map(s -> UnifyTag.item(new ResourceLocation(s)))
|
||||||
.collect(Collectors.toSet()), new HashSet<>());
|
.collect(Collectors.toSet()), new HashSet<>());
|
||||||
|
Set<Pattern> ignoredItems = deserializePatterns(json, IGNORED_ITEMS, List.of());
|
||||||
Set<Pattern> ignoredRecipeTypes = deserializePatterns(json,
|
Set<Pattern> ignoredRecipeTypes = deserializePatterns(json,
|
||||||
IGNORED_RECIPE_TYPES,
|
IGNORED_RECIPE_TYPES,
|
||||||
Defaults.getIgnoredRecipeTypes(AlmostUnifiedPlatform.INSTANCE.getPlatform()));
|
Defaults.getIgnoredRecipeTypes(AlmostUnifiedPlatform.INSTANCE.getPlatform()));
|
||||||
|
@ -131,6 +139,7 @@ public class UnifyConfig extends Config {
|
||||||
materials,
|
materials,
|
||||||
priorityOverrides,
|
priorityOverrides,
|
||||||
ignoredTags,
|
ignoredTags,
|
||||||
|
ignoredItems,
|
||||||
ignoredRecipeTypes,
|
ignoredRecipeTypes,
|
||||||
ignoredRecipes,
|
ignoredRecipes,
|
||||||
hideJeiRei
|
hideJeiRei
|
||||||
|
@ -155,6 +164,7 @@ public class UnifyConfig extends Config {
|
||||||
.map(UnifyTag::location)
|
.map(UnifyTag::location)
|
||||||
.map(ResourceLocation::toString)
|
.map(ResourceLocation::toString)
|
||||||
.toList()));
|
.toList()));
|
||||||
|
serializePatterns(json, IGNORED_ITEMS, config.ignoredItems);
|
||||||
serializePatterns(json, IGNORED_RECIPE_TYPES, config.ignoredRecipeTypes);
|
serializePatterns(json, IGNORED_RECIPE_TYPES, config.ignoredRecipeTypes);
|
||||||
serializePatterns(json, IGNORED_RECIPES, config.ignoredRecipes);
|
serializePatterns(json, IGNORED_RECIPES, config.ignoredRecipes);
|
||||||
json.add(HIDE_JEI_REI, new JsonPrimitive(config.hideJeiRei));
|
json.add(HIDE_JEI_REI, new JsonPrimitive(config.hideJeiRei));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.almostreliable.unified.utils;
|
package com.almostreliable.unified.utils;
|
||||||
|
|
||||||
import com.almostreliable.unified.AlmostUnified;
|
import com.almostreliable.unified.AlmostUnified;
|
||||||
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
import com.almostreliable.unified.api.StoneStrataHandler;
|
||||||
import com.almostreliable.unified.config.UnifyConfig;
|
import com.almostreliable.unified.config.UnifyConfig;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -11,42 +11,17 @@ import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ReplacementMap {
|
public class ReplacementMap {
|
||||||
private static final Pattern FABRIC_STRATA_PATTERN = Pattern.compile("(c:ores/.+|c:.+_ore)");
|
|
||||||
|
|
||||||
private final TagMap tagMap;
|
private final TagMap tagMap;
|
||||||
private final UnifyConfig unifyConfig;
|
private final UnifyConfig unifyConfig;
|
||||||
|
private final StoneStrataHandler stoneStrataHandler;
|
||||||
|
|
||||||
public ReplacementMap(TagMap tagMap, UnifyConfig unifyConfig) {
|
public ReplacementMap(TagMap tagMap, StoneStrataHandler stoneStrataHandler, UnifyConfig unifyConfig) {
|
||||||
this.tagMap = tagMap;
|
this.tagMap = tagMap;
|
||||||
this.unifyConfig = unifyConfig;
|
this.unifyConfig = unifyConfig;
|
||||||
}
|
this.stoneStrataHandler = stoneStrataHandler;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the stone strata from given item. Method works on the requirement that it's an item which has a stone strata.
|
|
||||||
* Use {@link #isStoneStrataTag(UnifyTag)} to fill this requirement.
|
|
||||||
*
|
|
||||||
* @param item The item to get the stone strata from.
|
|
||||||
* @return The stone strata of the item. Returning empty string means clean-stone strata.
|
|
||||||
*/
|
|
||||||
private String getStoneStrata(ResourceLocation item) {
|
|
||||||
for (String stone : unifyConfig.getStoneStrata()) {
|
|
||||||
if (item.getPath().contains(stone + "_")) {
|
|
||||||
return stone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isStoneStrataTag(UnifyTag<Item> tag) {
|
|
||||||
String tagString = tag.location().toString();
|
|
||||||
return switch (AlmostUnifiedPlatform.INSTANCE.getPlatform()) {
|
|
||||||
case FORGE -> tagString.startsWith("forge:ores/");
|
|
||||||
case FABRIC -> FABRIC_STRATA_PATTERN.matcher(tagString).matches();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -74,9 +49,9 @@ public class ReplacementMap {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStoneStrataTag(t)) {
|
if (stoneStrataHandler.isStoneStrataTag(t)) {
|
||||||
String stone = getStoneStrata(item);
|
String stone = stoneStrataHandler.getStoneStrata(item);
|
||||||
return getPreferredItemForTag(t, i -> stone.equals(getStoneStrata(i)));
|
return getPreferredItemForTag(t, i -> stone.equals(stoneStrataHandler.getStoneStrata(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return getPreferredItemForTag(t, i -> true);
|
return getPreferredItemForTag(t, i -> true);
|
||||||
|
|
|
@ -31,13 +31,18 @@ public class TagMap {
|
||||||
return tagMap;
|
return tagMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TagMap create(TagManager tagManager, Predicate<UnifyTag<Item>> filter) {
|
/**
|
||||||
|
* Creates a {@link TagMap} from a vanilla {@link TagManager}.
|
||||||
|
*
|
||||||
|
* @param tagManager The vanilla tag manager.
|
||||||
|
* @return A new {@link TagMap}.
|
||||||
|
*/
|
||||||
|
public static TagMap create(TagManager tagManager) {
|
||||||
Objects.requireNonNull(tagManager, "Requires a non-null tag manager");
|
Objects.requireNonNull(tagManager, "Requires a non-null tag manager");
|
||||||
|
|
||||||
var tags = tagManager
|
var tags = tagManager
|
||||||
.getResult()
|
.getResult()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(result -> result.key().equals(Registry.ITEM_REGISTRY))
|
.filter(result -> result.key() == Registry.ITEM_REGISTRY)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(TagManager.LoadResult::tags)
|
.map(TagManager.LoadResult::tags)
|
||||||
.orElseThrow(() -> new IllegalStateException("No item tag result found"));
|
.orElseThrow(() -> new IllegalStateException("No item tag result found"));
|
||||||
|
@ -46,12 +51,7 @@ public class TagMap {
|
||||||
|
|
||||||
for (var entry : tags.entrySet()) {
|
for (var entry : tags.entrySet()) {
|
||||||
UnifyTag<Item> tag = UnifyTag.item(entry.getKey());
|
UnifyTag<Item> tag = UnifyTag.item(entry.getKey());
|
||||||
if (!filter.test(tag)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var holderTag = entry.getValue();
|
var holderTag = entry.getValue();
|
||||||
|
|
||||||
for (Holder<?> holder : holderTag) {
|
for (Holder<?> holder : holderTag) {
|
||||||
holder
|
holder
|
||||||
.unwrapKey()
|
.unwrapKey()
|
||||||
|
@ -60,6 +60,25 @@ public class TagMap {
|
||||||
.ifPresent(itemId -> tagMap.put(tag, itemId));
|
.ifPresent(itemId -> tagMap.put(tag, itemId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tagMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a filtered {@link TagMap}.
|
||||||
|
*
|
||||||
|
* @param tagFilter A filter to determine which tags to include.
|
||||||
|
* @param itemFilter A filter to determine which items to include.
|
||||||
|
* @return A new {@link TagMap}.
|
||||||
|
*/
|
||||||
|
public TagMap filtered(Predicate<UnifyTag<Item>> tagFilter, Predicate<ResourceLocation> itemFilter) {
|
||||||
|
TagMap tagMap = new TagMap();
|
||||||
|
|
||||||
|
tagsToItems.forEach((tag, items) -> {
|
||||||
|
if (!tagFilter.test(tag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
items.stream().filter(itemFilter).forEach(item -> tagMap.put(tag, item));
|
||||||
|
});
|
||||||
|
|
||||||
return tagMap;
|
return tagMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
|
import com.almostreliable.unified.api.StoneStrataHandler;
|
||||||
import com.almostreliable.unified.config.Defaults;
|
import com.almostreliable.unified.config.Defaults;
|
||||||
import com.almostreliable.unified.config.UnifyConfig;
|
import com.almostreliable.unified.config.UnifyConfig;
|
||||||
import com.almostreliable.unified.recipe.RecipeTransformer;
|
import com.almostreliable.unified.recipe.RecipeTransformer;
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
import com.almostreliable.unified.utils.ReplacementMap;
|
import com.almostreliable.unified.utils.ReplacementMap;
|
||||||
|
import com.almostreliable.unified.utils.TagMap;
|
||||||
import com.almostreliable.unified.utils.TagMapTests;
|
import com.almostreliable.unified.utils.TagMapTests;
|
||||||
import com.almostreliable.unified.utils.UnifyTag;
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
@ -17,6 +19,7 @@ import net.minecraft.world.item.Item;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
|
@ -38,6 +41,7 @@ public class TestUtils {
|
||||||
new HashSet<>(),
|
new HashSet<>(),
|
||||||
new HashSet<>(),
|
new HashSet<>(),
|
||||||
new HashSet<>(),
|
new HashSet<>(),
|
||||||
|
new HashSet<>(),
|
||||||
true);
|
true);
|
||||||
public static final ResourceKey<Registry<Item>> FAKE_ITEM_REGISTRY = FakeResourceKeyRegistry.create("item");
|
public static final ResourceKey<Registry<Item>> FAKE_ITEM_REGISTRY = FakeResourceKeyRegistry.create("item");
|
||||||
public static final UnifyTag<Item> BRONZE_ORES_TAG = tag("forge:ores/bronze");
|
public static final UnifyTag<Item> BRONZE_ORES_TAG = tag("forge:ores/bronze");
|
||||||
|
@ -79,8 +83,14 @@ public class TestUtils {
|
||||||
return new ResourceLocation(TEST_MOD_5, name);
|
return new ResourceLocation(TEST_MOD_5, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StoneStrataHandler createTestStrataHandler() {
|
||||||
|
return StoneStrataHandler.create(List.of(), Set.of(), TagMap.create(List.of()));
|
||||||
|
}
|
||||||
|
|
||||||
public static RecipeTransformer basicTransformer(Consumer<RecipeHandlerFactory> consumer) {
|
public static RecipeTransformer basicTransformer(Consumer<RecipeHandlerFactory> consumer) {
|
||||||
ReplacementMap map = new ReplacementMap(TagMapTests.testTagMap(), DEFAULT_UNIFY_CONFIG);
|
ReplacementMap map = new ReplacementMap(TagMapTests.testTagMap(),
|
||||||
|
createTestStrataHandler(),
|
||||||
|
DEFAULT_UNIFY_CONFIG);
|
||||||
RecipeHandlerFactory factory = new RecipeHandlerFactory();
|
RecipeHandlerFactory factory = new RecipeHandlerFactory();
|
||||||
consumer.accept(factory);
|
consumer.accept(factory);
|
||||||
return new RecipeTransformer(factory, map, DEFAULT_UNIFY_CONFIG, null);
|
return new RecipeTransformer(factory, map, DEFAULT_UNIFY_CONFIG, null);
|
||||||
|
|
|
@ -3,11 +3,15 @@ package com.almostreliable.unified;
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
import com.almostreliable.unified.api.ModConstants;
|
||||||
import com.almostreliable.unified.compat.AmethystImbuementRecipeUnifier;
|
import com.almostreliable.unified.compat.AmethystImbuementRecipeUnifier;
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@AutoService(AlmostUnifiedPlatform.class)
|
@AutoService(AlmostUnifiedPlatform.class)
|
||||||
public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
|
public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
|
||||||
|
@ -46,4 +50,9 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
|
||||||
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
||||||
factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier());
|
factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<UnifyTag<Item>> getStoneStrataTags(List<String> stoneStrataIds) {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@ package com.almostreliable.unified;
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
import com.almostreliable.unified.api.ModConstants;
|
||||||
import com.almostreliable.unified.compat.IERecipeUnifier;
|
import com.almostreliable.unified.compat.IERecipeUnifier;
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.loading.FMLLoader;
|
import net.minecraftforge.fml.loading.FMLLoader;
|
||||||
|
@ -12,6 +15,9 @@ import net.minecraftforge.fml.loading.LoadingModList;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@AutoService(AlmostUnifiedPlatform.class)
|
@AutoService(AlmostUnifiedPlatform.class)
|
||||||
public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
||||||
|
@ -53,4 +59,13 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
||||||
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
||||||
factory.registerForMod(ModConstants.IE, new IERecipeUnifier());
|
factory.registerForMod(ModConstants.IE, new IERecipeUnifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<UnifyTag<Item>> getStoneStrataTags(List<String> stoneStrataIds) {
|
||||||
|
return stoneStrataIds
|
||||||
|
.stream()
|
||||||
|
.map(id -> new ResourceLocation("forge", "ores_in_ground/" + id))
|
||||||
|
.map(UnifyTag::item)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue