Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.techmage.magetech.item.crafting;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import java.util.ArrayList;
- import java.util.List;
- public class RecipesCrystalInfuser
- {
- private static final RecipesCrystalInfuser infusingBase = new RecipesCrystalInfuser();
- public static RecipesCrystalInfuser infusing()
- {
- return infusingBase;
- }
- private RecipesCrystalInfuser() { }
- private List<Item> outputs = new ArrayList<Item>();
- private List<List<ItemStack>> inputs = new ArrayList<List<ItemStack>>();
- public void addRecipe(Item output, List<ItemStack> inputs)
- {
- this.outputs.add(output);
- this.inputs.add(inputs);
- }
- /**
- * @param inputs List of ItemEntities to get the craftingResults for
- * @return A List of items with all available recipes for the given items
- */
- public List<Item> getCraftingResults(List inputs)
- {
- List<Item> craftingResults = new ArrayList<Item>();
- List<Item> inputItems = new ArrayList<Item>();
- // Convert the input EntityItems to Items ...
- for (EntityItem entityItem : (List<EntityItem>) inputs)
- {
- inputItems.add(entityItem.getEntityItem().getItem());
- }
- // Get the crafting result
- for (List<ItemStack> sInputs : this.inputs)
- {
- int equal = 0;
- for (ItemStack sInput : sInputs)
- {
- if (inputItems.contains(sInput.getItem()))
- equal ++;
- }
- if (equal == sInputs.size())
- craftingResults.add(outputs.get(this.inputs.indexOf(sInputs)));
- }
- return craftingResults;
- }
- public Item getNextCraftingResult(List<Item> craftingResults, Item currentResult)
- {
- if (craftingResults == null) return null;
- if (currentResult == null)
- return craftingResults.get(0);
- else
- {
- if (craftingResults.indexOf(currentResult) == craftingResults.size() - 1)
- return null;
- else
- return craftingResults.get(craftingResults.indexOf(currentResult) + 1);
- }
- }
- public List<ItemStack> getNeededInputs(Item output)
- {
- return this.outputs.contains(output) ? this.inputs.get(this.outputs.indexOf(output)) : null;
- }
- public boolean hasCraftingResult(List inputs)
- {
- List<Item> inputItems = new ArrayList<Item>();
- // Convert the input EntityItems to Items ...
- for (EntityItem entityItem : (List<EntityItem>) inputs)
- {
- inputItems.add(entityItem.getEntityItem().getItem());
- }
- // Check if there is a recipe registered for the given items
- for (List<ItemStack> sInputs : this.inputs)
- {
- int equal = 0;
- for (ItemStack sInput : sInputs)
- {
- if (inputItems.contains(sInput.getItem()))
- equal ++;
- }
- if (equal == sInputs.size())
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement