Skip to content

Commit

Permalink
Add recipe debugger for recipes with small variant of items (#18)
Browse files Browse the repository at this point in the history
* Add recipe debugger for recipes with small variant of items

* Address reviews
  • Loading branch information
miozune authored Jan 26, 2023
1 parent d460ab1 commit dc2e77e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,6 +223,7 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) {
final Set<Recipe> collidingRecipes;
final List<Recipe> voidingRecipes;
final List<Recipe> unequalCellRecipes;
final List<Recipe> smallVariantRecipes;

RecipeHandler() {
this.allRecipes = new HashMap<>();
Expand All @@ -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. */
Expand Down Expand Up @@ -276,6 +281,10 @@ void initialize() {
if (unequalCellRecipe(recipe)) {
unequalCellRecipes.add(recipe);
}

if (smallVariantRecipe(recipe)) {
smallVariantRecipes.add(recipe);
}
}
}
}
Expand Down Expand Up @@ -411,4 +420,47 @@ private static boolean unequalCellRecipe(Recipe recipe) {

return countCells(recipe.inputs()) != countCells(recipe.outputs());
}

private static final ImmutableSet<OrePrefixes> SMALL_VARIANT_ORE_PREFIXES =
ImmutableSet.of(OrePrefixes.dustTiny, OrePrefixes.dustSmall, OrePrefixes.nugget);
private static final ImmutableSet<OrePrefixes> CABLE_ORE_PREFIXES = ImmutableSet.of(
OrePrefixes.cableGt01,
OrePrefixes.cableGt02,
OrePrefixes.cableGt04,
OrePrefixes.cableGt08,
OrePrefixes.cableGt12,
OrePrefixes.cableGt16);
private static final ImmutableSet<RecipeMap> 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> 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<OrePrefixes> getOrePrefixes(Set<Component> 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));
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/neicustomdiagram/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/neicustomdiagram/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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=压缩机合成表
Expand Down

0 comments on commit dc2e77e

Please sign in to comment.