Modding 1.4.7: Basic Block Part 2

In this tutorial I will show you how to make the Block file that you will need to add a basic Block to minecraft. This is the code in the mod file from the last tutorial.


package tutorial;

import net.minecraft.block.Block;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block tutorialBlock;

@Init
public void load(FMLInitializationEvent event)
{
tutorialBlock = new BlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);

GameRegistry.registerBlock(tutorialBlock);

LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
}
}


In this tutorial all you don’t have to do anything in the mod file. Just click on the package of this mod or hover your mouse over the BlockTutorialBlock error and create a class with that name.
When you create the file it will probably look like this.


package tutorial;

public class BlockTutorialBlock {

}


The first thing that you will have to do is make BlockTutorialBlock extend Block. Do this by adding this to the file.


package tutorial;

import net.minecraft.block.Block;

public class BlockTutorialBlock extends Block
{

}


When you do this you will get an error under BlockTutorialBlock. To fix this you will have to add this method.


public BlockTutorialBlock(int id, int texture)
{
super(id, texture, Material.cloth);
}


You need to make sure that the method is public FileName and that it contains 2 integers inside of the brackets. You can change the names of those 2 numbers into anything you want, but the names they have right now are their functions.
The line inside of the method with super tells the Block file what the id and the texture number of the block is. It also tells Block which kind of material it is made out of. In this case the material is cloth. Making it minable by certain items, but not with others. Material can also add some other interesting properties like making it impossible to be moved by a piston, but that doesn’t count for cloth. To find out all the materials go to net.minecraft.src.Material.

Another line that you might want to add is on which creative tab in the creative menu it should be shown. To do this you have to add this line inside of the method.


this.setCreativeTab(CreativeTabs.tabBlock);


CreativeTabs is the file that contains all the tabs from the creative inventory and tabBlock is the one you start out in when you open up the inventory on creative mode.

The whole file should now look like this.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;


public class BlockTutorialBlock extends Block
{
public BlockTutorialBlock(int id, int texture)
{
super(id, texture, Material.cloth);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}


You can download the source code over here.
In the next tutorials I will show you how to add some special settings to a block like being able to walk through it etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">