1111import net .ess3 .provider .InventoryViewProvider ;
1212import net .kyori .adventure .text .format .NamedTextColor ;
1313import org .bukkit .Material ;
14+ import org .bukkit .NamespacedKey ;
1415import org .bukkit .Server ;
1516import org .bukkit .inventory .FurnaceRecipe ;
1617import org .bukkit .inventory .InventoryView ;
1718import org .bukkit .inventory .ItemStack ;
1819import org .bukkit .inventory .Recipe ;
20+ import org .bukkit .inventory .RecipeChoice ;
1921import org .bukkit .inventory .ShapedRecipe ;
2022import org .bukkit .inventory .ShapelessRecipe ;
23+ import org .bukkit .inventory .TransmuteRecipe ;
2124
25+ import java .util .ArrayList ;
2226import java .util .Collections ;
2327import java .util .HashMap ;
2428import java .util .List ;
@@ -62,7 +66,7 @@ public void run(final Server server, final CommandSource sender, final String co
6266 if (!sender .isPlayer ()) {
6367 throw new TranslatableException ("consoleCannotUseCommand" );
6468 }
65-
69+
6670 itemType = Inventories .getItemInHand (sender .getPlayer ());
6771 } else {
6872 itemType = ess .getItemDb ().get (args [0 ]);
@@ -78,24 +82,42 @@ public void run(final Server server, final CommandSource sender, final String co
7882 }
7983 }
8084
81- final List <Recipe > recipesOfType = ess .getServer ().getRecipesFor (itemType );
82- if (recipesOfType . size () < 1 ) {
85+ final List <Recipe > bukkitRecipes = ess .getServer ().getRecipesFor (itemType );
86+ if (bukkitRecipes . isEmpty () ) {
8387 throw new TranslatableException ("recipeNone" , getMaterialName (sender , itemType ));
8488 }
8589
86- if (recipeNo < 0 || recipeNo >= recipesOfType .size ()) {
90+ final List <Recipe > recipes = new ArrayList <>();
91+ for (Recipe recipe : bukkitRecipes ) {
92+ if (VersionUtil .getServerBukkitVersion ().isHigherThanOrEqualTo (VersionUtil .v1_21_3_R01 ) && recipe instanceof TransmuteRecipe ) {
93+ final TransmuteRecipe transmuteRecipe = (TransmuteRecipe ) recipe ;
94+
95+ for (ItemStack inputChoice : toChoices (transmuteRecipe .getInput ())) {
96+ for (ItemStack materialChoice : toChoices (transmuteRecipe .getMaterial ())) {
97+ final ShapelessRecipe shapelessRecipe = new ShapelessRecipe (new NamespacedKey (ess , "transmute" ), itemType );
98+ shapelessRecipe .addIngredient (inputChoice );
99+ shapelessRecipe .addIngredient (materialChoice );
100+ recipes .add (shapelessRecipe );
101+ }
102+ }
103+ } else {
104+ recipes .add (recipe );
105+ }
106+ }
107+
108+ if (recipeNo < 0 || recipeNo >= recipes .size ()) {
87109 throw new TranslatableException ("recipeBadIndex" );
88110 }
89111
90- final Recipe selectedRecipe = recipesOfType .get (recipeNo );
91- sender .sendTl ("recipe" , getMaterialName (sender , itemType ), recipeNo + 1 , recipesOfType .size ());
112+ final Recipe selectedRecipe = recipes .get (recipeNo );
113+ sender .sendTl ("recipe" , getMaterialName (sender , itemType ), recipeNo + 1 , recipes .size ());
92114
93115 if (selectedRecipe instanceof FurnaceRecipe ) {
94116 furnaceRecipe (sender , (FurnaceRecipe ) selectedRecipe );
95117 } else if (selectedRecipe instanceof ShapedRecipe ) {
96118 shapedRecipe (sender , (ShapedRecipe ) selectedRecipe , sender .isPlayer ());
97119 } else if (selectedRecipe instanceof ShapelessRecipe ) {
98- if (recipesOfType .size () == 1 && ( itemType .getType () == FIREWORK_ROCKET ) ) {
120+ if (recipes .size () == 1 && itemType .getType () == FIREWORK_ROCKET ) {
99121 final ShapelessRecipe shapelessRecipe = new ShapelessRecipe (itemType );
100122 shapelessRecipe .addIngredient (GUNPOWDER );
101123 shapelessRecipe .addIngredient (Material .PAPER );
@@ -106,11 +128,25 @@ public void run(final Server server, final CommandSource sender, final String co
106128 }
107129 }
108130
109- if (recipesOfType .size () > 1 && args .length == 1 ) {
131+ if (recipes .size () > 1 && args .length == 1 ) {
110132 sender .sendTl ("recipeMore" , commandLabel , args [0 ], getMaterialName (sender , itemType ));
111133 }
112134 }
113135
136+ private List <ItemStack > toChoices (final RecipeChoice choice ) {
137+ if (choice instanceof RecipeChoice .MaterialChoice ) {
138+ final List <ItemStack > stacks = new ArrayList <>();
139+ for (final Material material : ((RecipeChoice .MaterialChoice ) choice ).getChoices ()) {
140+ stacks .add (new ItemStack (material , 1 ));
141+ }
142+ return stacks ;
143+ } else if (choice instanceof RecipeChoice .ExactChoice ) {
144+ return ((RecipeChoice .ExactChoice ) choice ).getChoices ();
145+ } else {
146+ return Collections .emptyList ();
147+ }
148+ }
149+
114150 public void furnaceRecipe (final CommandSource sender , final FurnaceRecipe recipe ) {
115151 sender .sendTl ("recipeFurnace" , getMaterialName (sender , recipe .getInput ()));
116152 }
0 commit comments