From a58923cc0bab347f7c88abff62cb5fe76e690e3f Mon Sep 17 00:00:00 2001 From: miozune Date: Wed, 25 Jan 2023 22:46:25 +0900 Subject: [PATCH] Add recipe debugger for recipes with small variant of items --- .../recipedebugger/DiagramHandler.java | 3 + .../GregTechRecipeDebugger.java | 10 +++- .../recipedebugger/LayoutFactory.java | 1 + .../recipedebugger/RecipeHandler.java | 57 +++++++++++++++++++ .../assets/neicustomdiagram/lang/en_US.lang | 1 + 5 files changed, 71 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..a5eff60 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,9 @@ 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_OreDictUnificator; import gregtech.api.util.GT_Utility; import java.util.Arrays; import java.util.Collection; @@ -45,7 +48,12 @@ public enum View { UNEQUAL_CELL_RECIPES( "-unequal-cell-recipes", GregTechOreDictUtil.getComponent(ItemList.Cell_Empty), - "unequalcellrecipesbutton"); + "unequalcellrecipesbutton"), + + SMALL_VARIANT_RECIPES( + "-small-variant-recipes", + ItemComponent.create(GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Salt, 1)), + "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..fd782d1 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,6 +13,8 @@ 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.objects.ItemData; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; @@ -220,6 +222,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 +231,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 +280,10 @@ void initialize() { if (unequalCellRecipe(recipe)) { unequalCellRecipes.add(recipe); } + + if (SmallVariantRecipe(recipe)) { + smallVariantRecipes.add(recipe); + } } } } @@ -411,4 +419,53 @@ private static boolean unequalCellRecipe(Recipe recipe) { return countCells(recipe.inputs()) != countCells(recipe.outputs()); } + + private static boolean SmallVariantRecipe(Recipe recipe) { + if (recipe.recipeMap() == RecipeMap.PACKAGER + || recipe.recipeMap() == RecipeMap.UNPACKAGER + || recipe.recipeMap() == RecipeMap.MACERATOR + || recipe.recipeMap() == RecipeMap.LATHE + || recipe.recipeMap() == RecipeMap.FLUID_EXTRACTOR + || recipe.recipeMap() == RecipeMap.IMPLOSION_COMPRESSOR + || recipe.recipeMap() == RecipeMap.ALLOY_SMELTER) { + // These recipemaps are meant to have tiny / small dusts or nuggets. + return false; + } + if (recipe.recipeMap() == RecipeMap.ASSEMBLING_MACHINE) { + List components = new ArrayList<>(recipe.outputs().keySet()); + if (components.size() > 0) { + Component component = components.get(0); + if (component.type() == Component.ComponentType.ITEM) { + ItemStack itemStack = ((ItemComponent) component).stack(); + ItemData itemData = GT_OreDictUnificator.getAssociation(itemStack); + if (itemData != null + && (itemData.mPrefix == OrePrefixes.cableGt01 + || itemData.mPrefix == OrePrefixes.cableGt02 + || itemData.mPrefix == OrePrefixes.cableGt04 + || itemData.mPrefix == OrePrefixes.cableGt08 + || itemData.mPrefix == OrePrefixes.cableGt12 + || itemData.mPrefix == OrePrefixes.cableGt16)) { + // Allow using small dusts for cable insulation. + return false; + } + } + } + } + return hasSmallVariant(recipe.inputs()) || hasSmallVariant(recipe.outputs()); + } + + private static boolean hasSmallVariant(Map componentMap) { + for (Component component : componentMap.keySet()) { + if (component.type() != Component.ComponentType.ITEM) continue; + ItemStack itemStack = ((ItemComponent) component).stack(); + ItemData itemData = GT_OreDictUnificator.getAssociation(itemStack); + if (itemData == null) continue; + if (itemData.mPrefix == OrePrefixes.dustTiny + || itemData.mPrefix == OrePrefixes.dustSmall + || itemData.mPrefix == OrePrefixes.nugget) { + return true; + } + } + return false; + } } 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