Guest User

Untitled

a guest
Mar 1st, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. public class AssemblyRecipes implements IRecipe {
  2.  
  3.  
  4. /** How many horizontal slots this recipe is wide. */
  5. public final int recipeWidth;
  6. /** How many vertical slots this recipe uses. */
  7. public final int recipeHeight;
  8. /** Is a array of ItemStack that composes the recipe. */
  9. public final ItemStack[] recipeItems;
  10.  
  11. /** Is the itemID of the output item that you get when craft the recipe. */
  12. public final ItemStack recipeOutput;
  13. private boolean copyIngredientNBT;
  14.  
  15. public AssemblyRecipes(int width, int height, ItemStack[] ingredientsIn, ItemStack output)
  16. {
  17. this.recipeWidth = width;
  18. this.recipeHeight = height;
  19. this.recipeItems = ingredientsIn;
  20.  
  21. for (int i = 0; i < this.recipeItems.length; ++i)
  22. {
  23. if (this.recipeItems[i] == null)
  24. {
  25. this.recipeItems[i] = ItemStack.EMPTY;
  26. }
  27. }
  28. this.recipeOutput = output;
  29. }
  30.  
  31. @Override
  32. public ItemStack getRecipeOutput()
  33. {
  34. return this.recipeOutput;
  35. }
  36.  
  37. @Override
  38. public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
  39. {
  40. NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
  41. for (int i = 0; i < nonnulllist.size(); ++i)
  42. {
  43. ItemStack itemstack = inv.getStackInSlot(i);
  44. nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
  45. }
  46. return nonnulllist;
  47. }
  48.  
  49. /**
  50. * Used to check if a recipe matches current crafting inventory
  51. */
  52. @Override
  53. public boolean matches(InventoryCrafting inv, World worldIn)
  54. {
  55. for (int i = 0; i <= 3 - this.recipeWidth; ++i)
  56. {
  57. for (int j = 0; j <= 3 - this.recipeHeight; ++j)
  58. {
  59. if (this.checkMatch(inv, i, j, true))
  60. {
  61. return true;
  62. }
  63.  
  64. if (this.checkMatch(inv, i, j, false))
  65. {
  66. return true;
  67. }
  68. }
  69. }
  70. return false;
  71. }
  72.  
  73. /**
  74. * Checks if the region of a crafting inventory is match for the recipe.
  75. */
  76. private boolean checkMatch(InventoryCrafting p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_)
  77. {
  78. for (int i = 0; i < 3; ++i)
  79. {
  80. for (int j = 0; j < 3; ++j)
  81. {
  82. int k = i - p_77573_2_;
  83. int l = j - p_77573_3_;
  84. ItemStack itemstack = ItemStack.EMPTY;
  85.  
  86. if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight)
  87. {
  88. if (p_77573_4_)
  89. {
  90. itemstack = this.recipeItems[this.recipeWidth - k - 1 + l * this.recipeWidth];
  91. }
  92. else
  93. {
  94. itemstack = this.recipeItems[k + l * this.recipeWidth];
  95. }
  96. }
  97.  
  98. ItemStack itemstack1 = p_77573_1_.getStackInRowAndColumn(i, j);
  99.  
  100. if (!itemstack1.isEmpty() || !itemstack.isEmpty())
  101. {
  102. if (itemstack1.isEmpty() != itemstack.isEmpty())
  103. {
  104. return false;
  105. }
  106.  
  107. if (itemstack.getItem() != itemstack1.getItem())
  108. {
  109. return false;
  110. }
  111.  
  112. if (itemstack.getMetadata() != 32767 && itemstack.getMetadata() != itemstack1.getMetadata())
  113. {
  114. return false;
  115. }
  116. }
  117. }
  118. }
  119.  
  120. return true;
  121. }
  122.  
  123. /**
  124. * Returns an Item that is the result of this recipe
  125. */
  126. @Override
  127. public ItemStack getCraftingResult(InventoryCrafting inv)
  128. {
  129. ItemStack itemstack = this.getRecipeOutput().copy();
  130.  
  131. if (this.copyIngredientNBT)
  132. {
  133. for (int i = 0; i < inv.getSizeInventory(); ++i)
  134. {
  135. ItemStack itemstack1 = inv.getStackInSlot(i);
  136.  
  137. if (!itemstack1.isEmpty() && itemstack1.hasTagCompound())
  138. {
  139. itemstack.setTagCompound(itemstack1.getTagCompound().copy());
  140. }
  141. }
  142. }
  143. return itemstack;
  144. }
  145.  
  146. /**
  147. * Returns the size of the recipe area
  148. */
  149. @Override
  150. public int getRecipeSize()
  151. {
  152. return this.recipeWidth * this.recipeHeight;
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment