Skip to content

Commit 0cc6a5c

Browse files
authored
Fix name mold recipes in forming press not working (#1311)
1 parent 279d5ab commit 0cc6a5c

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/main/java/gregtech/api/recipes/machines/RecipeMapFormingPress.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gregtech.api.util.GTUtility;
1313
import gregtech.common.items.MetaItems;
1414
import net.minecraft.item.ItemStack;
15+
import net.minecraftforge.common.util.Constants;
1516
import net.minecraftforge.fluids.FluidStack;
1617
import net.minecraftforge.items.IItemHandlerModifiable;
1718

@@ -20,6 +21,8 @@
2021

2122
public class RecipeMapFormingPress extends RecipeMap<SimpleRecipeBuilder> {
2223

24+
private static ItemStack NAME_MOLD = ItemStack.EMPTY;
25+
2326
public RecipeMapFormingPress(String unlocalizedName, int minInputs, int maxInputs, int minOutputs, int maxOutputs, int minFluidInputs, int maxFluidInputs, int minFluidOutputs, int maxFluidOutputs, SimpleRecipeBuilder defaultRecipe, boolean isHidden) {
2427
super(unlocalizedName, minInputs, maxInputs, minOutputs, maxOutputs, minFluidInputs, maxFluidInputs, minFluidOutputs, maxFluidOutputs, defaultRecipe, isHidden);
2528
}
@@ -28,22 +31,36 @@ public RecipeMapFormingPress(String unlocalizedName, int minInputs, int maxInput
2831
@Nullable
2932
public Recipe findRecipe(long voltage, List<ItemStack> inputs, List<FluidStack> fluidInputs, int outputFluidTankCapacity, boolean exactVoltage) {
3033
Recipe recipe = super.findRecipe(voltage, inputs, fluidInputs, outputFluidTankCapacity, exactVoltage);
31-
if (inputs.size() < 2 || inputs.get(0).isEmpty() || inputs.get(1).isEmpty()) {
32-
return recipe;
33-
}
34-
if (recipe == null) {
34+
35+
// Item Mold renaming - min of 2 inputs required
36+
if (recipe == null && inputs.size() > 1) {
37+
// cache name mold target comparison stack so a new one is not made every lookup
38+
// cannot statically initialize as RecipeMaps are registered before items, throwing a NullPointer
39+
if (NAME_MOLD.isEmpty()) {
40+
NAME_MOLD = MetaItems.SHAPE_MOLD_NAME.getStackForm();
41+
}
42+
43+
// find the mold and the stack to rename
3544
ItemStack moldStack = ItemStack.EMPTY;
3645
ItemStack itemStack = ItemStack.EMPTY;
3746
for (ItemStack inputStack : inputs) {
38-
if (MetaItems.SHAPE_MOLD_NAME.getStackForm().isItemEqual(moldStack)) {
39-
moldStack = inputStack;
40-
} else {
47+
// early exit
48+
if (!moldStack.isEmpty() && !itemStack.isEmpty()) break;
49+
50+
if (moldStack.isEmpty() && inputStack.isItemEqual(NAME_MOLD)) {
51+
// only valid if the name mold has a name, which is stored in the "display" sub-compound
52+
if (inputStack.getTagCompound() != null && inputStack.getTagCompound().hasKey("display", Constants.NBT.TAG_COMPOUND)) {
53+
moldStack = inputStack;
54+
}
55+
} else if (itemStack.isEmpty()) {
4156
itemStack = inputStack;
4257
}
4358
}
44-
if (!moldStack.isEmpty() && !itemStack.isEmpty()) {
59+
60+
// make the mold recipe if the two required inputs were found
61+
if (!moldStack.isEmpty() && moldStack.getTagCompound() != null && !itemStack.isEmpty()) {
4562
ItemStack output = GTUtility.copyAmount(1, itemStack);
46-
output.setStackDisplayName(inputs.get(0).getDisplayName());
63+
output.setStackDisplayName(moldStack.getDisplayName());
4764
return this.recipeBuilder()
4865
.notConsumable(GTRecipeItemInput.getOrCreate(moldStack)) //recipe is reusable as long as mold stack matches
4966
.inputs(GTUtility.copyAmount(1, itemStack))

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ metaitem.shape.mold.cylinder.tooltip=Mold for shaping Cylinders
167167
metaitem.shape.mold.anvil.name=Mold (Anvil)
168168
metaitem.shape.mold.anvil.tooltip=Mold for shaping Anvils
169169
metaitem.shape.mold.name.name=Mold (Name)
170-
metaitem.shape.mold.name.tooltip=Mold for naming Items (rename Mold with Anvil)
170+
metaitem.shape.mold.name.tooltip=Mold for naming Items in the Forming Press (rename Mold with Anvil)
171171
metaitem.shape.mold.gear.small.name=Mold (Small Gear)
172172
metaitem.shape.mold.gear.small.tooltip=Mold for making small Gears
173173
metaitem.shape.mold.rotor.name=Mold (Rotor)

0 commit comments

Comments
 (0)