Tutorial 5: Blocks

In this tutorial we will be adding our very first block to the game.  This is pretty similar to the Item so let's begin!

Create a new class called BlockInit. I have placed this class in my init package just like my ItemInit.

Now we need to create a list where we can initialize all of our Blocks, to do this we need to create a new static ArrayList of BLOCK. Just like this:
	//Creates a new ArrayList for our Block
	public static final List<Block> BLOCK = new ArrayList();
Now we need to add our block, to do this we need to create a new class called Block that extends Block. In this class we can set properties for blocks that don't have any special uses, in the constructor.
public class BlockBase extends Block
	public BlockBase(String name, Material material)

		//Sets the registry and unlocalised name to a string we can change

		//Sets the hardness of the block
		//Adds the Block to the BLOCK List in BlockInit and adds it as an Item in ItemInit
		ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));

Just like items we need parameters in the Constructor, for a block we tend to use a String and String, agiain like an item sets the name, the Material sets the material for the Block.

Go back into BlockInit and initialize your block underneath the ArrayList we made before like this:
public static final Block TUTORIAL_BLOCK = new BlockBase("tutorial_block", Material.ROCK);

Because we didn't set the Material in the BlockBase class we have to do it here.

Now we need to go into our RegistryHandler and add a new method just like onItemRegister but in this case we need to call it onBlockRegister:
public static void onBlockRegister(RegistryEvent.Register event)
	event.getRegistry().registerAll(BlockInit.BLOCKS.toArray(new Block[0]));
Now we need to create another for loop inside the onModelRegister method inside of RegistryHandler. Just like the Item one but for our blocks:
for(Block block: BlockInit.BLOCKS)
	Main.proxy.registerItemRenderer(Item.getItemFromBlock(block), 0, "inventory");

That's it our block should now be in the Game! However it won't have any textures because we haven't added them yet.
To get your block you must do /give @a modid:block_name this is beacuse we haven't assigned it to a creative tab yet.
Now go into your lang file and make a name for your block:
tile.tutorial_block.name=Tutorial Block
Now create a new JSON file in models/item and give it the same name as your items registryName (The string we made in BlockInit). This will be the block's model file where we reference the model/block file:
	"parent": "tutorialmod:block/tutorial_block"
Now create a new package in models called block and create a new JSON file, with the same name of your block and add this to the file:
	"parent": "block/cube_all",
		"all": "tutorialmod:blocks/tutorial_block"
Now we need to add the blockstate, we need to create a new package in our assets package called blockstates and add a new JSON file, again with the same name registry name of your block, and it's contents should look like this:
		"normal": { "model": "tutorialmod:tutorial_block" }
That's it! we now should have a block in our game!

Finally we're finished!  Thank you for following this tutorial, and remember to look out for the next one!
- Mr. Pineapple