Modding 1.4.7: Basic Mob Part 1: EntityRegistry

Adding a mob to Minecraft takes a lot of time and code. In this tutorial I will show you what you need in your mod file for a working mob. This is the file I will start with.


package tutorial;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();
}
}


There are 3 lines of code that you will have to add to your mod file.
This is the first one.


EntityRegistry.registerModEntity(EntityTutorial.class, “Tutorial”, 1, this, 80, 3, true);


EntityRegistry is the file that contains the method registerModEntity.
The first parameter is the Entity class. Make sure you get the .class behind it or it will give you errors.
The second parameter is the name of the entity. You will need that name when you want it to spawn inside of a mob spawner.
The third one is the id of the mob. The id is mod specific so if you have 2 different mod files you can have the same id twice.
The fourth parameter is always this. This refers to the class it is in. The fourth parameter has to be the mod file so this way it gets the right file. Even if you would rename it.
40 is the tracking range of the mob. If it gets further than 40 blocks away it will stop updating. You can make this anything you want, but I suggest keeping it at 40.
The sixth parameter is 1 here. 1 is the update frequency of the mob. If you have it on 1 it will update every tick (20 times every second).
The last parameter can be true or false. When it’s true it will send velocity updates to the server. I suggest keeping this true if you are making a normal mob.

The second line of code you need is this one. You only need this line if you want your mob to spawn naturally if you don’t want that you can skip this.


EntityRegistry.addSpawn(EntityTutorial.class, 10, 2, 4, EnumCreatureType.monster, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.ocean, BiomeGenBase.plains, BiomeGenBase.river, BiomeGenBase.swampland);


The first parameter in this line of code is the entity.
The second parameter is the chance of the mob spawning. 10 is pretty often and 1 really low.
The third and fourth ones are for the size of the groups they naturally spawn in. 2 is the minimum and 4 is the maximum.
The fifth parameter is pretty important. This decides when and where to spawn a mob. If you want a mob to spawn at night you need the monster. If you want it to spawn during the day you can use creature and if you want it to spawn in water you have to use waterCreature.
All the parameters after this are the biomes the mob can spawn in.

The last line of code required is pretty much a bug fix for the server side.


LanguageRegistry.instance().addStringLocalization(“entity.Tutorial_Tutorialmod.Tutorial.name”, “Tutorial”);


This line of code makes sure that the server displays the name of the entity as “Tutorial” and not as what is in the first parameter when the mob kills somebody.
The second parameter is pretty simple. It’s the name of the mob that you want it to be.
The first parameter is a bit harder. It is: entity.modid.mobname.name. Make sure you get it exactly like that. Any mistakes will keep this bug in your mod.

The whole file should now look like this.


package tutorial.common;

import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.BiomeGenBase;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

EntityRegistry.registerModEntity(EntityTutorial.class, “Tutorial”, 1, this, 80, 3, true);
EntityRegistry.addSpawn(EntityTutorial.class, 10, 2, 4, EnumCreatureType.monster, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.ocean, BiomeGenBase.plains, BiomeGenBase.river, BiomeGenBase.swampland);
LanguageRegistry.instance().addStringLocalization(“entity.Tutorial_Tutorialmod.Tutorial.name”, “Tutorial”);
}
}


In the next tutorial I will show you how to set up the Entity class.
The source code will be avaliable at the last part of these tutorials.

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