Modding 1.4.7: Basic Mob Part 2: Entity file basics

In this tutorial I will show you how the Ai for a mob works. This is the mod file I will start with.


package tutorial;

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


Now to start you have to hover your mouse over the EntityTutorial error. Once the little menu shows up you have to select Create Class EntityTutorial and hit finish. This will give you a file like this.


package tutorial;

public class EntityTutorial {

}


The first thing that you have to do is make it extend some kind of other Entity. If you want a hostile mob you extend EntityMob. If you want an peaceful mob you extend EntityAnimal etc. For this tutorial I will extend the EntityMob and make it a hostile monster.
When you extend one of those files you will get an error under that name. Fix it by importing the file. After that you will get an error under the Entity file name. To fix it click the “Add constructor (World)” and it should add a constructor to your file.
Once you have done that you will get another error under the file name. Once again hover you mouse over it and click add unimplemented methods. This will add the getMaxHealth() method. The number you add in here is the maximum health of the mob in half hearts. 20 is the max health with a zombie, becuase it has 10 hearts. The file should now look something like this.


package tutorial;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.world.World;

public class EntityTutorial extends EntityMob
{
public EntityTutorial(World par1World) 
{
super(par1World);
}

public int getMaxHealth() 
{
return 20;
}
}


The next line of code that you will need has to be placed inside of the constructor. The constructor is the method that has the exact same name as the class. This is the line you will need.


this.texture = “/Tutorial/TutorialEntity.png”;


How to make this texture and where to place it will be explained in a later tutorial.

After this you have to set the moving speed of the mob. You can do that with this code.


this.moveSpeed = 0.25F;


0.25F is the speed of a normal mob. If you make it lower the mob will be walking slower and the other way around.

Now you might want to add something extra to the mob type. Use this code for it.


public EnumCreatureAttribute getCreatureAttribute()
    {
        return EnumCreatureAttribute.UNDEAD;
    }


If you have the mob as UNDEAD health potions and regeneration potions will hurt the mob. Poison and harm will heal them.
If you have the mob as ANTHROPOD the bane of anthropods enchantment will do more damage.
If you want the mob to have neither of those 2 things you don’t need this method. If you don’t have this method the mob will be UNDIFINED and it will skip those 2 effect changes.

There is one last important method that you will have to add.


public int getAttackStrength(Entity par1Entity)
    {
    return 4;
    }


The value that is returned in here is the amount of half hearts of damage the mob will do.

When you have added all of this code your file should look something like this.


package tutorial;

import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.world.World;


public class EntityTutorial extends EntityMob
{
public EntityTutorial(World par1World) 
{
super(par1World);
this.texture = “/Tutorial/TutorialEntity.png”;
this.moveSpeed = 0.25F;
}


public int getAttackStrength(Entity par1Entity)
    {
    return 4;
    }
public int getMaxHealth() 
{
return 20;
}

public EnumCreatureAttribute getCreatureAttribute()
    {
        return EnumCreatureAttribute.UNDEAD;
    }
}


 

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