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.modid, name = "Mod Name", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired
= false)
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");
}
}
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.
{
super(id, par2Material);
}
You need to make sure that the method is public FileName and that it contains 1 integer and 1 Material inside of the brackets. You can change the names of those 2 variables 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 of the block is. It also tells Block which kind of material it is made out of. In this case the material is rock. 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 the Material file.
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, Material
par2Material)
{
super(id,
par2Material);
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.
When you are done you should go back to the tutorials list here.
Geen opmerkingen:
Een reactie posten