Skip to content

Commit ed7c6cd

Browse files
committed
Updated: Support transmute recipes in /uses
1 parent fb7336e commit ed7c6cd

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/CmdUses.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
import org.bukkit.inventory.InventoryHolder;
2727
import org.bukkit.inventory.ItemStack;
2828
import org.bukkit.inventory.Recipe;
29+
import org.bukkit.inventory.RecipeChoice;
2930
import org.bukkit.inventory.ShapedRecipe;
3031
import org.bukkit.inventory.ShapelessRecipe;
32+
import org.bukkit.inventory.TransmuteRecipe;
33+
import org.bukkit.inventory.RecipeChoice.ExactChoice;
34+
import org.bukkit.inventory.RecipeChoice.MaterialChoice;
3135
import org.bukkit.inventory.meta.Damageable;
3236
import org.bukkit.inventory.meta.ItemMeta;
3337
import org.royaldev.royalcommands.MessageColor;
@@ -97,6 +101,28 @@ private void scheduleUsesTask(final Player p, final ItemStack is) {
97101
i.setItem(slot, this.syncDurabilities(ingredients.get(slot - 1), is));
98102
}
99103
i.setItem(0, sr.getResult());
104+
} else if (r instanceof TransmuteRecipe) {
105+
final TransmuteRecipe tr = (TransmuteRecipe) r;
106+
if (!tr.getInput().test(is) && !tr.getMaterial().test(is)) continue;
107+
RecipeChoice in1 = tr.getInput();
108+
RecipeChoice in2 = tr.getMaterial();
109+
i = this.plugin.getServer().createInventory(new UsesHolder(), InventoryType.WORKBENCH);
110+
final List<ItemStack> ingredients = new ArrayList<>();
111+
if (in1 instanceof ExactChoice) {
112+
ingredients.add(((ExactChoice) in1).getItemStack());
113+
} else if (in1 instanceof MaterialChoice) {
114+
ingredients.add(((MaterialChoice) in1).getItemStack());
115+
}
116+
if (in2 instanceof ExactChoice) {
117+
ingredients.add(((ExactChoice) in2).getItemStack());
118+
} else if (in2 instanceof MaterialChoice) {
119+
ingredients.add(((MaterialChoice) in2).getItemStack());
120+
}
121+
for (int slot = 1; slot <= ingredients.size(); slot++) {
122+
if (slot > ingredients.size()) continue;
123+
i.setItem(slot, this.syncDurabilities(ingredients.get(slot - 1), is));
124+
}
125+
i.setItem(0, tr.getResult());
100126
} else if (r instanceof FurnaceRecipe) {
101127
final FurnaceRecipe fr = (FurnaceRecipe) r;
102128
if (!this.itemStackEquals(fr.getInput(), is)) continue;

0 commit comments

Comments
 (0)