From dc2e77e5130df11c68b5275b0690a129eda7a3fa Mon Sep 17 00:00:00 2001 From: miozune Date: Thu, 26 Jan 2023 14:39:07 +0900 Subject: [PATCH] Add recipe debugger for recipes with small variant of items (#18) * Add recipe debugger for recipes with small variant of items * Address reviews --- .../recipedebugger/DiagramHandler.java | 3 ++ .../GregTechRecipeDebugger.java | 10 +++- .../recipedebugger/LayoutFactory.java | 1 + .../recipedebugger/RecipeHandler.java | 52 +++++++++++++++++++ .../assets/neicustomdiagram/lang/en_US.lang | 1 + .../assets/neicustomdiagram/lang/zh_CN.lang | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/DiagramHandler.java b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/DiagramHandler.java index f218145..70e9dbc 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/DiagramHandler.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/DiagramHandler.java @@ -53,6 +53,9 @@ void initialize() { diagramListMultimap.putAll( GregTechRecipeDebugger.View.UNEQUAL_CELL_RECIPES, buildRecipeDiagrams(recipeHandler.unequalCellRecipes)); + diagramListMultimap.putAll( + GregTechRecipeDebugger.View.SMALL_VARIANT_RECIPES, + buildRecipeDiagrams(recipeHandler.smallVariantRecipes)); // This must be last, as it reads counts from diagramListMultimap. menuDiagram = buildMenuDiagram(); diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/GregTechRecipeDebugger.java b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/GregTechRecipeDebugger.java index d715840..3d5fb18 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/GregTechRecipeDebugger.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/GregTechRecipeDebugger.java @@ -14,6 +14,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_Utility; import java.util.Arrays; import java.util.Collection; @@ -45,7 +47,13 @@ public enum View { UNEQUAL_CELL_RECIPES( "-unequal-cell-recipes", GregTechOreDictUtil.getComponent(ItemList.Cell_Empty), - "unequalcellrecipesbutton"); + "unequalcellrecipesbutton"), + + SMALL_VARIANT_RECIPES( + "-small-variant-recipes", + GregTechOreDictUtil.getComponent(OrePrefixes.dustTiny, Materials.Salt) + .get(), + "smallvariantrecipesbutton"); /** The suffix to append to the group ID, to get the custom behavior ID for this view. */ public final String suffix; diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/LayoutFactory.java b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/LayoutFactory.java index 3322d73..744bf26 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/LayoutFactory.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/LayoutFactory.java @@ -26,6 +26,7 @@ class LayoutFactory { .put(GregTechRecipeDebugger.View.COLLIDING_RECIPES, Grid.GRID.grid(6, 2)) .put(GregTechRecipeDebugger.View.VOIDING_RECIPES, Grid.GRID.grid(8, 2)) .put(GregTechRecipeDebugger.View.UNEQUAL_CELL_RECIPES, Grid.GRID.grid(10, 2)) + .put(GregTechRecipeDebugger.View.SMALL_VARIANT_RECIPES, Grid.GRID.grid(12, 2)) .build(); static final class SlotGroupKeys { diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/RecipeHandler.java b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/RecipeHandler.java index 867ae60..4ccc258 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/RecipeHandler.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/generators/gregtech5/recipedebugger/RecipeHandler.java @@ -13,15 +13,18 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import gregtech.api.enums.ItemList; +import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -220,6 +223,7 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) { final Set collidingRecipes; final List voidingRecipes; final List unequalCellRecipes; + final List smallVariantRecipes; RecipeHandler() { this.allRecipes = new HashMap<>(); @@ -228,6 +232,7 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) { this.collidingRecipes = new LinkedHashSet<>(); this.voidingRecipes = new ArrayList<>(); this.unequalCellRecipes = new ArrayList<>(); + this.smallVariantRecipes = new ArrayList<>(); } /** This method must be called before any other methods are called. */ @@ -276,6 +281,10 @@ void initialize() { if (unequalCellRecipe(recipe)) { unequalCellRecipes.add(recipe); } + + if (smallVariantRecipe(recipe)) { + smallVariantRecipes.add(recipe); + } } } } @@ -411,4 +420,47 @@ private static boolean unequalCellRecipe(Recipe recipe) { return countCells(recipe.inputs()) != countCells(recipe.outputs()); } + + private static final ImmutableSet SMALL_VARIANT_ORE_PREFIXES = + ImmutableSet.of(OrePrefixes.dustTiny, OrePrefixes.dustSmall, OrePrefixes.nugget); + private static final ImmutableSet CABLE_ORE_PREFIXES = ImmutableSet.of( + OrePrefixes.cableGt01, + OrePrefixes.cableGt02, + OrePrefixes.cableGt04, + OrePrefixes.cableGt08, + OrePrefixes.cableGt12, + OrePrefixes.cableGt16); + private static final ImmutableSet RECIPE_MAPS_TO_IGNORE_FOR_SMALL_VARIANT = ImmutableSet.of( + // These recipemaps are meant to have tiny / small dusts or nuggets. + RecipeMap.PACKAGER, + RecipeMap.UNPACKAGER, + RecipeMap.MACERATOR, + RecipeMap.LATHE, + RecipeMap.FLUID_EXTRACTOR, + RecipeMap.IMPLOSION_COMPRESSOR, + RecipeMap.ALLOY_SMELTER); + + private static boolean smallVariantRecipe(Recipe recipe) { + if (RECIPE_MAPS_TO_IGNORE_FOR_SMALL_VARIANT.contains(recipe.recipeMap())) { + return false; + } + + Set orePrefixes = getOrePrefixes(recipe.outputs().keySet()); + if (recipe.recipeMap() == RecipeMap.ASSEMBLING_MACHINE + && Sets.intersection(orePrefixes, CABLE_ORE_PREFIXES).size() > 0) { + // Allow using small dusts for cable insulation. + return false; + } else { + orePrefixes.addAll(getOrePrefixes(recipe.inputs().keySet())); + return Sets.intersection(orePrefixes, SMALL_VARIANT_ORE_PREFIXES).size() > 0; + } + } + + private static Set getOrePrefixes(Set componentSet) { + return componentSet.stream() + .map(GregTechOreDictUtil::getItemData) // Checks for ComponentType.ITEM for us + .filter(Optional::isPresent) + .map(itemData -> itemData.get().mPrefix) + .collect(Collectors.toCollection(HashSet::new)); + } } diff --git a/src/main/resources/assets/neicustomdiagram/lang/en_US.lang b/src/main/resources/assets/neicustomdiagram/lang/en_US.lang index eb2daff..6bfac57 100644 --- a/src/main/resources/assets/neicustomdiagram/lang/en_US.lang +++ b/src/main/resources/assets/neicustomdiagram/lang/en_US.lang @@ -208,6 +208,7 @@ neicustomdiagram.generators.gregtech5.recipedebugger.unnecessarycircuitrecipesbu neicustomdiagram.generators.gregtech5.recipedebugger.collidingrecipesbutton=Recipes with colliding inputs neicustomdiagram.generators.gregtech5.recipedebugger.voidingrecipesbutton=Recipes which void inputs neicustomdiagram.generators.gregtech5.recipedebugger.unequalcellrecipesbutton=Recipes which output unequal cells +neicustomdiagram.generators.gregtech5.recipedebugger.smallvariantrecipesbutton=Recipes with tiny / small dusts or nuggets neicustomdiagram.generators.gregtech5.recipedebugger.orewashingplantlabel=Ore Washing Plant recipe neicustomdiagram.generators.gregtech5.recipedebugger.thermalcentrifugelabel=Thermal Centrifuge recipe neicustomdiagram.generators.gregtech5.recipedebugger.compressorlabel=Compressor recipe diff --git a/src/main/resources/assets/neicustomdiagram/lang/zh_CN.lang b/src/main/resources/assets/neicustomdiagram/lang/zh_CN.lang index 281b19b..f6d4f70 100644 --- a/src/main/resources/assets/neicustomdiagram/lang/zh_CN.lang +++ b/src/main/resources/assets/neicustomdiagram/lang/zh_CN.lang @@ -208,6 +208,7 @@ neicustomdiagram.generators.gregtech5.recipedebugger.unnecessarycircuitrecipesbu neicustomdiagram.generators.gregtech5.recipedebugger.collidingrecipesbutton=输入冲突的合成表 neicustomdiagram.generators.gregtech5.recipedebugger.voidingrecipesbutton=销毁输入的合成表 neicustomdiagram.generators.gregtech5.recipedebugger.unequalcellrecipesbutton=输出不等单元的合成表 +neicustomdiagram.generators.gregtech5.recipedebugger.smallvariantrecipesbutton=Recipes with tiny / small dusts or nuggets neicustomdiagram.generators.gregtech5.recipedebugger.orewashingplantlabel=洗矿机合成表 neicustomdiagram.generators.gregtech5.recipedebugger.thermalcentrifugelabel=热力离心机合成表 neicustomdiagram.generators.gregtech5.recipedebugger.compressorlabel=压缩机合成表