1212import gregtech .api .util .GTUtility ;
1313import gregtech .common .items .MetaItems ;
1414import net .minecraft .item .ItemStack ;
15+ import net .minecraftforge .common .util .Constants ;
1516import net .minecraftforge .fluids .FluidStack ;
1617import net .minecraftforge .items .IItemHandlerModifiable ;
1718
2021
2122public 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 ))
0 commit comments