Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AssemblyTableCraftingManager {
- private static final AssemblyTableCraftingManager INSTANCE = new AssemblyTableCraftingManager();
- private final List<IRecipe> recipes = Lists.<IRecipe>newArrayList();
- public static final AssemblyTableCraftingManager getInstance()
- {
- return INSTANCE;
- }
- private AssemblyTableCraftingManager()
- {
- Collections.sort(this.recipes, new Comparator<IRecipe>()
- {
- public int compare(IRecipe p_compare_1_, IRecipe p_compare_2_)
- {
- return p_compare_2_ instanceof AssemblyRecipes ? 1 : (p_compare_1_ instanceof AssemblyRecipes ? -1 : (p_compare_2_.getRecipeSize() < p_compare_1_.getRecipeSize() ? -1 : (p_compare_2_.getRecipeSize() > p_compare_1_.getRecipeSize() ? 1 : 0)));
- }
- });
- }
- public AssemblyRecipes addRecipe(ItemStack stack, Object ... recipeComponents)
- {
- String s = "";
- int i = 0;
- int j = 0;
- int k = 0;
- if (recipeComponents[i] instanceof String[])
- {
- String[] astring = (String[])((String[])recipeComponents[i++]);
- for (String s2 : astring)
- {
- ++k;
- j = s2.length();
- s = s + s2;
- }
- }
- else
- {
- while (recipeComponents[i] instanceof String)
- {
- String s1 = (String)recipeComponents[i++];
- ++k;
- j = s1.length();
- s = s + s1;
- }
- }
- Map<Character, ItemStack> map;
- for (map = Maps.<Character, ItemStack>newHashMap(); i < recipeComponents.length; i += 2)
- {
- Character character = (Character)recipeComponents[i];
- ItemStack itemstack = ItemStack.EMPTY;
- if (recipeComponents[i + 1] instanceof Item)
- {
- itemstack = new ItemStack((Item)recipeComponents[i + 1]);
- }
- else if (recipeComponents[i + 1] instanceof Block)
- {
- itemstack = new ItemStack((Block)recipeComponents[i + 1], 1, 32767);
- }
- else if (recipeComponents[i + 1] instanceof ItemStack)
- {
- itemstack = (ItemStack)recipeComponents[i + 1];
- }
- map.put(character, itemstack);
- }
- ItemStack[] aitemstack = new ItemStack[j * k];
- for (int l = 0; l < j * k; ++l)
- {
- char c0 = s.charAt(l);
- if (map.containsKey(Character.valueOf(c0)))
- {
- aitemstack[l] = ((ItemStack)map.get(Character.valueOf(c0))).copy();
- }
- else
- {
- aitemstack[l] = ItemStack.EMPTY;
- }
- }
- AssemblyRecipes assemblyrecipe = new AssemblyRecipes(j, k, aitemstack, stack);
- this.recipes.add(assemblyrecipe);
- return assemblyrecipe;
- }
- public ItemStack findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
- {
- for (IRecipe irecipe : this.recipes)
- {
- if (irecipe.matches(craftMatrix, worldIn))
- {
- return irecipe.getCraftingResult(craftMatrix);
- }
- }
- return ItemStack.EMPTY;
- }
- public NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
- {
- for (IRecipe irecipe : this.recipes)
- {
- if (irecipe.matches(craftMatrix, worldIn))
- {
- return irecipe.getRemainingItems(craftMatrix);
- }
- }
- NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);
- for (int i = 0; i < nonnulllist.size(); ++i)
- {
- nonnulllist.set(i, craftMatrix.getStackInSlot(i));
- }
- return nonnulllist;
- }
- public void addRecipe(IRecipe recipe)
- {
- this.recipes.add(recipe);
- }
- public List getRecipeList()
- {
- return this.recipes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement