ModRecipes.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package me.km.items;
  2. import me.km.blocks.EnumMetals;
  3. import me.km.blocks.ModBlocks;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.init.Blocks;
  6. import net.minecraft.init.Items;
  7. import net.minecraft.item.EnumDyeColor;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.item.crafting.CraftingManager;
  11. import net.minecraft.item.crafting.FurnaceRecipes;
  12. public class ModRecipes
  13. {
  14. public static void init()
  15. {
  16. CraftingManager cm = CraftingManager.getInstance();
  17. FurnaceRecipes fr = FurnaceRecipes.instance();
  18. // misc
  19. cm.addShapelessRecipe(new ItemStack(ModItems.bronzeIngot, 9), new Object[]
  20. {
  21. ModItems.copperIngot, ModItems.copperIngot, ModItems.copperIngot,
  22. ModItems.copperIngot, ModItems.copperIngot, ModItems.copperIngot,
  23. ModItems.copperIngot, ModItems.copperIngot, ModItems.tinIngot
  24. });
  25. cm.addRecipe(new ItemStack(ModItems.realHayBed, 3), new Object[] {"XXX", 'X', ModBlocks.realHayBlock});
  26. cm.addRecipe(new ItemStack(ModItems.strawHat, 1), new Object[] {" X ", "XXX", 'X', Items.WHEAT});
  27. // traps
  28. addMetalRecipes(cm, new String[] {" X ", "XXX"}, ModBlocks.spikes, 3);
  29. // furnace recipes
  30. fr.addSmeltingRecipeForBlock(ModBlocks.copperOre, new ItemStack(ModItems.copperIngot), 0.5f);
  31. fr.addSmeltingRecipeForBlock(ModBlocks.tinOre, new ItemStack(ModItems.tinIngot), 1);
  32. fr.addSmeltingRecipeForBlock(ModBlocks.silverOre, new ItemStack(ModItems.silverIngot), 1);
  33. // armor recipes
  34. Item[][] armorItems = new Item[][]
  35. {
  36. {ModItems.copperIngot, ModItems.bronzeIngot},
  37. {ModItems.copperHelmet, ModItems.bronzeHelmet},
  38. {ModItems.copperChestplate, ModItems.bronzeChestplate},
  39. {ModItems.copperLeggings, ModItems.bronzeLeggings},
  40. {ModItems.copperBoots, ModItems.bronzeBoots}
  41. };
  42. addArmorRecipes(cm, armorItems);
  43. // additionel old tool recipes
  44. String[][] toolPatterns = new String[][] {{"XXX", " # ", " # "}, {"X", "#", "#"}, {"XX", "X#", " #"}, {"XX", " #", " #"}};
  45. Object[][] toolItems = new Object[][]
  46. {
  47. {ModItems.copperIngot, ModItems.bronzeIngot},
  48. {ModItems.copperPickaxe, ModItems.bronzePickaxe},
  49. {ModItems.copperShovel, ModItems.bronzeShovel},
  50. {ModItems.copperAxe, ModItems.bronzeAxe},
  51. {ModItems.copperHoe, ModItems.bronzeHoe}
  52. };
  53. addToolRecipes(cm, toolPatterns, toolItems);
  54. // new tool / weapon recipes
  55. toolPatterns = new String[][] {{"X ", " # ", " X"}, {" X", "# "}, {"XXX", "X#X", " # "}};
  56. toolItems = new Object[][]
  57. {
  58. {Blocks.PLANKS, Blocks.COBBLESTONE, Items.IRON_INGOT, Items.DIAMOND,
  59. Items.GOLD_INGOT, ModItems.copperIngot, ModItems.bronzeIngot},
  60. {ModItems.woodenStick, ModItems.stoneStick, ModItems.ironStick, ModItems.diamondStick,
  61. ModItems.goldStick, ModItems.copperStick, ModItems.bronzeStick},
  62. {ModItems.woodenDagger, ModItems.stoneDagger, ModItems.ironDagger, ModItems.diamondDagger,
  63. ModItems.goldDagger, ModItems.copperDagger, ModItems.bronzeDagger},
  64. {ModItems.woodenHammer, ModItems.stoneHammer, ModItems.ironHammer, ModItems.diamondHammer,
  65. ModItems.goldHammer, ModItems.copperHammer, ModItems.bronzeHammer},
  66. };
  67. addToolRecipes(cm, toolPatterns, toolItems);
  68. // wands
  69. toolPatterns = new String[][] {{" #X", " ##", "# "}};
  70. toolItems = new Object[][]
  71. {
  72. {Blocks.PLANKS, Blocks.COBBLESTONE, Items.IRON_INGOT, Items.DIAMOND, Items.GOLD_INGOT,
  73. ModItems.copperIngot, ModItems.bronzeIngot, Items.EMERALD, Items.REDSTONE,
  74. new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()), ModItems.silverIngot},
  75. {ModItems.woodenWand, ModItems.stoneWand, ModItems.ironWand, ModItems.diamondWand, ModItems.goldWand,
  76. ModItems.copperWand, ModItems.bronzeWand, ModItems.emeraldWand, ModItems.redstoneWand,
  77. ModItems.lapisWand, ModItems.silverWand},
  78. };
  79. addToolRecipes(cm, toolPatterns, toolItems);
  80. // additionel old weapon recipes
  81. Object[][] weaponItems = new Object[][]
  82. {
  83. {ModItems.copperIngot, ModItems.bronzeIngot},
  84. {ModItems.copperSword, ModItems.bronzeSword}
  85. };
  86. addWeaponRecipes(cm, weaponItems);
  87. // block <-> parts <-> smaller parts recipes
  88. Object[][] ingotItems = new Object[][]
  89. {
  90. {ModBlocks.copperBlock, new ItemStack(ModItems.copperIngot, 9)},
  91. {ModItems.copperIngot, new ItemStack(ModItems.copperNugget, 9)},
  92. {ModBlocks.tinBlock, new ItemStack(ModItems.tinIngot, 9)},
  93. {ModItems.tinIngot, new ItemStack(ModItems.tinNugget, 9)},
  94. {ModBlocks.bronzeBlock, new ItemStack(ModItems.bronzeIngot, 9)},
  95. {ModItems.bronzeIngot, new ItemStack(ModItems.bronzeNugget, 9)},
  96. {ModBlocks.silverBlock, new ItemStack(ModItems.silverIngot, 9)},
  97. {ModItems.silverIngot, new ItemStack(ModItems.silverNugget, 9)},
  98. {ModBlocks.realHayBlock, new ItemStack(ModItems.hayBundle, 9)},
  99. };
  100. addIngotRecipes(cm, ingotItems);
  101. addNuggetRecipes(fr, toolItems, armorItems, weaponItems, ModItems.copperNugget, ModItems.bronzeNugget);
  102. }
  103. private static void addArmorRecipes(CraftingManager cm, Item[][] armorItems)
  104. {
  105. String[][] armorPatterns = new String[][] {{"XXX", "X X"}, {"X X", "XXX", "XXX"}, {"XXX", "X X", "X X"}, {"X X", "X X"}};
  106. for (int i = 0; i < armorItems[0].length; ++i)
  107. {
  108. Item item = armorItems[0][i];
  109. for (int j = 0; j < armorItems.length - 1; ++j)
  110. {
  111. Item item2 = armorItems[j + 1][i];
  112. cm.addRecipe(new ItemStack(item2), new Object[] {armorPatterns[j], 'X', item});
  113. }
  114. }
  115. }
  116. private static void addToolRecipes(CraftingManager cm, String[][] toolPatterns, Object[][] toolItems)
  117. {
  118. for(int i = 0; i < toolItems[0].length; ++i)
  119. {
  120. Object object = toolItems[0][i];
  121. for(int j = 0; j < toolItems.length - 1; ++j)
  122. {
  123. Item item = (Item) toolItems[j + 1][i];
  124. cm.addRecipe(new ItemStack(item), new Object[] {toolPatterns[j], '#', Items.STICK, 'X', object});
  125. }
  126. }
  127. }
  128. private static void addWeaponRecipes(CraftingManager cm, Object[][] weaponItems)
  129. {
  130. String[][] weaponPatterns = new String[][] {{"X", "X", "#"}};
  131. for(int i = 0; i < weaponItems[0].length; ++i)
  132. {
  133. Object object = weaponItems[0][i];
  134. for(int j = 0; j < weaponItems.length - 1; ++j)
  135. {
  136. Item item = (Item) weaponItems[j + 1][i];
  137. cm.addRecipe(new ItemStack(item), new Object[] {weaponPatterns[j], '#', Items.STICK, 'X', object});
  138. }
  139. }
  140. }
  141. private static void addIngotRecipes(CraftingManager cm, Object[][] ingotItems)
  142. {
  143. for(Object[] aobject : ingotItems)
  144. {
  145. try
  146. {
  147. Item block = (Item) aobject[0];
  148. ItemStack parts = (ItemStack) aobject[1];
  149. ItemStack ingot = parts.copy();
  150. ingot.setCount(1);
  151. cm.addRecipe(new ItemStack(block), new Object[] {"###", "###", "###", '#', ingot});
  152. cm.addRecipe(parts, new Object[] {"#", '#', block});
  153. }
  154. catch(ClassCastException ex)
  155. {
  156. Block block = (Block) aobject[0];
  157. ItemStack parts = (ItemStack) aobject[1];
  158. ItemStack ingot = parts.copy();
  159. ingot.setCount(1);
  160. cm.addRecipe(new ItemStack(block), new Object[] {"###", "###", "###", '#', ingot});
  161. cm.addRecipe(parts, new Object[] {"#", '#', block});
  162. }
  163. }
  164. }
  165. private static void addNuggetRecipes(FurnaceRecipes fr, Object[][] toolItems, Item[][] armorItems, Object[][] weaponItems, Item... nuggets)
  166. {
  167. for(int i = 0; i < nuggets.length; i++)
  168. {
  169. for(int j = 1; j < toolItems.length; j++)
  170. {
  171. fr.addSmelting((Item) toolItems[j][i], new ItemStack(nuggets[i]), 0.1f);
  172. }
  173. for(int j = 1; j < armorItems.length; j++)
  174. {
  175. fr.addSmelting((Item) armorItems[j][i], new ItemStack(nuggets[i]), 0.1f);
  176. }
  177. for(int j = 1; j < weaponItems.length; j++)
  178. {
  179. fr.addSmelting((Item) weaponItems[j][i], new ItemStack(nuggets[i]), 0.1f);
  180. }
  181. }
  182. }
  183. private static void addMetalRecipes(CraftingManager cm, String[] patterns, Item output, int amount)
  184. {
  185. for(EnumMetals metal : EnumMetals.values())
  186. {
  187. cm.addRecipe(new ItemStack(output, amount, metal.getMetadata()),
  188. new Object[] {patterns, 'X', metal.getMetalIngot()});
  189. }
  190. }
  191. private static void addMetalRecipes(CraftingManager cm, String[] patterns, Block output, int amount)
  192. {
  193. addMetalRecipes(cm, patterns, Item.getItemFromBlock(output), amount);
  194. }
  195. }