shane020482

Init/Register

May 25th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. @Mod.EventBusSubscriber(modid = Reference.MOD_ID)
  2.  
  3. public class BlockInit
  4. {
  5. //this is where you put all the blocks you want to add this is just a local variable so that you can reference you block throughout the rest of this class
  6. static Block block_test;
  7. static Block block_test2;
  8.  
  9.  
  10. //this is where you initialize your block. aka tell the game all about your block
  11. public static void init()
  12. {
  13. //this is where the order of your parameters come in if you dont do this in the same order you will get errors thats why i comment in the order just so i have a reference in this class
  14. //name, material, hardness, resistance, harvest level(tool, level), Creative Tab, Sound, Light
  15. //To Initialize your block use the name that you gave it from above and point it to your BlockBase. It will ask to add arguments from BlockBase just say yes and it will give you the parameters to fill in just fill them in in the order from your BlockBase and done.If you dont need a parameter just zero it out like i did with the light level.
  16. block_test = new BlockBase("block_test", Material.ROCK, 5f, 30f, "pickaxe", 2, CreativeTabs.DECORATIONS, SoundType.METAL, 0f);
  17. block_test2 = new BlockBase("block_test", Material.IRON, 5f, 30f, "pickaxe", 1, CreativeTabs.DECORATIONS, SoundType.METAL, 0f);
  18. }
  19.  
  20.  
  21. //Now we can register our blocks in the same class
  22.  
  23. //First we need to register the block its self just use event.getRegistry().registerAll(block name from above);
  24. @SubscribeEvent
  25. public static void registerBlocks(RegistryEvent.Register<Block> event)
  26. {
  27. event.getRegistry().registerAll(block_test);
  28. event.getRegistry().registerAll(block_test2);
  29. }
  30.  
  31. Next we need to register the item block(what the player sees in there inventory)just use event.getRegistry().registerAll(new ItemBlock(name from above).setRegistryName(name from above.getRegistryName()));
  32. @SubscribeEvent
  33. public static void registerItemBlocks(RegistryEvent.Register<Item> event)
  34. {
  35. event.getRegistry().registerAll(new ItemBlock(block_test).setRegistryName(block_test.getRegistryName()));
  36. event.getRegistry().registerAll(new ItemBlock(block_test2).setRegistryName(block_test2.getRegistryName()));
  37. }
  38.  
  39. //The next we register the models just use registerRender(Item.getItemFromBlock(name from above));
  40. @SubscribeEvent
  41. public static void registerRenders(ModelRegistryEvent event)
  42. {
  43. registerRender(Item.getItemFromBlock(block_test));
  44. registerRender(Item.getItemFromBlock(block_test2));
  45. }
  46.  
  47. //And the last method points to the model resource location you dont need to do any thing here it just works
  48. public static void registerRender(Item item)
  49. {
  50. ModelLoader.setCustomModelResourceLocation(item, 0,
  51. new ModelResourceLocation(item.getRegistryName(), "inventory"));
  52. }
  53. }
Add Comment
Please, Sign In to add comment