Minecraft Blogs / Article

Lets Make A Mod! Ep.3 Your First Block

  • 210 views, 1 today
  • 2
  • 1
  • 1
lilpsyco99's Avatar lilpsyco99
Level 43 : Master Modder
52
HEY GUYS! TIME TO ACTUALLY MAKE YOU BLOCK!!! O: DO YOU FEEL LIKE A MODDER YET????? O.O

ok now on to all seriousness here we go into the steps!!
Also before we do diamond the post and subscribe it helps!

  • Step Numero Uno! variable for the block

Ok Step one you are going to want to declare the block itself to do this go into your main mod file. then go under the proxy variable declare this under it:


public static Block YourBlockName;

For ex. mine would be

public static Block TutorialBlock;

  • Step 2 declaring our variable

now declare the variable you will want to do this under the @Init method

YourBlockName = (new BlockYourBlockName(538, 0));

For ex. mine would be:

TutorialBlock = (new BlockTutorial(538, 0));

Now the 538 is the block id (the 0 is the sprite index we will make use of this later on in custom textures) this has to be a unused id or the mod will be incompatible with a mod that already has that id you can find a list of unused block ids here: www.minecraftforge.net/forum/index.php/board,57.0.html

  • Step 3 setting names!

now we need to set a code name to do this go between the )) and the ; in the last
code

(YourBlockNameBlock = (new BlockYourBlockName(538, 0));)

and add this:

.setBlockName("codeNameNonHumanReadble")

So it should now look like this:

YourBlockNameBlock =(new BlockYourBlockName(538, 0)).setBlockName("YourBlockNameBlock";

(Yours would be one line i just ran out of room) For ex. mine would look like this:

TutorialBlock =(new BlockTutorial(538, 0)).setBlockName("TutorialBlock";




Now we are going to add a human readable name so to do this under the other codes add this:

LanguageRegistry.addName(YourBlockName, "Your Blocks IGN");

So it should now looks something like this:

myFirstBlock = (new BlockFirst(538, 0)).setBlockName("YourBlockNameBlock");

LanguageRegistry.addName(YourBlockName, "Your Block IGN");

For example mine would look like this:


TutorialBlock = (new BlockTutorial(538, 0)).setBlockName("TutorialBlock");
LanguageRegistry.addName(TutorialBlock, "Tutorial Block");

  • Step 4. Adding the harvest level! and registering the block!

So now we want to be able to harvest this block right? so to do this we wont to add this line of code under the rest:


MinecraftForge.setBlockHarvestLevel(YourBlockName, "pickaxe", 2);

Pickaxe is a variable it can be say axe for wood or so forth 2 stands for the type like 3 would be a diamond pick 2 is iron 1 is stone and 0 is wooden soo this would be able to be broke with a iron pickaxe

now that we have that we need to add the register the most imprtant part!
So under all that put this:
This actually registers the block

GameRegistry.registerBlock(YourBlockName);

So for yours should now look like this


YourBlockName = (new BlockYourBlockName(538, 0)).setBlockName("YourBlockName");
LanguageRegistry.addName(YourBlockName, "Your Blocks IGN");
MinecraftForge.setBlockHarvestLevel(YourBlockName, "pickaxe", 2);
GameRegistry.registerBlock(YourBlockName);


So for ex. mine would look like this:


TutorialBlock = (new BlockTutorial(538, 0)).setBlockName("TutorialBlock");
LanguageRegistry.addName(TutorialBlock, "Tutorial Block");
MinecraftForge.setBlockHarvestLevel(TutorialBlock, "pickaxe", 2);
GameRegistry.registerBlock(TutorialBlock);

  • Step 5. The Block Class


Now we should have an error in the first line at BlockYourBlockName so we need to do CTRL+Shift+O then this should create a new class called BlockYourBlockName but if it doesnt go and hover over the redline and click create class

now that you have a BlockYourBlockName class you need to go to where it says public class and add extends Block to the end. then sort the imports CTRL+SHIFT+O then select net.minecraft.src.Block

now in the brackets add this constructor:

public BlockYourBlockName(int par1, int par2){
super(par1, par2, Material.rock);
}

No need to change par1 thats the blockid nor the par2 thats the texture index as for material go to the material class for possible variables now the block is pretty much done! but we have some more to do now remeber this next part all of it goes in the constructor after super();

Now we want to set the creative tab like so:

this.setCreativeTab(CreativeTabs.tabBlock);

Now the hardness this goes after the creative tab code:

this.setHardness(5.0F);

The 5.0F is a float value which means it varies the one for obsidian is 50.0F as the one for dirt is 0.5F

Now the resistance:

this.setResistance(56.34F);

Now as for this this is the blocks resistance to TNT if you dont want to have resistance dont include this but the one for bedrock for example is: 6000000.0F

Finally for the last code this is step sound this also varies go to the block class for variables this one is stone:

this.setStepSound(this.soundStoneFootstep);

Finally!!! Done! these are your final codes:

TutorialMain.java

package yourusername.yourmodname.common;


import net.minecraft.src.Block;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.Mod.PostInit;

import cpw.mods.fml.common.Mod.PreInit;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.network.NetworkMod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;


@Mod(modid = "modid", name = "yourmodname", version = "your current mod version")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)


public class YourModNameMain {

@Instance("modid")

public static YourModNameMain instance;

@SidedProxy(clientSide="youusername.yourmodname.client.YourModNameClientProxy", serverSide="yourusername.yourmodname.common.YourModNameCommonProxy")

public static YourModNameCommonProxy proxy;

public static Block YourBlockName;

@PreInit

public void preInit(FMLPreInitializationEvent event) {

}


@Init

public void init(FMLInitializationEvent event) {

YourBlockName = (new BlockFirst(538, 0)).setBlockName("YourBlock NON-Human readable name");

LanguageRegistry.addName(myFirstBlock, "Your Blocks HUMAN readable name");

MinecraftForge.setBlockHarvestLevel(YourBlockName, "pickaxe", 3);

GameRegistry.registerBlock(YourBlockName);

}


@PostInit

public static void postInit(FMLPostInitializationEvent event) {

}

}

BlockFirst.java

package yourusername.yourmodname.common;


import net.minecraft.src.Block;

import net.minecraft.src.CreativeTabs;

import net.minecraft.src.Material;


public class BlockYourBlockName extends Block {

public BlockYourBlockName(int par1, int par2){

super(par1, par2, Material.rock);

this.setCreativeTab(CreativeTabs.tabBlock);

this.setHardness(15.3F);

this.setResistance(15.3F);

this.setStepSound(soundMetalFootstep);

}

}

Tags

1 Update Logs

Update #1 : by lilpsyco99 12/04/2012 4:28:22 pmDec 4th, 2012

Made it more clearer

Create an account or sign in to comment.

GigabyteGiant
07/21/2013 7:19 pm
Level 42 : Master Droid
GigabyteGiant's Avatar
First off, great tutorial...

You see I am new to Forge, I only decided to do it because I got bored of Modloader, so I was wondering, could you make an updated series of tutorials just for forge modding? I am trying to do it in 1.6.2 and I am having a hard time with it... Help is appreciated.
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome