Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. package ed.enderdeath.mod.AnvilDragon;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import com.google.common.collect.Lists;
  7.  
  8. import net.minecraft.inventory.InventoryCrafting;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.item.crafting.IRecipe;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.common.ForgeHooks;
  13. import net.minecraftforge.oredict.OreDictionary;
  14.  
  15. public class TutorielShapelessRecipe implements IRecipe {
  16.  
  17. /** Is the ItemStack that you get when craft the recipe. */
  18. private final ItemStack recipeOutput;
  19. /** Is a List of ItemStack that composes the recipe. */
  20. public final List recipeItems;
  21. private static int getHeight;
  22. private static int getWidth;
  23. public TutorielShapelessRecipe(ItemStack output, List inputList)
  24. {
  25. this.recipeOutput = output;
  26. this.recipeItems = inputList;
  27. }
  28.  
  29. public ItemStack getRecipeOutput()
  30. {
  31. return this.recipeOutput;
  32. }
  33.  
  34. public ItemStack[] getRemainingItems(InventoryCrafting inv)
  35. {
  36. ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
  37. for (int i = 0; i < aitemstack.length; ++i)
  38. {
  39. ItemStack itemstack = inv.getStackInSlot(i);
  40. aitemstack[i] = recipeOutput.getItem().getContainerItem(recipeOutput);
  41. }
  42. return aitemstack;
  43. }
  44.  
  45. /**
  46. * Used to check if a recipe matches current crafting inventory
  47. * Retourne true si la recette correspond à la matrice donnée (le craft que le joueur a fait)
  48. *
  49. * La fonction prend une liste des items requis pour le craft, puis pour chaque item rencontré dans la matrice, le retire de la liste des items,
  50. * si la liste ne contient pas l'item, c'est qu'il y a un item en trop dans le craft et la fonction retourne false, à la fin, si la liste est vide, la
  51. * fonction retourne true.
  52. */
  53. public boolean matches(InventoryCrafting inv, World worldIn)
  54. {
  55. ArrayList arraylist = Lists.newArrayList(this.recipeItems); //Copie les items du craft dans une nouvelle liste
  56. for (int i = 0; i < this.getHeight(); ++i)
  57. {
  58. for (int j = 0; j < this.getWidth(); ++j)
  59. {
  60. ItemStack itemstack = inv.getStackInRowAndColumn(j, i);
  61. if (itemstack != null)
  62. {
  63. boolean flag = false;
  64. for(Object component : arraylist)
  65. {
  66. if(component instanceof String) //Search in ore dictionary
  67. {
  68. List<ItemStack> stacks = OreDictionary.getOres((String) component);
  69. for(ItemStack itemstack1 : stacks)
  70. {
  71. if (TutorielShapedRecipes.areItemStacksEquals(itemstack, itemstack1))
  72. {
  73. flag = true;
  74. arraylist.remove(itemstack1);
  75. break;
  76. }
  77. }
  78. }
  79. else
  80. {
  81. ItemStack itemstack1 = (ItemStack)component;
  82. if (TutorielShapedRecipes.areItemStacksEquals(itemstack, itemstack1))
  83. {
  84. flag = true;
  85. arraylist.remove(itemstack1);
  86. break;
  87. }
  88. }
  89. }
  90. if (!flag)
  91. return false;
  92. }
  93. }
  94. }
  95. return arraylist.isEmpty();
  96. }
  97.  
  98. private int getWidth() {
  99. return getWidth;
  100. }
  101.  
  102. private int getHeight() {
  103. return getHeight;
  104. }
  105.  
  106. /**
  107. * Returns an Item that is the result of this recipe
  108. */
  109. public ItemStack getCraftingResult(InventoryCrafting inv)
  110. {
  111. return this.recipeOutput.copy();
  112. }
  113.  
  114. /**
  115. * Returns the size of the recipe area
  116. */
  117. public int getRecipeSize()
  118. {
  119. return this.recipeItems.size();
  120. }
  121.  
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement