ModBlocks.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package me.km.blocks;
  2. import me.km.fluids.BlockFluidBase;
  3. import me.km.fluids.BlockFluidHoney;
  4. import me.km.fluids.BlockFluidPoison;
  5. import me.km.fluids.ModFluids;
  6. import me.km.items.ItemMetal;
  7. import me.km.items.ModItems;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.MapColor;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.creativetab.CreativeTabs;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemBlock;
  15. import net.minecraftforge.fml.common.registry.GameRegistry;
  16. import net.minecraftforge.registries.IForgeRegistry;
  17. public class ModBlocks
  18. {
  19. // ores + blocks
  20. public static BlockOre copperOre;
  21. public static BlockBase copperBlock;
  22. public static BlockOre tinOre;
  23. public static BlockBase tinBlock;
  24. public static BlockBase bronzeBlock;
  25. public static BlockOre silverOre;
  26. public static BlockBase silverBlock;
  27. // misc
  28. public static BlockBase guildblock;
  29. public static BlockBase artefact;
  30. public static BlockHay realHayBlock;
  31. public static BlockHayBed realHayBed;
  32. public static BlockBase crateAcacia;
  33. public static BlockBase crateBigOak;
  34. public static BlockBase crateBirch;
  35. public static BlockBase crateJungle;
  36. public static BlockBase crateOak;
  37. public static BlockBase crateSpruce;
  38. public static BlockWoodCauldron cauldronOak;
  39. public static BlockWoodCauldron cauldronBirch;
  40. public static BlockWoodCauldron cauldronAcacia;
  41. public static BlockWoodCauldron cauldronJungle;
  42. public static BlockWoodCauldron cauldronSpruce;
  43. public static BlockWoodCauldron cauldronBigOak;
  44. public static BlockCampFire campFire;
  45. public static BlockCampFireBurning campFireBurning;
  46. public static BlockCampFireBurnt campFireBurnt;
  47. // traps
  48. public static BlockSpikeTrap spikes;
  49. // fluids
  50. public static BlockFluidPoison poison;
  51. public static BlockFluidHoney honey;
  52. public static void initBlocks(IForgeRegistry<Block> r)
  53. {
  54. // ores + blocks
  55. copperOre = register(r, new BlockOre("copper_ore", "oreCopper"));
  56. copperBlock = register(r, (BlockBase) new BlockBase(Material.IRON, "copper_block", "blockCopper")
  57. .setMapColor(MapColor.BROWN).setHardness(3).setResistance(10));
  58. tinOre = register(r, new BlockOre("tin_ore", "oreTin"));
  59. tinBlock = register(r, (BlockBase) new BlockBase(Material.IRON, "tin_block", "blockTin")
  60. .setMapColor(MapColor.IRON).setHardness(3).setResistance(5));
  61. bronzeBlock = register(r, (BlockBase) new BlockBase(Material.IRON, "bronze_block", "blockBronze")
  62. .setMapColor(MapColor.YELLOW).setHardness(5).setResistance(10));
  63. silverOre = register(r, new BlockOre("silver_ore", "oreSilver"));
  64. silverBlock = register(r, (BlockBase) new BlockBase(Material.IRON, "silver_block", "blockSilver")
  65. .setMapColor(MapColor.IRON).setHardness(5).setResistance(10));
  66. // misc
  67. guildblock = register(r, (BlockBase) new BlockBase(Material.IRON, "guild_block", "blockGuild")
  68. .setHardness(50.0F).setResistance(2000.0F));
  69. artefact = register(r, (BlockBase) new BlockBase(Material.IRON, "artefact", "artefact")
  70. .setHardness(50.0F).setResistance(2000.0F));
  71. realHayBlock = register(r, new BlockHay("real_hay_block", "realHayBlock"));
  72. realHayBed = register(r, new BlockHayBed("real_hay_bed", "realHayBed"));
  73. crateAcacia = register(r, new BlockBase(Material.WOOD, "crate_acacia", "crateAcacia").setCreativeTab(CreativeTabs.DECORATIONS));
  74. crateBigOak = register(r, new BlockBase(Material.WOOD, "crate_big_oak", "crateBigOak").setCreativeTab(CreativeTabs.DECORATIONS));
  75. crateBirch = register(r, new BlockBase(Material.WOOD, "crate_birch", "crateBirch").setCreativeTab(CreativeTabs.DECORATIONS));
  76. crateJungle = register(r, new BlockBase(Material.WOOD, "crate_jungle", "crateJungle").setCreativeTab(CreativeTabs.DECORATIONS));
  77. crateOak = register(r, new BlockBase(Material.WOOD, "crate_oak", "crateOak").setCreativeTab(CreativeTabs.DECORATIONS));
  78. crateSpruce = register(r, new BlockBase(Material.WOOD, "crate_spruce", "crateSpruce").setCreativeTab(CreativeTabs.DECORATIONS));
  79. cauldronOak = register(r, new BlockWoodCauldron("cauldron_oak", "cauldronOak"));
  80. cauldronBirch = register(r, new BlockWoodCauldron("cauldron_birch", "cauldronBirch"));
  81. cauldronAcacia = register(r, new BlockWoodCauldron("cauldron_acacia", "cauldronAcacia"));
  82. cauldronJungle = register(r, new BlockWoodCauldron("cauldron_jungle", "cauldronJungle"));
  83. cauldronSpruce = register(r, new BlockWoodCauldron("cauldron_spruce", "cauldronSpruce"));
  84. cauldronBigOak = register(r, new BlockWoodCauldron("cauldron_big_oak", "cauldronBigOak"));
  85. GameRegistry.registerTileEntity(TileEntityCauldron.class, "km:cauldron");
  86. campFire = register(r, new BlockCampFire("camp_fire", "campFire"));
  87. campFireBurning = (BlockCampFireBurning) register(r, new BlockCampFireBurning("camp_fire_burning", "campFireBurning")).setLightLevel(1);
  88. campFireBurnt = register(r, new BlockCampFireBurnt("camp_fire_burnt", "campFireBurnt"));
  89. GameRegistry.registerTileEntity(TileEntityCampFire.class, campFireBurning.getRegistryName().toString());
  90. // traps
  91. spikes = register(r, new BlockSpikeTrap(Material.IRON, "spikes", "spikes"));
  92. // fluids
  93. poison = register(r, new BlockFluidPoison(ModFluids.poison, Material.WATER));
  94. honey = register(r, new BlockFluidHoney(ModFluids.honey, Material.WATER));
  95. // overwrites
  96. register(r, Blocks.FARMLAND, new BlockNoTrampleFarmland());
  97. }
  98. private static void register(IForgeRegistry<Block> r, Block old, Block newBlock)
  99. {
  100. newBlock.setRegistryName(old.getRegistryName());
  101. r.register(newBlock);
  102. }
  103. public static void initItemBlocks(IForgeRegistry<Item> r)
  104. {
  105. // ores + blocks
  106. register(r, copperOre, getItemBlock(copperOre));
  107. register(r, copperBlock, getItemBlock(copperBlock));
  108. register(r, tinOre, getItemBlock(tinOre));
  109. register(r, tinBlock, getItemBlock(tinBlock));
  110. register(r, bronzeBlock, getItemBlock(bronzeBlock));
  111. register(r, silverOre, getItemBlock(silverOre));
  112. register(r, silverBlock, getItemBlock(silverBlock));
  113. // misc
  114. register(r, guildblock, getItemBlock(guildblock));
  115. register(r, artefact, getItemBlock(artefact));
  116. register(r, realHayBlock, getItemBlock(realHayBlock));
  117. register(r, crateAcacia, getItemBlock(crateAcacia));
  118. register(r, crateBigOak, getItemBlock(crateBigOak));
  119. register(r, crateBirch, getItemBlock(crateBirch));
  120. register(r, crateJungle, getItemBlock(crateJungle));
  121. register(r, crateOak, getItemBlock(crateOak));
  122. register(r, crateSpruce, getItemBlock(crateSpruce));
  123. cauldronOak.setItem(ModItems.cauldronOak);
  124. cauldronBirch.setItem(ModItems.cauldronBirch);
  125. cauldronAcacia.setItem(ModItems.cauldronAcacia);
  126. cauldronJungle.setItem(ModItems.cauldronJungle);
  127. cauldronSpruce.setItem(ModItems.cauldronSpruce);
  128. cauldronBigOak.setItem(ModItems.cauldronBigOak);
  129. // traps
  130. register(r, spikes, getItemMetal(spikes));
  131. // fluids
  132. register(r, poison, getItemBlock(poison));
  133. register(r, honey, getItemBlock(honey));
  134. }
  135. private static void register(IForgeRegistry<Item> r, Block block, Item itemBlock)
  136. {
  137. r.register(itemBlock);
  138. if(block instanceof IBlockBase)
  139. {
  140. ((IBlockBase) block).registerItemModel(itemBlock);
  141. }
  142. if(block instanceof BlockFluidBase)
  143. {
  144. ((BlockFluidBase) block).registerBlockModel();
  145. }
  146. }
  147. private static <T extends Block> T register(IForgeRegistry<Block> r, T block)
  148. {
  149. r.register(block);
  150. return block;
  151. }
  152. private static ItemBlock getItemBlock(Block block)
  153. {
  154. ItemBlock itemBlock = new ItemBlock(block);
  155. itemBlock.setRegistryName(block.getRegistryName());
  156. return itemBlock;
  157. }
  158. private static ItemMetal getItemMetal(Block block)
  159. {
  160. ItemMetal itemBlock = new ItemMetal(block);
  161. itemBlock.setRegistryName(block.getRegistryName());
  162. return itemBlock;
  163. }
  164. }