Modding: Your first block part 1

In this tutorial you will learn how to create your own ore block in Minecraft.
This is the file you can start with.


package Tutorial.common;

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;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@Init
public void load(FMLInitializationEvent event) 
{

}
}


Now to get a block in your game you will need several lines of code.


public static Block oreblock;


oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);


The file should look like this now.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.ModLoader;
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 = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block oreblock;

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);
}
}


If you add this to your mod file Eclipse should import all the required files like Block and ModLoader automatically. If it doesn’t you should hover your mouse over them and select the thing you want to import. Right now there are 3 Blocks you could import. The one you need is net.minecraft.src.Block.
It will also give red underlines for BlockOres. This is because it is a new file, but you haven’t created it yet. We will do this later. I will first explain what this all means.


public static Block oreblock;


Oreblock is the name you have to use to give certain settings to it.
Public static means that you can find the file anywhere by using: Tutorial.oreblock.
Block is the type of variable that the oreblock is.


oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);


Oreblock is the name of the Block variable you made above.
230 is the block Id.
0 is the texture from the spreadsheet.
New BlockOres is the file where Java will get the settings of the block.
.setStepSound(Block.soundStoneFootstep) is the sound the block will make when you walk over it.
.setHardness(3F) is the hardness of the block. The higher it is the longer it will take to destroy it. You will also need a better pickaxe when it is above certain values.
.setResistance(1.0F) is the explosion resistance of the block.
.setBlockName(“oreblock”) is the name for the block in java. Some people might say that this one doesn’t matter, but if you have 2 things with the same name in there it will not work.


GameRegistry.registerBlock(oreblock);


.registerBlock(oreblock) is the method used to make sure that the game knows that the variable between the brackets is a block. In this case the variable is oreblock.
GameRegistry is the class where the .registerBlock() method can be found. You need to call this file to make it work.


LanguageRegistry.addName(oreblock, “Your Ore”);


This is what gives the in-game name to your block.
LanguageRegistry is the class where you can find the .addName() method.
oreblock is the thing that is given a name.
Your Ore is the name it will have in your game.

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="">