Blogs Tutorial

Minecraft Modding Making - Episode 3 - Basic Block

  • 530 views 0 today
  • 3
  • 1
mysteryman3546
Lvl 75Legendary Creeper Hugger
143

Introduction


In this tutorial I will show you how to add your first basic block to Minecraft. A part of this code is done in the mod file. This is the file you should start with:
THERE IS A WEIRD PROBLEM WITH THE

Starting File
package tutorial;

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 = Tutorial.modid, name = "Mod Name", version = "1.0")


@NetworkMod(clientSideRequired = true, serverSideRequired = false)


public class Tutorial


{


public static final String modid = "YourName_ModName";




@Init


public void load(FMLInitializationEvent event)


{




}


}


Step 1 [Adding the Block]


1) The Next Line has to be placed inside of the class so past the bracket below Your_Name. It also has to be above the @Init
2) This line will add a Block variable called Your_NameBlock to the mod file.

3) Right now Your_NameBlock is set to nothing.
4) You will also have to import net.minecraft.src.Block. Do this by Pressing: "Ctrl, Shift, O" [Windows] or "Command, Shift, O" [Mac] or by hovering your mouse over the error under block and clicking the import net.minecraft.src.Block fix option.

Your_NameBlock Line

public class Your_Name


{


public static final String modid = "YourName_ModName";




public static Block Your_NameBlock;




@Init


public void load(FMLInitializationEvent event)
}


Step 2 [Block Type]


1) The Next Line has to be inside of the load method.


Setting Block Type Line

public class Tutorial


{


public static final String modid = "YourName_ModName";




public static Block tutorialBlock;




@Init


public void load(FMLInitializationEvent event)


{


tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName("tutorialBlock");
}



Step 2a [Explanation for Step 2]



1) What this does is it sets Your_NameBlock to BlockYour_NameBlock which is a new file that we are going to create in the next part of this tutorial. *The number inside the brackets is the id of the block*
2) The second parameter is the Material for the block. You can see other materials by going to the Material File. Materials set some important settings for your block like which tools are required etc.

3) .setUnlocalizedName() sets the name of the block. It is smart to keep the name exactly the same as the block variable name. It will not crash if you don't, but it might give you some strange errors.
4) Right know you will have an error under BlockYour_NameBlock. This is because you are calling a file that isn't there. We will be creating this file in the next part of this tutorial.
*You might be thinking why I didn't just do both of those things on one line. This is because you can have configurable block id's when you write it this way. Configurable block id's will also be in a later tutorial*

Step 3 [Forge Block Recognition]


1) There are 2 more lines that you will have to add. The first is to let Forge know that Your_NameBlock is a Block. To do that you have to add this inside of the load method:

Forge Block Recognition Line

public class Tutorial


{


public static final String modid = "YourName_ModName";




public static Block tutorialBlock;




@Init


public void load(FMLInitializationEvent event)


{


tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName("tutorialBlock");


GameRegistry.registerBlock(tutorialBlock, modid +tutorialBlock.getUnlocalizedName2());
}


Step 3a [Explanation for Step 3]


1) The First Parameter in this method is the Block you are registering.
2) The Second Parameter in here is an Unique String for your Block.
3) The easiest thing to do is use the modid variable in combination with the unlocalized name for the Block. The unlocalizedname is set in the .setBlockName.
4) The reason why you should use getUnlocalizedName2 and not getUnlocalizedName is that getUnlocalizedName adds something to the name that you don't want or need.

Step 4 [Final Line]


1) The Last Line you should add is this:

LanguageRegistry Line

public class Tutorial


{


public static final String modid = "YourName_ModName";




public static Block tutorialBlock;




@Init


public void load(FMLInitializationEvent event)


{


tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName("tutorialBlock");


GameRegistry.registerBlock(tutorialBlock, modid +tutorialBlock.getUnlocalizedName2());




LanguageRegistry.addName(tutorialBlock, "Tutorial Block");


}


More like this

  Have something to say?

Welcome