Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.techmage.magetech.crafting;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import java.util.*;
- public class RecipesCauldron
- {
- private static final RecipesCauldron cauldronBase = new RecipesCauldron();
- public static RecipesCauldron crafting() { return cauldronBase; }
- private RecipesCauldron() { }
- private Map recipes = new HashMap<ItemStack, ArrayList<Item>>();
- public void addRecipe(ItemStack output, Item ... inputs)
- {
- ArrayList<Item> inputList = new ArrayList<Item>();
- for (Item input : inputs)
- inputList.add(input);
- recipes.put(output, inputList);
- }
- public boolean hasCraftingResult(Item ... inputs)
- {
- ArrayList<Item> inputList = new ArrayList<Item>();
- Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
- for (Item input : inputs)
- inputList.add(input);
- while (iterator.hasNext())
- {
- Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
- if (entry.getValue().containsAll(inputList) && entry.getValue().size() == inputList.size())
- return true;
- }
- return false;
- }
- public ItemStack getCraftingResult(Item ... inputs)
- {
- ArrayList<Item> inputList = new ArrayList<Item>();
- Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
- for (Item input : inputs)
- inputList.add(input);
- while (iterator.hasNext())
- {
- Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
- if (entry.getValue().containsAll(inputList) && entry.getValue().size() == inputList.size())
- return entry.getKey();
- }
- return null;
- }
- public ArrayList<Item> getCraftingIngredients(ItemStack output)
- {
- Iterator<Map.Entry<ItemStack, ArrayList<Item>>> iterator = recipes.entrySet().iterator();
- while (iterator.hasNext())
- {
- Map.Entry<ItemStack, ArrayList<Item>> entry = iterator.next();
- if (entry.getKey().getItem() == output.getItem() && entry.getKey().stackSize == output.stackSize && entry.getKey().getItemDamage() == output.getItemDamage())
- return entry.getValue();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement