Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<ItemStack> getIngredientList(ItemStack itemStack) {
- itemStack = new ItemBuilder(itemStack.getType())
- .data(itemStack.getDurability())
- .build();
- Map<ItemStack, Integer> map = new HashMap<>();
- int value = map.get(item);
- for (Recipe recipe : Bukkit.getRecipesFor(itemStack)) {
- if (recipe instanceof ShapelessRecipe) {
- ShapelessRecipe shapeless = (ShapelessRecipe) recipe;
- for (ItemStack item : shapeless.getIngredientList()) {
- if (item != null) {
- ItemStack is = new ItemBuilder(item.getType())
- .data(item.getDurability())
- .build();
- if (map.containsKey(is)) {
- map.replace(is, value, value + item.getAmount());
- } else {
- map.put(is, item.getAmount());
- }
- }
- }
- } else if (recipe instanceof ShapedRecipe) {
- ShapedRecipe shaped = (ShapedRecipe) recipe;
- for (ItemStack item : shaped.getIngredientMap().values()) {
- if (item != null) {
- ItemStack is = new ItemBuilder(item.getType())
- .data(item.getDurability())
- .build();
- if (map.containsKey(is)) {
- map.replace(is, value, value + item.getAmount());
- } else {
- map.put(is, item.getAmount());
- }
- }
- }
- }
- }
- List<ItemStack> items = new ArrayList<>();
- map.forEach((k, v) -> items.add(new ItemBuilder(k.getType()).data(k.getDurability()).amount(v).build()));
- return items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement