mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-24 08:37:55 -05:00
Add MissingRecipesDumper
This commit is contained in:
parent
ddc29a2f01
commit
20472767e1
3 changed files with 104 additions and 2 deletions
|
@ -7,6 +7,7 @@ import com.almostreliable.unified.config.UnifyConfig;
|
|||
import com.almostreliable.unified.recipe.RecipeDumper;
|
||||
import com.almostreliable.unified.recipe.RecipeTransformer;
|
||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||
import com.almostreliable.unified.utils.MissingRecipesDumper;
|
||||
import com.almostreliable.unified.utils.ReplacementMap;
|
||||
import com.almostreliable.unified.utils.TagMap;
|
||||
import com.google.gson.JsonElement;
|
||||
|
@ -55,6 +56,7 @@ public final class AlmostUnifiedRuntimeImpl implements AlmostUnifiedRuntime {
|
|||
dumper.dump(debugConfig.dumpOverview, debugConfig.dumpUnification, debugConfig.dumpDuplicates);
|
||||
|
||||
debugConfig.logRecipes(recipes, "recipes_after_unification.txt");
|
||||
MissingRecipesDumper.write(this, debugConfig.dumpPotentialMissingRecipes, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,13 +21,15 @@ public class DebugConfig extends Config {
|
|||
public final boolean dumpUnification;
|
||||
public final boolean dumpOverview;
|
||||
public final boolean dumpRecipes;
|
||||
public final boolean dumpPotentialMissingRecipes;
|
||||
|
||||
public DebugConfig(boolean dumpTagMap, boolean dumpDuplicates, boolean dumpUnification, boolean dumpOverview, boolean dumpRecipes) {
|
||||
public DebugConfig(boolean dumpTagMap, boolean dumpDuplicates, boolean dumpUnification, boolean dumpOverview, boolean dumpRecipes, boolean dumpPotentialMissingRecipes) {
|
||||
this.dumpTagMap = dumpTagMap;
|
||||
this.dumpDuplicates = dumpDuplicates;
|
||||
this.dumpUnification = dumpUnification;
|
||||
this.dumpOverview = dumpOverview;
|
||||
this.dumpRecipes = dumpRecipes;
|
||||
this.dumpPotentialMissingRecipes = dumpPotentialMissingRecipes;
|
||||
}
|
||||
|
||||
public void logUnifyTagDump(TagMap<Item> tagMap) {
|
||||
|
@ -71,6 +73,7 @@ public class DebugConfig extends Config {
|
|||
public static final String DUMP_UNIFICATION = "dumpUnification";
|
||||
public static final String DUMP_OVERVIEW = "dumpOverview";
|
||||
public static final String DUMP_RECIPES = "dumpRecipes";
|
||||
public static final String DUMP_POTENTIAL_MISSING_RECIPES = "dumpPotentialMissingRecipes";
|
||||
|
||||
@Override
|
||||
public DebugConfig deserialize(JsonObject json) {
|
||||
|
@ -79,7 +82,8 @@ public class DebugConfig extends Config {
|
|||
safeGet(() -> json.get(DUMP_DUPLICATES).getAsBoolean(), false),
|
||||
safeGet(() -> json.get(DUMP_UNIFICATION).getAsBoolean(), false),
|
||||
safeGet(() -> json.get(DUMP_OVERVIEW).getAsBoolean(), false),
|
||||
safeGet(() -> json.get(DUMP_RECIPES).getAsBoolean(), false)
|
||||
safeGet(() -> json.get(DUMP_RECIPES).getAsBoolean(), false),
|
||||
safeGet(() -> json.get(DUMP_POTENTIAL_MISSING_RECIPES).getAsBoolean(), false)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -91,6 +95,7 @@ public class DebugConfig extends Config {
|
|||
json.addProperty(DUMP_UNIFICATION, src.dumpUnification);
|
||||
json.addProperty(DUMP_OVERVIEW, src.dumpOverview);
|
||||
json.addProperty(DUMP_RECIPES, src.dumpRecipes);
|
||||
json.addProperty(DUMP_POTENTIAL_MISSING_RECIPES, src.dumpPotentialMissingRecipes);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package com.almostreliable.unified.utils;
|
||||
|
||||
import com.almostreliable.unified.AlmostUnifiedPlatform;
|
||||
import com.almostreliable.unified.AlmostUnifiedRuntime;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class MissingRecipesDumper {
|
||||
|
||||
public static void write(AlmostUnifiedRuntime runtime, boolean dumpPotentialMissingRecipes, Map<ResourceLocation, JsonElement> recipes) {
|
||||
if (!dumpPotentialMissingRecipes) return;
|
||||
|
||||
var itemsPerTag = getHidingIds(runtime);
|
||||
FileUtils.write(AlmostUnifiedPlatform.INSTANCE.getLogPath(), "recipe_hiding_check.txt", sb -> {
|
||||
recipes.forEach(((recipe, json) -> {
|
||||
if (json instanceof JsonObject obj) {
|
||||
write(recipe, obj, itemsPerTag, sb);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private static void write(ResourceLocation recipe, JsonObject json, Multimap<UnifyTag<Item>, ResourceLocation> itemsPerTag, StringBuilder sb) {
|
||||
String jsonStr = json.toString();
|
||||
Multimap<UnifyTag<Item>, ResourceLocation> found = HashMultimap.create();
|
||||
itemsPerTag.asMap().forEach((tag, items) -> {
|
||||
for (ResourceLocation item : items) {
|
||||
if (jsonStr.contains(item.toString())) {
|
||||
found.put(tag, item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (found.isEmpty()) return;
|
||||
|
||||
String type = Optional.ofNullable(json.get("type")).map(JsonElement::getAsString).orElse("");
|
||||
sb
|
||||
.append("Recipe ")
|
||||
.append(recipe)
|
||||
.append(" (")
|
||||
.append(type)
|
||||
.append(") contains potentially hiding items:")
|
||||
.append("\n")
|
||||
.append("Json: ")
|
||||
.append(jsonStr)
|
||||
.append("\n")
|
||||
.append("Items: ")
|
||||
.append("\n");
|
||||
found.asMap().forEach((tag, items) -> {
|
||||
for (ResourceLocation item : items) {
|
||||
sb.append("\t").append(item).append(" (#").append(tag.location()).append(")").append("\n");
|
||||
}
|
||||
});
|
||||
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
|
||||
public static Multimap<UnifyTag<Item>, ResourceLocation> getHidingIds(AlmostUnifiedRuntime runtime) {
|
||||
ReplacementMap repMap = runtime.getReplacementMap().orElse(null);
|
||||
var tagMap = runtime.getFilteredTagMap().orElse(null);
|
||||
|
||||
Multimap<UnifyTag<Item>, ResourceLocation> hidings = HashMultimap.create();
|
||||
if (repMap == null || tagMap == null) return hidings;
|
||||
|
||||
for (var unifyTag : tagMap.getTags()) {
|
||||
var itemsByTag = tagMap.getEntriesByTag(unifyTag);
|
||||
|
||||
if (Utils.allSameNamespace(itemsByTag)) continue;
|
||||
|
||||
ResourceLocation kingItem = repMap.getPreferredItemForTag(unifyTag, $ -> true);
|
||||
if (kingItem == null) continue;
|
||||
|
||||
Set<ResourceLocation> r = new HashSet<>();
|
||||
for (ResourceLocation item : itemsByTag) {
|
||||
if (!item.equals(kingItem)) {
|
||||
r.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
hidings.putAll(unifyTag, r);
|
||||
}
|
||||
|
||||
return hidings;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue