33import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
44import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
55import net .minecraft .core .component .DataComponents ;
6+ import net .minecraft .tags .TagKey ;
67import net .minecraft .world .inventory .AnvilMenu ;
78import net .minecraft .world .item .Item ;
89import net .minecraft .world .item .ItemStack ;
1112import org .spongepowered .asm .mixin .Unique ;
1213import org .spongepowered .asm .mixin .injection .At ;
1314
15+ import java .util .ArrayList ;
16+ import java .util .List ;
17+
1418import static net .minecraft .tags .ItemTags .*;
1519import static net .fabricmc .fabric .api .tag .convention .v2 .ConventionalItemTags .*;
1620
@@ -20,7 +24,7 @@ public abstract class AnvilMenuMixin {
2024 private boolean wrappedCreateResultItemStackIs (ItemStack firstInputStack , Item secondInputItem , Operation <Boolean > original ) {
2125 if (original .call (firstInputStack , secondInputItem )) return true ;
2226
23- if (isSameToolType (firstInputStack , new ItemStack (secondInputItem ))) {
27+ if (isSameEnchantabilityType (firstInputStack , new ItemStack (secondInputItem ))) {
2428 Repairable firstRepairable = firstInputStack .get (DataComponents .REPAIRABLE );
2529 Repairable secondRepairable = secondInputItem .getDefaultInstance ().get (DataComponents .REPAIRABLE );
2630 if (firstRepairable != null ) {
@@ -32,16 +36,14 @@ private boolean wrappedCreateResultItemStackIs(ItemStack firstInputStack, Item s
3236 }
3337
3438 @ Unique
35- private boolean isSameToolType (ItemStack stack1 , ItemStack stack2 ) {
36- return (stack1 .is (AXES ) && stack2 .is (AXES ))
37- || (stack1 .is (HOES ) && stack2 .is (HOES ))
38- || (stack1 .is (PICKAXES ) && stack2 .is (PICKAXES ))
39- || (stack1 .is (SHOVELS ) && stack2 .is (SHOVELS ))
40- || (stack1 .is (SWORDS ) && stack2 .is (SWORDS ))
41- || (stack1 .is (BOW_TOOLS ) && stack2 .is (BOW_TOOLS ))
42- || (stack1 .is (CROSSBOW_TOOLS ) && stack2 .is (CROSSBOW_TOOLS ))
43- || (stack1 .is (FISHING_ROD_TOOLS ) && stack2 .is (FISHING_ROD_TOOLS ))
44- || (stack1 .is (SHIELD_TOOLS ) && stack2 .is (SHIELD_TOOLS ))
45- || (stack1 .is (SPEAR_TOOLS ) && stack2 .is (SPEAR_TOOLS ));
39+ private boolean isSameEnchantabilityType (ItemStack stack1 , ItemStack stack2 ) {
40+ List <TagKey <Item >> enchantableTags = new ArrayList <>();
41+ enchantableTags .add (AXES ); enchantableTags .add (HOES ); enchantableTags .add (PICKAXES ); enchantableTags .add (SHOVELS ); enchantableTags .add (SWORDS );
42+ enchantableTags .add (BOW_ENCHANTABLE ); enchantableTags .add (CROSSBOW_ENCHANTABLE ); enchantableTags .add (FISHING_ENCHANTABLE );
43+ enchantableTags .add (SHIELD_TOOLS ); enchantableTags .add (SPEAR_TOOLS );
44+ for (TagKey <Item > tag : enchantableTags ) {
45+ if (stack1 .is (tag ) && stack2 .is (tag )) return true ;
46+ }
47+ return false ;
4648 }
4749}
0 commit comments