3131import java .util .Collections ;
3232
3333final class RecipesPatch extends GamePatch {
34+ private static final String ItemStack = "net/minecraft/common/item/ItemStack" ;
3435 private static final String Items = "net/minecraft/common/item/Items" ;
36+ private static final String Container = "net/minecraft/common/block/container/Container" ;
37+ private static final String InventoryCrafting = "net/minecraft/common/entity/inventory/InventoryCrafting" ;
38+ private static final String IRecipe = "net/minecraft/common/recipe/IRecipe" ;
3539 private static final String ShapedRecipes = "net/minecraft/common/recipe/ShapedRecipes" ;
3640 private static final String ShapelessRecipes = "net/minecraft/common/recipe/ShapelessRecipes" ;
41+ private static final String CraftingManager = "net/minecraft/common/recipe/CraftingManager" ;
3742 private static final String RecipesDyes = "net/minecraft/common/recipe/RecipesDyes" ;
3843 private static final String TaggedIngredient = "net/minecraft/common/recipe/TaggedIngredient" ;
3944 private static final String FoxTaggedIngredients = "com/fox2code/foxloader/recipe/FoxTaggedIngredients" ;
45+ private static final String InternalRecipeHooks = "com/fox2code/foxloader/internal/InternalRecipeHooks" ;
4046
4147 RecipesPatch () {
42- super (new String []{ShapedRecipes , ShapelessRecipes , RecipesDyes });
48+ super (new String []{InventoryCrafting , ShapedRecipes , ShapelessRecipes , CraftingManager , RecipesDyes });
4349 }
4450
4551 @ Override
4652 public ClassNode transform (ClassNode classNode ) {
4753 switch (classNode .name ) {
54+ case InventoryCrafting : {
55+ patchInventoryCrafting (classNode );
56+ break ;
57+ }
4858 case ShapedRecipes : {
4959 TransformerUtils .makeGetterForFields (classNode , "width" , "height" , "ingredients" );
5060 break ;
@@ -53,6 +63,10 @@ public ClassNode transform(ClassNode classNode) {
5363 TransformerUtils .makeGetterForFields (classNode , "ingredients" );
5464 break ;
5565 }
66+ case CraftingManager : {
67+ patchCraftingManager (classNode );
68+ break ;
69+ }
5670 case RecipesDyes : {
5771 patchAllDyeRecipes (classNode );
5872 break ;
@@ -61,6 +75,39 @@ public ClassNode transform(ClassNode classNode) {
6175 return classNode ;
6276 }
6377
78+ private void patchInventoryCrafting (ClassNode classNode ) {
79+ FieldNode fieldNode = TransformerUtils .getFieldDesc (classNode , "L" + Container + ";" );
80+ MethodNode methodNode = new MethodNode (ACC_PUBLIC ,
81+ "getCraftingContainer" , "()" + fieldNode .desc , null , null );
82+ methodNode .instructions .add (new VarInsnNode (ALOAD , 0 ));
83+ methodNode .instructions .add (new FieldInsnNode (GETFIELD ,
84+ classNode .name , fieldNode .name , fieldNode .desc ));
85+ methodNode .instructions .add (new InsnNode (ARETURN ));
86+ classNode .methods .add (methodNode );
87+ }
88+
89+ private void patchCraftingManager (ClassNode classNode ) {
90+ MethodNode methodNode = TransformerUtils .getMethod (classNode , "findMatchingRecipe" );
91+ for (AbstractInsnNode abstractInsnNode : methodNode .instructions .toArray ()) {
92+ if (abstractInsnNode .getOpcode () == ARETURN ) {
93+ AbstractInsnNode previous = abstractInsnNode .getPrevious ();
94+ if (previous .getOpcode () == INVOKEINTERFACE &&
95+ ((MethodInsnNode ) previous ).owner .equals (IRecipe )) {
96+ methodNode .instructions .remove (previous );
97+ methodNode .instructions .insertBefore (abstractInsnNode , new MethodInsnNode (
98+ INVOKESTATIC , InternalRecipeHooks , "onWorkbenchRecipe" ,
99+ "(L" + IRecipe + ";L" + InventoryCrafting + ";)L" + ItemStack + ";" ));
100+ } else if (previous .getOpcode () != ACONST_NULL ) {
101+ methodNode .instructions .insertBefore (
102+ abstractInsnNode , new VarInsnNode (ALOAD , 1 ));
103+ methodNode .instructions .insertBefore (abstractInsnNode , new MethodInsnNode (
104+ INVOKESTATIC , InternalRecipeHooks , "onWorkbenchRecipe" ,
105+ "(L" + ItemStack + ";L" + InventoryCrafting + ";)L" + ItemStack + ";" ));
106+ }
107+ }
108+ }
109+ }
110+
64111 private static void patchAllDyeRecipes (ClassNode classNode ) {
65112 for (MethodNode methodNode : classNode .methods ) {
66113 ArrayList <StaticDyeOccurrence > staticDyeOccurrences = new ArrayList <>();
0 commit comments