Skip to content

Commit

Permalink
Add logger for invalid UnificationEntry ingredients (#439)
Browse files Browse the repository at this point in the history
Fixed discovered issues
  • Loading branch information
ALongStringOfNumbers authored Dec 31, 2021
1 parent bc91b8b commit b3ac404
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 55 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/recipes/ModHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ public static Object finalizeIngredient(Object ingredient) {
} else if (ingredient instanceof OrePrefix) {
ingredient = ((OrePrefix) ingredient).name();
} else if (ingredient instanceof UnificationEntry) {
UnificationEntry entry = (UnificationEntry) ingredient;
if(ConfigHolder.misc.debug && entry.material != null && !entry.orePrefix.isIgnored(entry.material) && !entry.orePrefix.doGenerateItem(entry.material)) {
GTLog.logger.error("Attempted to create recipe for invalid/missing Unification Entry {}", ingredient.toString(), new IllegalArgumentException());
}
ingredient = ingredient.toString();
} else if (!(ingredient instanceof ItemStack
|| ingredient instanceof Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void register() {
Aluminium = new Material.Builder(2, "aluminium")
.ingot().fluid().ore()
.color(0x80C8F0)
.flags(EXT2_METAL, GENERATE_SMALL_GEAR, GENERATE_RING, GENERATE_FRAME, GENERATE_SPRING, GENERATE_SPRING_SMALL, GENERATE_FINE_WIRE)
.flags(EXT2_METAL, GENERATE_GEAR, GENERATE_SMALL_GEAR, GENERATE_RING, GENERATE_FRAME, GENERATE_SPRING, GENERATE_SPRING_SMALL, GENERATE_FINE_WIRE)
.element(Elements.Al)
.toolStats(10.0f, 2.0f, 128, 21)
.cableProperties(GTValues.V[4], 1, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/unification/ore/OrePrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static OrePrefix getPrefix(String prefixName, @Nullable OrePrefix replace
}

public boolean doGenerateItem(Material material) {
return !material.isHidden() && !isSelfReferencing && generationCondition != null && !isIgnored(material) && generationCondition.test(material);
return !material.isHidden() && !isSelfReferencing && !isIgnored(material) && (generationCondition == null || generationCondition.test(material));
}

public void setGenerationCondition(@Nullable Predicate<Material> in) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static void init() {
ModHandler.addShapedRecipe(true, "coke_oven", MetaTileEntities.COKE_OVEN.getStackForm(), "PIP", "IwI", "PIP", 'P', MetaBlocks.METAL_CASING.getItemVariant(MetalCasingType.COKE_BRICKS), 'I', new UnificationEntry(OrePrefix.plate, Materials.Iron));
ModHandler.addShapelessRecipe("coke_oven_hatch", MetaTileEntities.COKE_OVEN_HATCH.getStackForm(), MetaBlocks.METAL_CASING.getItemVariant(MetalCasingType.COKE_BRICKS), MetaTileEntities.WOODEN_DRUM.getStackForm());
ModHandler.addShapedRecipe(true, "vacuum_freezer", MetaTileEntities.VACUUM_FREEZER.getStackForm(), "PPP", "CMC", "WCW", 'M', MetaBlocks.METAL_CASING.getItemVariant(ALUMINIUM_FROSTPROOF), 'P', MetaItems.ELECTRIC_PUMP_HV, 'C', new UnificationEntry(OrePrefix.circuit, Tier.Extreme), 'W', new UnificationEntry(OrePrefix.cableGtSingle, Materials.Gold));
ModHandler.addShapedRecipe(true, "implosion_compressor", MetaTileEntities.IMPLOSION_COMPRESSOR.getStackForm(), "OOO", "CMC", "WCW", 'M', MetaBlocks.METAL_CASING.getItemVariant(STEEL_SOLID), 'O', new UnificationEntry(OrePrefix.stone, Materials.Obsidian), 'C', new UnificationEntry(OrePrefix.circuit, MarkerMaterials.Tier.Advanced), 'W', new UnificationEntry(OrePrefix.cableGtSingle, Materials.Aluminium));
ModHandler.addShapedRecipe(true, "implosion_compressor", MetaTileEntities.IMPLOSION_COMPRESSOR.getStackForm(), "OOO", "CMC", "WCW", 'M', MetaBlocks.METAL_CASING.getItemVariant(STEEL_SOLID), 'O', new UnificationEntry(OrePrefix.block, Materials.Obsidian), 'C', new UnificationEntry(OrePrefix.circuit, MarkerMaterials.Tier.Advanced), 'W', new UnificationEntry(OrePrefix.cableGtSingle, Materials.Aluminium));
ModHandler.addShapedRecipe(true, "distillation_tower", MetaTileEntities.DISTILLATION_TOWER.getStackForm(), "CBC", "FMF", "CBC", 'M', MetaTileEntities.HULL[GTValues.HV].getStackForm(), 'B', new UnificationEntry(OrePrefix.pipeLargeFluid, Materials.StainlessSteel), 'C', new UnificationEntry(OrePrefix.circuit, Tier.Extreme), 'F', MetaItems.ELECTRIC_PUMP_HV);
ModHandler.addShapedRecipe(true, "cracking_unit", MetaTileEntities.CRACKER.getStackForm(), "CEC", "PHP", "CEC", 'C', MetaBlocks.WIRE_COIL.getItemVariant(CUPRONICKEL), 'E', MetaItems.ELECTRIC_PUMP_HV, 'P', new UnificationEntry(OrePrefix.circuit, Tier.Advanced), 'H', MetaTileEntities.HULL[GTValues.HV].getStackForm());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,19 @@ public static void processLongStick(OrePrefix longStickPrefix, Material material
GTUtility.copyAmount(2, stickStack),
"s", "X", 'X', new UnificationEntry(OrePrefix.stickLong, material));

ModHandler.addShapedRecipe(String.format("stick_long_gem_flawless_%s", material.toString()),
stickStack,
"sf",
"G ",
'G', new UnificationEntry(OrePrefix.gemFlawless, material));
if(material.hasProperty(PropertyKey.GEM)) {
ModHandler.addShapedRecipe(String.format("stick_long_gem_flawless_%s", material.toString()),
stickStack,
"sf",
"G ",
'G', new UnificationEntry(OrePrefix.gemFlawless, material));

ModHandler.addShapedRecipe(String.format("stick_long_gem_exquisite_%s", material.toString()),
GTUtility.copyAmount(2, stickStack),
"sf", "G ",
'G', new UnificationEntry(OrePrefix.gemExquisite, material));

ModHandler.addShapedRecipe(String.format("stick_long_gem_exquisite_%s", material.toString()),
GTUtility.copyAmount(2, stickStack),
"sf", "G ",
'G', new UnificationEntry(OrePrefix.gemExquisite, material));
}

ModHandler.addShapedRecipe(String.format("stick_long_stick_%s", material.toString()), stack,
"ShS",
Expand Down
105 changes: 63 additions & 42 deletions src/main/java/gregtech/loaders/recipe/handlers/ToolRecipeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void processSimpleElectricToolHead(OrePrefix toolPrefix, Material
}
}

public static void processSimpleToolHead(OrePrefix toolPrefix, Material material, MetaToolValueItem toolItem, Object... recipe) {
public static void processSimpleToolHead(OrePrefix toolPrefix, Material material, MetaToolValueItem toolItem, boolean mirrored, Object... recipe) {
Material handleMaterial = Materials.Wood;

ModHandler.addShapelessRecipe(String.format("%s_%s_%s", toolPrefix.name(), material, handleMaterial),
Expand All @@ -120,11 +120,11 @@ public static void processSimpleToolHead(OrePrefix toolPrefix, Material material
if (material.hasProperty(PropertyKey.INGOT) && material.hasFlag(GENERATE_PLATE)) {
addSimpleToolRecipe(toolPrefix, material, toolItem,
new UnificationEntry(OrePrefix.plate, material),
new UnificationEntry(OrePrefix.ingot, material), recipe);
new UnificationEntry(OrePrefix.ingot, material), mirrored, recipe);
} else if (material.hasProperty(GEM)) {
addSimpleToolRecipe(toolPrefix, material, toolItem,
new UnificationEntry(OrePrefix.gem, material),
new UnificationEntry(OrePrefix.gem, material), recipe);
new UnificationEntry(OrePrefix.gem, material), mirrored, recipe);
}
}

Expand Down Expand Up @@ -199,56 +199,70 @@ public static void processDrillHead(OrePrefix drillHead, Material material, Tool
} else {
processSimpleElectricToolHead(drillHead, material, new MetaToolValueItem[]{MetaItems.DRILL_LV, MetaItems.DRILL_MV, MetaItems.DRILL_HV});
}
ModHandler.addShapedRecipe(String.format("drill_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadDrill, material),
"XSX", "XSX", "ShS",
'X', new UnificationEntry(OrePrefix.plate, material),
'S', new UnificationEntry(OrePrefix.plate, Materials.Steel));

if(material.hasFlag(GENERATE_PLATE)) {
ModHandler.addShapedRecipe(String.format("drill_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadDrill, material),
"XSX", "XSX", "ShS",
'X', new UnificationEntry(OrePrefix.plate, material),
'S', new UnificationEntry(OrePrefix.plate, Materials.Steel));
}
}

public static void processChainSawHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleElectricToolHead(toolPrefix, material, new MetaToolValueItem[]{MetaItems.CHAINSAW_LV, MetaItems.CHAINSAW_MV, MetaItems.CHAINSAW_HV});
ModHandler.addShapedRecipe(String.format("chainsaw_head_%s", material.toString()),
OreDictUnifier.get(toolPrefix, material),
"SRS", "XhX", "SRS",
'X', new UnificationEntry(OrePrefix.plate, material),
'S', new UnificationEntry(OrePrefix.plate, Materials.Steel),
'R', new UnificationEntry(OrePrefix.ring, Materials.Steel));

if(material.hasFlag(GENERATE_PLATE)) {
ModHandler.addShapedRecipe(String.format("chainsaw_head_%s", material.toString()),
OreDictUnifier.get(toolPrefix, material),
"SRS", "XhX", "SRS",
'X', new UnificationEntry(OrePrefix.plate, material),
'S', new UnificationEntry(OrePrefix.plate, Materials.Steel),
'R', new UnificationEntry(OrePrefix.ring, Materials.Steel));
}
}

public static void processWrenchHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleElectricToolHead(toolPrefix, material, new MetaToolValueItem[]{MetaItems.WRENCH_LV, MetaItems.WRENCH_MV, MetaItems.WRENCH_HV});
ModHandler.addShapedRecipe(String.format("wrench_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadWrench, material),
"hXW", "XRX", "WXd",
'X', new UnificationEntry(OrePrefix.plate, material),
'R', new UnificationEntry(OrePrefix.ring, Materials.Steel),
'W', new UnificationEntry(OrePrefix.screw, Materials.Steel));

if(material.hasFlag(GENERATE_PLATE)) {
ModHandler.addShapedRecipe(String.format("wrench_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadWrench, material),
"hXW", "XRX", "WXd",
'X', new UnificationEntry(OrePrefix.plate, material),
'R', new UnificationEntry(OrePrefix.ring, Materials.Steel),
'W', new UnificationEntry(OrePrefix.screw, Materials.Steel));
}
}

public static void processBuzzSawHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleElectricToolHead(toolPrefix, material, new MetaToolValueItem[]{MetaItems.BUZZSAW});
ModHandler.addShapedRecipe(String.format("buzzsaw_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadBuzzSaw, material),
"wXh", "X X", "fXx",
'X', new UnificationEntry(OrePrefix.plate, material));

if(material.hasFlag(GENERATE_PLATE)) {
ModHandler.addShapedRecipe(String.format("buzzsaw_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadBuzzSaw, material),
"wXh", "X X", "fXx",
'X', new UnificationEntry(OrePrefix.plate, material));
}
}

public static void processScrewdriverHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleElectricToolHead(toolPrefix, material, new MetaToolValueItem[]{MetaItems.SCREWDRIVER_LV});

ModHandler.addShapedRecipe(String.format("screwdriver_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadScrewdriver, material),
"fX", "Xh",
'X', new UnificationEntry(OrePrefix.stick, material));
if(material.hasFlag(GENERATE_ROD)) {
ModHandler.addShapedRecipe(String.format("screwdriver_head_%s", material.toString()),
OreDictUnifier.get(OrePrefix.toolHeadScrewdriver, material),
"fX", "Xh",
'X', new UnificationEntry(OrePrefix.stick, material));
}

ModHandler.addShapelessRecipe(String.format("%s_%s_%s", toolPrefix.name(), material.toString(), Materials.Wood.toString()),
MetaItems.SCREWDRIVER.getStackForm(material),
new UnificationEntry(toolPrefix, material),
new UnificationEntry(OrePrefix.stick, Materials.Wood));
}

public static void addSimpleToolRecipe(OrePrefix toolPrefix, Material material, MetaToolValueItem toolItem, UnificationEntry plate, UnificationEntry ingot, Object[] recipe) {
public static void addSimpleToolRecipe(OrePrefix toolPrefix, Material material, MetaToolValueItem toolItem, UnificationEntry plate, UnificationEntry ingot, boolean mirrored, Object[] recipe) {
ArrayList<Character> usedChars = new ArrayList<>();
for (Object object : recipe) {
if (!(object instanceof String))
Expand All @@ -265,13 +279,20 @@ public static void addSimpleToolRecipe(OrePrefix toolPrefix, Material material,
recipe = ArrayUtils.addAll(recipe, 'I', ingot);
}

ModHandler.addShapedRecipe(
String.format("head_%s_%s", toolPrefix.name(), material.toString()),
OreDictUnifier.get(toolPrefix, material), recipe);
if(mirrored) {
ModHandler.addMirroredShapedRecipe(
String.format("head_%s_%s", toolPrefix.name(), material.toString()),
OreDictUnifier.get(toolPrefix, material), recipe);
}
else {
ModHandler.addShapedRecipe(
String.format("head_%s_%s", toolPrefix.name(), material.toString()),
OreDictUnifier.get(toolPrefix, material), recipe);
}
}

public static void processAxeHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.AXE, "PIh", "P ", "f ");
processSimpleToolHead(toolPrefix, material, MetaItems.AXE, false, "PIh", "P ", "f ");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -287,7 +308,7 @@ public static void processAxeHead(OrePrefix toolPrefix, Material material, ToolP
}

public static void processHoeHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.HOE, "PIh", "f ");
processSimpleToolHead(toolPrefix, material, MetaItems.HOE, false, "PIh", "f ");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -302,7 +323,7 @@ public static void processHoeHead(OrePrefix toolPrefix, Material material, ToolP
}

public static void processPickaxeHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.PICKAXE, "PII", "f h");
processSimpleToolHead(toolPrefix, material, MetaItems.PICKAXE, false, "PII", "f h");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -318,7 +339,7 @@ public static void processPickaxeHead(OrePrefix toolPrefix, Material material, T
}

public static void processSawHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.SAW, "PP", "fh");
processSimpleToolHead(toolPrefix, material, MetaItems.SAW, false, "PP", "fh");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -333,11 +354,11 @@ public static void processSawHead(OrePrefix toolPrefix, Material material, ToolP
}

public static void processSenseHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.SENSE, "PPI", "hf ");
processSimpleToolHead(toolPrefix, material, MetaItems.SENSE, false, "PPI", "hf ");
}

public static void processShovelHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.SHOVEL, "fPh");
processSimpleToolHead(toolPrefix, material, MetaItems.SHOVEL, false, "fPh");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -352,7 +373,7 @@ public static void processShovelHead(OrePrefix toolPrefix, Material material, To
}

public static void processSwordHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.SWORD, " P ", "fPh");
processSimpleToolHead(toolPrefix, material, MetaItems.SWORD, false, " P ", "fPh");

int voltageMultiplier = getVoltageMultiplier(material);

Expand All @@ -368,7 +389,7 @@ public static void processSwordHead(OrePrefix toolPrefix, Material material, Too

public static void processHammerHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
if (!material.hasFlag(NO_WORKING)) {
processSimpleToolHead(toolPrefix, material, MetaItems.HARD_HAMMER, "II ", "IIh", "II ");
processSimpleToolHead(toolPrefix, material, MetaItems.HARD_HAMMER, true, "II ", "IIh", "II ");

if (!material.hasProperty(GEM))
RecipeMaps.EXTRUDER_RECIPES.recipeBuilder()
Expand All @@ -382,12 +403,12 @@ public static void processHammerHead(OrePrefix toolPrefix, Material material, To
ModHandler.addMirroredShapedRecipe(String.format("hammer_%s", material.toString()),
MetaItems.HARD_HAMMER.getStackForm(material),
"XX ", "XXS", "XX ",
'X', new UnificationEntry(OrePrefix.ingot, material),
'X', new UnificationEntry(material.hasProperty(GEM) ? OrePrefix.gem : OrePrefix.ingot, material),
'S', new UnificationEntry(OrePrefix.stick, Materials.Wood));
}

public static void processFileHead(OrePrefix toolPrefix, Material material, ToolProperty property) {
processSimpleToolHead(toolPrefix, material, MetaItems.FILE, " I ", " I ", " fh");
processSimpleToolHead(toolPrefix, material, MetaItems.FILE, false," I ", " I ", " fh");

if (!material.hasProperty(GEM))
RecipeMaps.EXTRUDER_RECIPES.recipeBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static gregtech.api.GTValues.*;
import static gregtech.api.recipes.RecipeMaps.*;
import static gregtech.api.unification.material.Materials.*;
import static gregtech.api.unification.material.info.MaterialFlags.GENERATE_PLATE;
import static gregtech.api.unification.material.info.MaterialFlags.NO_WORKING;
import static gregtech.api.unification.ore.OrePrefix.*;
import static gregtech.common.items.MetaItems.SHAPE_EXTRUDER_WIRE;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static void processWireSingle(OrePrefix wirePrefix, Material material, Wi
.EUt(getVoltageMultiplier(material))
.buildAndRegister();

if (!material.hasFlag(NO_WORKING)) {
if (!material.hasFlag(NO_WORKING) && material.hasFlag(GENERATE_PLATE)) {
ModHandler.addShapedRecipe(String.format("%s_wire_single", material),
OreDictUnifier.get(wireGtSingle, material), "Xx",
'X', new UnificationEntry(plate, material));
Expand Down

0 comments on commit b3ac404

Please sign in to comment.