Guest User

Untitled

a guest
Jul 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. package ed.enderdeath.mod.AnvilDragon;
  2.  
  3. import java.util.List;
  4. import java.util.Map;
  5.  
  6. import com.google.common.collect.Lists;
  7. import com.google.common.collect.Maps;
  8. import com.sun.istack.internal.Nullable;
  9.  
  10. import net.minecraft.block.Block;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.inventory.InventoryCrafting;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.item.crafting.IRecipe;
  17. import net.minecraft.world.World;
  18.  
  19. public class TutorielCraftingManager {
  20. private static final TutorielCraftingManager INSTANCE = new TutorielCraftingManager();
  21. public static TutorielCraftingManager getInstance()
  22. {
  23. return INSTANCE;
  24. }
  25.  
  26. /** La liste des recettes */
  27. private final List<IRecipe> recipes = Lists.<IRecipe>newArrayList();
  28. private Block cratingTable;
  29.  
  30. private TutorielCraftingManager()
  31. {
  32.  
  33. addShapelessRecipe(new ItemStack(Blocks.anvil), Items.carrot, Items.golden_apple);
  34. addRecipe(new ItemStack(cratingTable), " C ", "X X", " C ", 'C', "slabWood", 'X', Blocks.planks); //"slabWood" est le nom des dalles de bois dans l'ore dictionnary, ceci est ajouté par Forge
  35. addRecipe(new ItemStack(Items.golden_apple), "A A", "X X", "X X", "A A", 'A', Items.carrot, 'X', Blocks.planks);
  36.  
  37. }
  38. public TutorielShapedRecipes addRecipe(ItemStack result, Object... recipeComponents)
  39. {
  40. String s = "";
  41. int i = 0;
  42. int j = 0;
  43. int k = 0;
  44. if (recipeComponents[i] instanceof String[])
  45. {
  46. String[] astring = (String[])((String[])recipeComponents[i++]);
  47. for (int l = 0; l < astring.length; ++l)
  48. {
  49. String s2 = astring[l];
  50. ++k;
  51. j = s2.length();
  52. s = s + s2;
  53. }
  54. }
  55. else
  56. {
  57. while (recipeComponents[i] instanceof String)
  58. {
  59. String s1 = (String)recipeComponents[i++];
  60. ++k;
  61. j = s1.length();
  62. s = s + s1;
  63. }
  64. }
  65. Character character;
  66. Map<Character, Object> components = Maps.<Character, Object>newHashMap();
  67. Object in;
  68. for ( ; i < recipeComponents.length; i += 2)
  69. {
  70. in = recipeComponents[i + 1];
  71. Object component = null;
  72. character = (Character)recipeComponents[i];
  73. if (in instanceof Item)
  74. {
  75. component = new ItemStack((Item)recipeComponents[i + 1]);
  76. }
  77. else if (in instanceof Block)
  78. {
  79. component = new ItemStack((Block)recipeComponents[i + 1], 1, 32767);
  80. }
  81. else if (in instanceof ItemStack)
  82. {
  83. component = (ItemStack)recipeComponents[i + 1];
  84. }
  85. else if (in instanceof String)
  86. {
  87. component = (String)in;
  88. }
  89. else
  90. {
  91. throw new IllegalArgumentException("Invalid shaped recipe: unknown type " + in.getClass().getName() + "!");
  92. }
  93. components.put(character, component);
  94. }
  95. Object[] aitemstack = new Object[j * k];
  96. char key;
  97. Object component;
  98. for (int i1 = 0; i1 < j * k; ++i1)
  99. {
  100. key = s.charAt(i1);
  101. if (components.containsKey(Character.valueOf(key)))
  102. {
  103. component = components.get(Character.valueOf(key));
  104. if(component instanceof ItemStack)
  105. aitemstack[i1] = ((ItemStack)component).copy();
  106. else
  107. aitemstack[i1] = component;
  108. }
  109. else
  110. aitemstack[i1] = null;
  111. }
  112. TutorielShapedRecipes shapedrecipes = new TutorielShapedRecipes(j, k, aitemstack, result);
  113. this.recipes.add(shapedrecipes);
  114. return shapedrecipes;
  115. }
  116.  
  117.  
  118. public void addShapelessRecipe(ItemStack result, Object... recipeComponents)
  119. {
  120. List list = Lists.newArrayList();
  121. for (Object component : recipeComponents) //Pour chaque composant de la recette
  122. {
  123. if (component instanceof ItemStack)
  124. {
  125. list.add(((ItemStack)component).copy());
  126. }
  127. else if (component instanceof Item)
  128. {
  129. list.add(new ItemStack((Item)component));
  130. }
  131. else if(component instanceof Block)
  132. {
  133. list.add(new ItemStack((Block)component));
  134. }
  135. else if(component instanceof String) //Pour l'ore dictionnary
  136. {
  137. list.add(component);
  138. }
  139. else throw new IllegalArgumentException("Invalid shapeless recipe: unknown type " + component.getClass().getName() + "!");
  140. }
  141. this.recipes.add(new TutorielShapelessRecipe(result, list));
  142. }
  143. /**
  144. * Adds a shaped recipe to the games recipe list.
  145. */
  146.  
  147. /**
  148. * Adds an IRecipe to the list of crafting recipes.
  149. */
  150. public void addRecipe(IRecipe recipe)
  151. {
  152. this.recipes.add(recipe);
  153. }
  154.  
  155. /**
  156. * Retourne le résultat de la recette ou null si il n'y en a aucun
  157. */
  158. @Nullable
  159. public ItemStack findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
  160. {
  161. for (IRecipe irecipe : this.recipes) //Pour chaque recette
  162. {
  163. if (irecipe.matches(craftMatrix, worldIn)) //Si elle correspond à la matrice actuelle
  164. {
  165. return irecipe.getCraftingResult(craftMatrix); //On donne son résultat
  166. }
  167. }
  168. return null;
  169. }
  170.  
  171. /**
  172. * Retourne les items retants après un craft
  173. */
  174.  
  175. public List<IRecipe> getRecipeList()
  176. {
  177. return this.recipes;
  178. }
  179. }
Add Comment
Please, Sign In to add comment