55import gregtech .api .items .toolitem .ToolHelper ;
66
77import net .minecraft .inventory .InventoryCrafting ;
8+ import net .minecraft .item .Item ;
89import net .minecraft .item .ItemStack ;
910import net .minecraft .item .crafting .RecipeRepairItem ;
1011import net .minecraft .nbt .NBTTagCompound ;
1112import net .minecraft .util .NonNullList ;
12- import net .minecraft .world .World ;
1313import net .minecraftforge .common .ForgeHooks ;
1414import net .minecraftforge .event .ForgeEventFactory ;
1515
2020import org .spongepowered .asm .mixin .Mixin ;
2121import org .spongepowered .asm .mixin .injection .At ;
2222import org .spongepowered .asm .mixin .injection .Inject ;
23+ import org .spongepowered .asm .mixin .injection .Redirect ;
2324import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
2425
2526import java .util .List ;
27+ import java .util .Set ;
2628
2729@ Mixin (RecipeRepairItem .class )
2830public class RecipeRepairItemMixin {
2931
30- @ Inject (method = "matches(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Z" ,
31- at = @ At (value = "INVOKE" ,
32- target = "Ljava/util/List;get(I)Ljava/lang/Object;" ,
33- shift = At .Shift .AFTER ),
34- cancellable = true )
35- public void gregtechCEu$matches (InventoryCrafting inv , World worldIn , CallbackInfoReturnable <Boolean > cir ,
36- @ Local (ordinal = 0 ) ItemStack itemstack , @ Local (ordinal = 0 ) List <ItemStack > list ) {
37- ItemStack itemstack1 = list .get (0 );
38- if (itemstack .getItem () instanceof IGTTool first &&
39- itemstack1 .getItem () instanceof IGTTool second ) {
40- if (first .isElectric () || second .isElectric () ||
41- first instanceof ItemGTToolbelt || second instanceof ItemGTToolbelt ) {
42- cir .setReturnValue (false );
43- } else {
44- cir .setReturnValue (first .getToolMaterial (itemstack ) == second .getToolMaterial (itemstack1 ));
32+ @ Redirect (method = "matches" ,
33+ at = @ At (value = "INVOKE" ,
34+ ordinal = 0 ,
35+ target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;" ))
36+ public Item gregtechCEu$checkFirst (ItemStack instance ) {
37+ if (instance .getItem () instanceof IGTTool )
38+ return null ; // return null to bypass item check
39+ else return instance .getItem ();
40+ }
41+
42+ @ Redirect (method = "matches" ,
43+ at = @ At (value = "INVOKE" ,
44+ ordinal = 1 ,
45+ target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;" ))
46+ public Item gregtechCEu$checkSecond (ItemStack instance ) {
47+ if (instance .getItem () instanceof IGTTool )
48+ return null ; // return null to bypass item check
49+ else return instance .getItem ();
50+ }
51+
52+ @ ModifyReturnValue (method = "matches" , at = @ At (value = "RETURN" , ordinal = 1 ), remap = false )
53+ public boolean gregtechCEu$matches (boolean b , @ Local List <ItemStack > list ) {
54+ if (!b ) return false ; // list size is not two
55+
56+ ItemStack stack1 = list .get (0 );
57+ ItemStack stack2 = list .get (1 );
58+
59+ if (!(stack1 .getItem () instanceof IGTTool ) || stack1 .getItem () instanceof ItemGTToolbelt )
60+ return false ;
61+
62+ // items must be the same at this point
63+ IGTTool first = (IGTTool ) stack1 .getItem ();
64+ IGTTool second = (IGTTool ) stack2 .getItem ();
65+
66+ // must be same material
67+ if (first .getToolMaterial (stack1 ) != second .getToolMaterial (stack2 ))
68+ return false ;
69+
70+ // must not be electric
71+ if (first .isElectric () || second .isElectric ())
72+ return false ;
73+
74+ // must share at least one tool class
75+ Set <String > firstClasses = first .getToolClasses (stack1 );
76+ Set <String > secondClasses = second .getToolClasses (stack2 );
77+ if (!firstClasses .isEmpty () && !secondClasses .isEmpty ()) {
78+ for (String toolClass : first .getToolClasses (stack1 )) {
79+ if (second .getToolClasses (stack2 ).contains (toolClass )) {
80+ return true ;
81+ }
4582 }
4683 }
84+ return false ;
4785 }
4886
4987 @ Inject (method = "getCraftingResult(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/item/ItemStack;" ,
5088 at = @ At (value = "INVOKE_ASSIGN" ,
5189 target = "Ljava/util/List;get(I)Ljava/lang/Object;" ,
52- ordinal = 0 ,
53- shift = At .Shift .BY ,
54- by = 2 ),
90+ ordinal = 0 ),
5591 cancellable = true )
5692 public void gregtechCEu$getCraftingResultFirst (InventoryCrafting inv , CallbackInfoReturnable <ItemStack > cir ,
5793 @ Local (ordinal = 0 ) ItemStack itemstack ,
@@ -63,11 +99,6 @@ public class RecipeRepairItemMixin {
6399 }
64100 }
65101
66- /*
67- * @Inject(method = "getCraftingResult(Lnet/minecraft/inventory/InventoryCrafting;)Lnet/minecraft/item/ItemStack;",
68- * at = @At(value = "RETURN", ordinal = 1),
69- * cancellable = true)
70- */
71102 @ ModifyReturnValue (method = "getCraftingResult" , at = @ At (value = "RETURN" , ordinal = 1 ))
72103 public ItemStack gregtechCEu$getCraftingResultSecond (ItemStack originalResult , InventoryCrafting inv ,
73104 @ Local (ordinal = 3 ) int itemDamage ,
0 commit comments