Skip to content

Commit

Permalink
Merge v1.5.4 from upstream (#24)
Browse files Browse the repository at this point in the history
Manual merge of these commits:
 * D-Cysteine@8eaa601
 * D-Cysteine@91c645a
  • Loading branch information
D-Cysteine committed Apr 28, 2023
1 parent 407ab6a commit 4e3e16a
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ void initialize() {
diagramListMultimap.putAll(
GregTechRecipeDebugger.View.SMALL_VARIANT_RECIPES,
buildRecipeDiagrams(recipeHandler.smallVariantRecipes));
diagramListMultimap.putAll(
GregTechRecipeDebugger.View.BAD_CRAFTING_TABLE_RECIPES,
buildRecipeDiagrams(recipeHandler.badCraftingTableRecipes));

// 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 @@ -5,6 +5,7 @@
import java.util.List;
import java.util.function.Supplier;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;

import com.github.dcysteine.neicustomdiagram.api.diagram.CustomDiagramGroup;
Expand All @@ -30,6 +31,9 @@ public final class GregTechRecipeDebugger implements DiagramGenerator {

public static final ItemComponent ICON = ItemComponent.create(GT_Utility.getIntegratedCircuit(0));

// TODO if we need to add more views in the future, it'd probably be worth going through and
// refactoring the code to clean it up a bit. I want to move each view into a custom class, with
// each view class containing its own recipe checking code, as well as recipe map exclusions.
public enum View {

PROGRAMMED_CIRCUITS("-programmed-circuits", ItemComponent.create(GT_Utility.getIntegratedCircuit(24)),
Expand All @@ -50,7 +54,10 @@ public enum View {

SMALL_VARIANT_RECIPES("-small-variant-recipes",
GregTechOreDictUtil.getComponent(OrePrefixes.dustTiny, Materials.Salt).get(),
"smallvariantrecipesbutton"),;
"smallvariantrecipesbutton"),

BAD_CRAFTING_TABLE_RECIPES("-bad-crafting-table-recipes", ItemComponent.create(Blocks.crafting_table, 0).get(),
"badcraftingtablerecipesbutton"),;

/** 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 @@ -27,7 +27,8 @@ 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();
.put(GregTechRecipeDebugger.View.SMALL_VARIANT_RECIPES, Grid.GRID.grid(12, 2))
.put(GregTechRecipeDebugger.View.BAD_CRAFTING_TABLE_RECIPES, Grid.GRID.grid(0, 4)).build();

static final class SlotGroupKeys {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package com.github.dcysteine.neicustomdiagram.generators.gregtech5.recipedebugger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.annotation.Nullable;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;

import com.github.dcysteine.neicustomdiagram.api.diagram.component.Component;
import com.github.dcysteine.neicustomdiagram.api.diagram.component.DisplayComponent;
import com.github.dcysteine.neicustomdiagram.api.diagram.component.FluidComponent;
import com.github.dcysteine.neicustomdiagram.api.diagram.component.ItemComponent;
import com.github.dcysteine.neicustomdiagram.api.diagram.tooltip.Tooltip;
import com.github.dcysteine.neicustomdiagram.main.Lang;
import com.github.dcysteine.neicustomdiagram.main.Logger;
import com.github.dcysteine.neicustomdiagram.util.gregtech5.GregTechOreDictUtil;
import com.github.dcysteine.neicustomdiagram.util.gregtech5.GregTechRecipeUtil;
Expand All @@ -28,6 +40,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import codechicken.nei.NEIServerUtils;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.util.GT_ModHandler;
Expand Down Expand Up @@ -68,6 +81,16 @@ class RecipeHandler {

enum RecipeMap {

/**
* Crafting table recipes.
*
* <p>
* This is the only enum entry which will have null {@code recipeMap}, since it doesn't correspond to a GT5
* recipe map. Currently, we only use this value to be able to check for crafting table recipes containing a bad
* {@link ItemStack} which has a null {@link Item}.
*/
CRAFTING_TABLE(null, ItemList.Schematic_Crafting, "craftingtablelabel"),

ORE_WASHING_PLANT(GT_Recipe.GT_Recipe_Map.sOreWasherRecipes, ItemList.Machine_HV_OreWasher,
"orewashingplantlabel"),
THERMAL_CENTRIFUGE(GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes, ItemList.Machine_HV_ThermalCentrifuge,
Expand Down Expand Up @@ -109,11 +132,21 @@ enum RecipeMap {
PACKAGER(GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes, ItemList.Machine_HV_Boxinator, "packagerlabel"),
UNPACKAGER(GT_Recipe.GT_Recipe_Map.sUnboxinatorRecipes, ItemList.Machine_HV_Unboxinator, "unpackagerlabel"),
FUSION_REACTOR(GT_Recipe.GT_Recipe_Map.sFusionRecipes, ItemList.FusionComputer_LuV, "fusionreactorlabel"),
COMPLEX_FUSION_REACTOR(GT_Recipe.GT_Recipe_Map.sComplexFusionRecipes, ItemList.FusionComputer_UV,
"complexfusionreactorlabel"),
CENTRIFUGE(GT_Recipe.GT_Recipe_Map.sCentrifugeRecipes, ItemList.Machine_HV_Centrifuge, "centrifugelabel"),
ELECTROLYZER(GT_Recipe.GT_Recipe_Map.sElectrolyzerRecipes, ItemList.Machine_HV_Electrolyzer,
"electrolyzerlabel"),
ELECTRIC_BLAST_FURNACE(GT_Recipe.GT_Recipe_Map.sBlastRecipes, ItemList.Machine_Multi_BlastFurnace,
"electricblastfurnacelabel"),
PLASMA_FORGE(GT_Recipe.GT_Recipe_Map.sPlasmaForgeRecipes, ItemList.Machine_Multi_PlasmaForge,
"plasmaforgelabel"),
// Commenting this one out for now, for backward compatibility. Uncomment later.
/*
* TRANSCENDENT_PLASMA_MIXER( GT_Recipe.GT_Recipe_Map.sTranscendentPlasmaMixerRecipes,
* ItemList.Machine_Multi_TranscendentPlasmaMixer, "transcendentplasmamixerlabel"),
*/
// Fake Space Project
BRICKED_BLAST_FURNACE(GT_Recipe.GT_Recipe_Map.sPrimitiveBlastRecipes, ItemList.Machine_Bricked_BlastFurnace,
"brickedblastfurnacelabel"),
IMPLOSION_COMPRESSOR(GT_Recipe.GT_Recipe_Map.sImplosionRecipes, ItemList.Machine_Multi_ImplosionCompressor,
Expand Down Expand Up @@ -142,14 +175,19 @@ enum RecipeMap {
CUTTING_MACHINE(GT_Recipe.GT_Recipe_Map.sCutterRecipes, ItemList.Machine_HV_Cutter, "cuttingmachinelabel"),
SLICING_MACHINE(GT_Recipe.GT_Recipe_Map.sSlicerRecipes, ItemList.Machine_HV_Slicer, "slicingmachinelabel"),
EXTRUDER(GT_Recipe.GT_Recipe_Map.sExtruderRecipes, ItemList.Machine_HV_Extruder, "extruderlabel"),
FORGE_HAMMER(GT_Recipe.GT_Recipe_Map.sHammerRecipes, ItemList.Machine_HV_Hammer, "forgehammerlabel");
FORGE_HAMMER(GT_Recipe.GT_Recipe_Map.sHammerRecipes, ItemList.Machine_HV_Hammer, "forgehammerlabel"),
// Amplifabricator, Mass Fabrication, fuels
// Multiblock Electrolyzer, Multiblock Centrifuge, Multiblock Mixer
NANO_FORGE(GT_Recipe.GT_Recipe_Map.sNanoForge, ItemList.NanoForge, "nanoforgelabel"),
PCB_FACTORY(GT_Recipe.GT_Recipe_Map.sPCBFactory, ItemList.PCBFactory, "pcbfactory"),;

/** This field will be null for the {@link RecipeMap#CRAFTING_TABLE} enum only. */
@Nullable
final GT_Recipe.GT_Recipe_Map recipeMap;
final ItemList item;
final String tooltipKey;

RecipeMap(GT_Recipe.GT_Recipe_Map recipeMap, ItemList item, String tooltipKey) {
RecipeMap(@Nullable GT_Recipe.GT_Recipe_Map recipeMap, ItemList item, String tooltipKey) {
this.recipeMap = recipeMap;
this.item = item;
this.tooltipKey = tooltipKey;
Expand Down Expand Up @@ -198,6 +236,94 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) {
ImmutableList.copyOf(GregTechRecipeUtil.buildComponentsFromOutputs(recipe)));
}

/**
* Checks if {@code recipe} contains any bad {@link ItemStack} instances. If so, returns an optional of a
* {@link Recipe}; otherwise, returns an empty optional.
*/
@SuppressWarnings("unchecked")
static Optional<Recipe> createIfBadItemStack(IRecipe recipe) {
boolean badRecipe = false;

List<DisplayComponent> inputList = new ArrayList<>();
List<DisplayComponent> outputList = new ArrayList<>();

Map<Component, Integer> inputs = new HashMap<>();
Map<Component, Integer> outputs = new HashMap<>();

ItemStack output = recipe.getRecipeOutput();
if (output == null) {
Logger.GREGTECH_5_RECIPE_DEBUGGER.warn("Found a crafting table recipe with null output:\n{}", recipe);
} else if (output.getItem() == null) {
badRecipe = true;
Logger.GREGTECH_5_RECIPE_DEBUGGER.warn("Found a crafting table recipe with bad output:\n{}", recipe);
} else {
outputList.add(DisplayComponent.builderWithNbt(output).build());
outputs.put(ItemComponent.createWithNbt(output), output.stackSize);
}

// We'll try to get the inputs,
// but can only do so for recipe types that we know how to handle.
List<ItemStack> inputItemStacks = new ArrayList<>();
if (recipe instanceof ShapedRecipes) {
inputItemStacks = Arrays.asList(((ShapedRecipes) recipe).recipeItems);
} else if (recipe instanceof ShapedOreRecipe) {
inputItemStacks = Arrays.stream(((ShapedOreRecipe) recipe).getInput()).filter(Objects::nonNull)
.map(NEIServerUtils::extractRecipeItems).flatMap(Arrays::stream)
.collect(Collectors.toCollection(ArrayList::new));
} else if (recipe instanceof ShapelessRecipes) {
inputItemStacks = (List<ItemStack>) ((ShapelessRecipes) recipe).recipeItems;
} else if (recipe instanceof ShapelessOreRecipe) {
inputItemStacks = ((ShapelessOreRecipe) recipe).getInput().stream().filter(Objects::nonNull)
.map(NEIServerUtils::extractRecipeItems).flatMap(Arrays::stream)
.collect(Collectors.toCollection(ArrayList::new));
}

for (ItemStack input : inputItemStacks) {
if (input == null) {
continue;
} else if (input.getItem() == null) {
badRecipe = true;
Logger.GREGTECH_5_RECIPE_DEBUGGER.warn("Found a crafting table recipe with bad input:\n{}", recipe);
continue;
}

// The diagram layout code currently doesn't support permutations,
// so for now, we'll handle wildcard damage by just reverting to damage 0.
boolean isWildcard = false;

ItemComponent itemComponent = ItemComponent.createWithNbt(input);
if (itemComponent.hasWildcardDamage()) {
isWildcard = true;

ItemStack nonWildcardInput = input.copy();
nonWildcardInput.setItemDamage(0);
itemComponent = ItemComponent.createWithNbt(nonWildcardInput);
}
inputs.put(itemComponent, input.stackSize);

DisplayComponent.Builder displayComponentBuilder = DisplayComponent.builder(itemComponent);
if (isWildcard) {
displayComponentBuilder.setAdditionalInfo("*").setAdditionalTooltip(
Tooltip.create(
Lang.GREGTECH_5_RECIPE_DEBUGGER.trans("wildcardlabel"),
Tooltip.INFO_FORMATTING));
}
inputList.add(displayComponentBuilder.build());
}

if (badRecipe) {
return Optional.of(
new AutoValue_RecipeHandler_Recipe(
RecipeMap.CRAFTING_TABLE,
ImmutableMap.copyOf(inputs),
ImmutableMap.copyOf(outputs),
ImmutableList.copyOf(inputList),
ImmutableList.copyOf(outputList)));
} else {
return Optional.empty();
}
}

abstract RecipeMap recipeMap();

/** Map of component to stack size. */
Expand All @@ -218,6 +344,7 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) {
final List<Recipe> voidingRecipes;
final List<Recipe> unequalCellRecipes;
final List<Recipe> smallVariantRecipes;
final List<Recipe> badCraftingTableRecipes;

RecipeHandler() {
this.allRecipes = new HashMap<>();
Expand All @@ -227,12 +354,18 @@ static Recipe create(RecipeMap recipeMap, GT_Recipe recipe) {
this.voidingRecipes = new ArrayList<>();
this.unequalCellRecipes = new ArrayList<>();
this.smallVariantRecipes = new ArrayList<>();
this.badCraftingTableRecipes = new ArrayList<>();
}

/** This method must be called before any other methods are called. */
@SuppressWarnings("unchecked")
void initialize() {
// First pass: build recipe data.
for (RecipeMap recipeMap : RecipeMap.values()) {
if (recipeMap == RecipeMap.CRAFTING_TABLE) {
continue;
}

Logger.GREGTECH_5_RECIPE_DEBUGGER.info("Checking recipes, pass 1: {}", recipeMap.name());

ImmutableList.Builder<Recipe> recipeListBuilder = ImmutableList.builder();
Expand All @@ -246,6 +379,10 @@ void initialize() {

// Second pass: check recipes for overlap, etc.
for (RecipeMap recipeMap : RecipeMap.values()) {
if (recipeMap == RecipeMap.CRAFTING_TABLE) {
continue;
}

Logger.GREGTECH_5_RECIPE_DEBUGGER
.info("Checking recipes, pass 2: {} [{}]", recipeMap.name(), allRecipes.get(recipeMap).size());

Expand Down Expand Up @@ -276,6 +413,11 @@ void initialize() {
}
}
}

// Third pass: check for crafting table recipes with bad item stacks.
Logger.GREGTECH_5_RECIPE_DEBUGGER.info("Checking crafting table recipes");
((List<IRecipe>) CraftingManager.getInstance().getRecipeList()).stream().map(Recipe::createIfBadItemStack)
.filter(Optional::isPresent).map(Optional::get).forEach(badCraftingTableRecipes::add);
}

static Set<Component> filterCircuits(Set<Component> components) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/neicustomdiagram/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ neicustomdiagram.generators.gregtech5.recipedebugger.collidingrecipesbutton=Reci
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.badcraftingtablerecipesbutton=Crafting Table recipes with bad item stacks
neicustomdiagram.generators.gregtech5.recipedebugger.wildcardLabel=Has wildcard damage
neicustomdiagram.generators.gregtech5.recipedebugger.craftingtablelabel=Crafting Table recipe
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 All @@ -235,9 +238,12 @@ neicustomdiagram.generators.gregtech5.recipedebugger.fluidextractorlabel=Fluid E
neicustomdiagram.generators.gregtech5.recipedebugger.packagerlabel=Packager recipe
neicustomdiagram.generators.gregtech5.recipedebugger.unpackagerlabel=Unpackager recipe
neicustomdiagram.generators.gregtech5.recipedebugger.fusionreactorlabel=Fusion Reactor recipe
neicustomdiagram.generators.gregtech5.recipedebugger.complexfusionreactorlabel=Complex Fusion Reactor recipe
neicustomdiagram.generators.gregtech5.recipedebugger.centrifugelabel=Centrifuge recipe
neicustomdiagram.generators.gregtech5.recipedebugger.electrolyzerlabel=Electrolyzer recipe
neicustomdiagram.generators.gregtech5.recipedebugger.electricblastfurnacelabel=Electric Blast Furnace recipe
neicustomdiagram.generators.gregtech5.recipedebugger.plasmaforgelabel=Plasma Forge recipe
neicustomdiagram.generators.gregtech5.recipedebugger.transcendentplasmamixerlabel=Transcendent Plasma Mixer recipe
neicustomdiagram.generators.gregtech5.recipedebugger.brickedblastfurnacelabel=Bricked Blast Furnace recipe
neicustomdiagram.generators.gregtech5.recipedebugger.implosioncompressorlabel=Implosion Compressor recipe
neicustomdiagram.generators.gregtech5.recipedebugger.vacuumfreezerlabel=Vacuum Freezer recipe
Expand All @@ -256,4 +262,6 @@ neicustomdiagram.generators.gregtech5.recipedebugger.lathelabel=Lathe recipe
neicustomdiagram.generators.gregtech5.recipedebugger.cuttingmachinelabel=Cutting Machine recipe
neicustomdiagram.generators.gregtech5.recipedebugger.slicingmachinelabel=Slicing Machine recipe
neicustomdiagram.generators.gregtech5.recipedebugger.extruderlabel=Extruder recipe
neicustomdiagram.generators.gregtech5.recipedebugger.forgehammerlabel=Forge Hammer recipe
neicustomdiagram.generators.gregtech5.recipedebugger.forgehammerlabel=Forge Hammer recipe
neicustomdiagram.generators.gregtech5.recipedebugger.nanoforgelabel=Nano Forge recipe
neicustomdiagram.generators.gregtech5.recipedebugger.pcbfactorylabel=PCB Factory recipe
Loading

0 comments on commit 4e3e16a

Please sign in to comment.