Modding: Your first block part 2

In this part of the tutorial I will show you how to create the BlockOres file.
This was the file you should have.


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”);
}
}


With this you will get an error under BlockOres. To fix this arrow move your mouse arrow over it and select: Create class ‘BlockOres’. You might have to search a bit in the quick fix options to find it.

When you click it you will get a file looking like this:

package Tutorial.common;

public class BlockOres 
{

}

Now you should add this.


public BlockOres(int par1, int par2)
    {
        super(par1, par2, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }


And the file should now look like this.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;

public class BlockOres extends Block
{
    public BlockOres(int par1, int par2)
    {
        super(par1, par2, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
    }
}


package Tutorial.common; tells java where the file is.
The imports are needed to use those files and functions in them.
super(par1, par2, Material.rock) tells the Block file the id, texture and material of the block.
The first 2 of those parameters are set in the mod underscore file. par1 is 230, par2 is 0.

Material is used in code to get the tool you have to use on it. Material.rock has to be destroyed with a pickaxe and Material.dirt with a shovel.
this.setCreativeTab(CreativeTabs.tabBlock); is the creative tab it will be shown in. This block will be shown in the Blocks tab.This is all you have to do for a working block in your game. When you destroy it, it will drop the block itself once. The texture used right now is the texture from grass in gray. It’s gray, because there are different shades of green for every biome.

In the next couple of tutorials I will teach you how to add a custom item, make this item drop from the block and how to give custom textures to the block and item.

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