Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Mod.EventBusSubscriber(modid = Reference.MOD_ID)
- public class BlockInit
- {
- //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
- static Block block_test;
- static Block block_test2;
- //this is where you initialize your block. aka tell the game all about your block
- public static void init()
- {
- //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
- //name, material, hardness, resistance, harvest level(tool, level), Creative Tab, Sound, Light
- //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.
- block_test = new BlockBase("block_test", Material.ROCK, 5f, 30f, "pickaxe", 2, CreativeTabs.DECORATIONS, SoundType.METAL, 0f);
- block_test2 = new BlockBase("block_test", Material.IRON, 5f, 30f, "pickaxe", 1, CreativeTabs.DECORATIONS, SoundType.METAL, 0f);
- }
- //Now we can register our blocks in the same class
- //First we need to register the block its self just use event.getRegistry().registerAll(block name from above);
- @SubscribeEvent
- public static void registerBlocks(RegistryEvent.Register<Block> event)
- {
- event.getRegistry().registerAll(block_test);
- event.getRegistry().registerAll(block_test2);
- }
- 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()));
- @SubscribeEvent
- public static void registerItemBlocks(RegistryEvent.Register<Item> event)
- {
- event.getRegistry().registerAll(new ItemBlock(block_test).setRegistryName(block_test.getRegistryName()));
- event.getRegistry().registerAll(new ItemBlock(block_test2).setRegistryName(block_test2.getRegistryName()));
- }
- //The next we register the models just use registerRender(Item.getItemFromBlock(name from above));
- @SubscribeEvent
- public static void registerRenders(ModelRegistryEvent event)
- {
- registerRender(Item.getItemFromBlock(block_test));
- registerRender(Item.getItemFromBlock(block_test2));
- }
- //And the last method points to the model resource location you dont need to do any thing here it just works
- public static void registerRender(Item item)
- {
- ModelLoader.setCustomModelResourceLocation(item, 0,
- new ModelResourceLocation(item.getRegistryName(), "inventory"));
- }
- }
Add Comment
Please, Sign In to add comment