top of page

Basic Block

Welcome to the basic block tutorial! Last tutorial we set up our mod file. Now to do our first block! The first block for this tutorial will be lead ore. To begin with, im going add a few things into the Constants class. 

As you can see, I added ORE_LEAD_NAME and ORE_LEAD_TEXTURE. ORE_LEAD_NAME is the unlocalized name for the lead ore. ORE_LEAD_TEXTURE is the name for the texture of lead ore. Now make a new package inside oru current one named exactly the same but with ".blocks" at the end so mine is "forgingmc.minecraftthing.blocks". In that we are going to create a new class that registers all of our blocks called "InitBlocks" 

The new code makes a new block. As you can see, we've made a variable block named "ore_lead" outside the init method. Then in the init method, we give the "ore_lead" block variable a new class called LeadOre which extends Block because of the "ore_lead" variable. Now you'll have an error under the lead ore class simply because it doesnt exist yet. Right click it and click make new class. Now the You'll have to import the Block just right click it and press import. Make sure it is minecraft's block. Now Lead Ore will be errored. Right click it and add constructor. Change it from protected to public and get rid of the material parameter in the constructor. Change the super to "Material.rock". Awesome here is what it should look like.

Now lets make it more like a block. In the constructor, add the following methods

Now to explain them. The first one is obvious, we set the creative tab of the block in our case the blocks tab. Our ore will be there when we are in creative mode. The second one is to give our block its unlocalized name. You need your mod_id, an underscore and the unlocalized name. We need the mod_id and the underscore because we are going to make our assets folder with our mod_id so forge knows where to find our block textures and localizations. Next we have the texture, which is exactly the same except we use a colon instead of an underscore and the block texture name. I'll show you how to add them in a bit. Next is the hardness of the block in a floating-point. I've made mine 3 which is about the same as iron. Lastly we have the harvest level. The first String parameter is what tool, ours is the "pickaxe" and the second number parameter is the havest level so whether you need a wooden pickaxe, stone or diamond pickaxe to mine. Java starts at 0 so wood is 0. Stone is 1. Iron is 2. Diamond is 3. I've used 2 which is iron, so you need an iron pickaxe to mine it. Awesome, now we've done this, we can add the name localizations and textures. Lastly, add GameRegistry.registerBlock(this, Constants.ORE_LEAD_NAME); so Forge knows it is a block. 

 

First off lets go into our ForgeWorkspace folder that we made on tutorial one. Open up the folder "Src". The "main". Now open resources. You might or might not see a folder called assets. If there is, cool if not make one. In that folder, make another folder with our mod id name. Mine is "forgingmc". In that folder, make two folders one named "lang" and the other named "textures". The lang folder will contain our language localizations. The other will hold our textures. Lets do the localizations first. Make a new text document called "en_US" in that text document, add the following line.

We add the "tile." at the front because its a block. Next is the mod_id with the underscore like we did in the block class. Now we add the unlocalized name exactly like we did in the block class. Add the ".name" and the equals sign. On the other side of the equal side is the localized name of our block the name that appears in game. Awesome, now our ore will be named "Lead Ore" instead of "tile.forgingmc_ore_lead.name". Sweet! But it still needs a texture, lets go ahead and do that. 

 

In the textures folder, create a new folder named "blocks" this folder will contain all textures required for blocks. These folders MUST because forge looks for textures in a folder called textures called blocks for block textures. Same with items. I've put my texture called "ore_lead" in that folder. Now that is done, we just need to go into our mod file. In the init method, we add Blocks.init(); To add our blocks and done! Just run minecraft and we should see it in the creative tab block. Awesome! See you for the next tutorial which is our basic Item!

bottom of page