Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. public class AssemblyTableCraftingManager {
  2.  
  3.  
  4. private static final AssemblyTableCraftingManager INSTANCE = new AssemblyTableCraftingManager();
  5.  
  6. private final List<IRecipe> recipes = Lists.<IRecipe>newArrayList();
  7.  
  8. public static final AssemblyTableCraftingManager getInstance()
  9. {
  10. return INSTANCE;
  11. }
  12.  
  13. private AssemblyTableCraftingManager()
  14. {
  15. Collections.sort(this.recipes, new Comparator<IRecipe>()
  16. {
  17. public int compare(IRecipe p_compare_1_, IRecipe p_compare_2_)
  18. {
  19. 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)));
  20. }
  21. });
  22. }
  23.  
  24. public AssemblyRecipes addRecipe(ItemStack stack, Object ... recipeComponents)
  25. {
  26. String s = "";
  27. int i = 0;
  28. int j = 0;
  29. int k = 0;
  30.  
  31. if (recipeComponents[i] instanceof String[])
  32. {
  33. String[] astring = (String[])((String[])recipeComponents[i++]);
  34.  
  35. for (String s2 : astring)
  36. {
  37. ++k;
  38. j = s2.length();
  39. s = s + s2;
  40. }
  41. }
  42. else
  43. {
  44. while (recipeComponents[i] instanceof String)
  45. {
  46. String s1 = (String)recipeComponents[i++];
  47. ++k;
  48. j = s1.length();
  49. s = s + s1;
  50. }
  51. }
  52.  
  53. Map<Character, ItemStack> map;
  54.  
  55. for (map = Maps.<Character, ItemStack>newHashMap(); i < recipeComponents.length; i += 2)
  56. {
  57. Character character = (Character)recipeComponents[i];
  58. ItemStack itemstack = ItemStack.EMPTY;
  59.  
  60. if (recipeComponents[i + 1] instanceof Item)
  61. {
  62. itemstack = new ItemStack((Item)recipeComponents[i + 1]);
  63. }
  64. else if (recipeComponents[i + 1] instanceof Block)
  65. {
  66. itemstack = new ItemStack((Block)recipeComponents[i + 1], 1, 32767);
  67. }
  68. else if (recipeComponents[i + 1] instanceof ItemStack)
  69. {
  70. itemstack = (ItemStack)recipeComponents[i + 1];
  71. }
  72.  
  73. map.put(character, itemstack);
  74. }
  75.  
  76. ItemStack[] aitemstack = new ItemStack[j * k];
  77.  
  78. for (int l = 0; l < j * k; ++l)
  79. {
  80. char c0 = s.charAt(l);
  81.  
  82. if (map.containsKey(Character.valueOf(c0)))
  83. {
  84. aitemstack[l] = ((ItemStack)map.get(Character.valueOf(c0))).copy();
  85. }
  86. else
  87. {
  88. aitemstack[l] = ItemStack.EMPTY;
  89. }
  90. }
  91.  
  92. AssemblyRecipes assemblyrecipe = new AssemblyRecipes(j, k, aitemstack, stack);
  93. this.recipes.add(assemblyrecipe);
  94. return assemblyrecipe;
  95. }
  96.  
  97.  
  98. public ItemStack findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
  99. {
  100. for (IRecipe irecipe : this.recipes)
  101. {
  102. if (irecipe.matches(craftMatrix, worldIn))
  103. {
  104. return irecipe.getCraftingResult(craftMatrix);
  105. }
  106. }
  107.  
  108. return ItemStack.EMPTY;
  109. }
  110.  
  111. public NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
  112. {
  113. for (IRecipe irecipe : this.recipes)
  114. {
  115. if (irecipe.matches(craftMatrix, worldIn))
  116. {
  117. return irecipe.getRemainingItems(craftMatrix);
  118. }
  119. }
  120.  
  121. NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);
  122.  
  123. for (int i = 0; i < nonnulllist.size(); ++i)
  124. {
  125. nonnulllist.set(i, craftMatrix.getStackInSlot(i));
  126. }
  127.  
  128. return nonnulllist;
  129. }
  130.  
  131. public void addRecipe(IRecipe recipe)
  132. {
  133. this.recipes.add(recipe);
  134. }
  135.  
  136. public List getRecipeList()
  137. {
  138. return this.recipes;
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement