Skip to content

Commit c9393e8

Browse files
committed
Updated: Support transmute recipes in /recipe
1 parent ffdcbbe commit c9393e8

File tree

1 file changed

+26
-0
lines changed
  • modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands

1 file changed

+26
-0
lines changed

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdRecipe.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
import org.bukkit.inventory.InventoryView;
2828
import org.bukkit.inventory.ItemStack;
2929
import org.bukkit.inventory.Recipe;
30+
import org.bukkit.inventory.RecipeChoice;
31+
import org.bukkit.inventory.RecipeChoice.ExactChoice;
32+
import org.bukkit.inventory.RecipeChoice.MaterialChoice;
3033
import org.bukkit.inventory.ShapedRecipe;
3134
import org.bukkit.inventory.ShapelessRecipe;
35+
import org.bukkit.inventory.TransmuteRecipe;
3236
import org.bukkit.inventory.meta.Damageable;
3337
import org.royaldev.royalcommands.MessageColor;
3438
import org.royaldev.royalcommands.RUtils;
@@ -85,6 +89,28 @@ private void scheduleRecipeTask(final Player p, ItemStack is) {
8589
i.setItem(slot, ingredients.get(slot - 1));
8690
}
8791
i.setItem(0, sr.getResult());
92+
} else if (r instanceof TransmuteRecipe) {
93+
final TransmuteRecipe tr = (TransmuteRecipe) r;
94+
if (!tr.getInput().test(is) && !tr.getMaterial().test(is)) continue;
95+
RecipeChoice in1 = tr.getInput();
96+
RecipeChoice in2 = tr.getMaterial();
97+
i = this.plugin.getServer().createInventory(new RecipeHolder(), InventoryType.WORKBENCH);
98+
final List<ItemStack> ingredients = new ArrayList<>();
99+
if (in1 instanceof ExactChoice) {
100+
ingredients.add(((ExactChoice) in1).getItemStack());
101+
} else if (in1 instanceof MaterialChoice) {
102+
ingredients.add(((MaterialChoice) in1).getItemStack());
103+
}
104+
if (in2 instanceof ExactChoice) {
105+
ingredients.add(((ExactChoice) in2).getItemStack());
106+
} else if (in2 instanceof MaterialChoice) {
107+
ingredients.add(((MaterialChoice) in2).getItemStack());
108+
}
109+
for (int slot = 1; slot <= ingredients.size(); slot++) {
110+
if (slot > ingredients.size()) continue;
111+
i.setItem(slot, ingredients.get(slot - 1));
112+
}
113+
i.setItem(0, tr.getResult());
88114
} else if (r instanceof FurnaceRecipe) {
89115
i = this.plugin.getServer().createInventory(new RecipeHolder(), InventoryType.FURNACE);
90116
final FurnaceRecipe fr = (FurnaceRecipe) r;

0 commit comments

Comments
 (0)