Basic Mobs
These guys can be a little tricky at times.
The first thing you want to do is go into your TutorialMain.class and add this to your code under your @init section:
EntityRegistry.registerGlobalEntityID(EntityTutorialMob.class, "TutorialMob", ModLoader.getUniqueEntityId(), 230, 78);
LanguageRegistry.instance().addStringLocalization("entity.TutorialMob.name", "en_US", "Epic Mob");
EntityRegistry.addSpawn(TutorialMob.class, 5, 1, 2, EnumCreatureType.creature, TutorialMain.TutorialBiome); //Go to the biome tutorial here!
EntityRegistry.registerGlobalEntityID(EntityTutorialMob.class is the class file that you will create that defines your mob. "TutorialMob" is the name that minecraft uses to recognize your mob.
ModLoader.getUniqueEntityId() will find a unique number for minecraft to recognize your mob. You can replace this with a number, but then if another mod has the same number with one of it's mobs then they'll conflict.
The numbers after that define the spawn eggs colors. 230, 78 creates a bluish background with black dots. Not really sure what color scale this one uses.
LanguageRegistry.instance().addStringLocalization("entity.TutorialMob.name" is calling the name that you called your mob. en_US sets the language and Epic Mob is the ingame name of your mob.
Now to create the TutorialMob.class. Instead of writing about the code after this section, I'm going to put the comments inside the code.
blfngl.tutorial.entity;
public class EntityTutorialMob extends EntityAnimal
{
public EntityTutorialMob(World par1World)
{
super(par1World);
this.setSize(0.9F, 1.3F);
this.getNavigator().setAvoidsWater(true);
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIPanic(this, 0.38F));
this.tasks.addTask(2, new EntityAIMate(this, 0.2F));
this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.wheat.itemID, false));
this.tasks.addTask(4, new EntityAIFollowParent(this, 0.25F));
this.tasks.addTask(5, new EntityAIWander(this, 0.2F));
this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
this.tasks.addTask(7, new EntityAILookIdle(this));
}
/**
* Returns true if the newer Entity AI code should be run. If false, your mob will be like the old mobs, no pathfinding and whatnot.
*/
public boolean isAIEnabled()
{
return true;
}
//Maximum health
public int getMaxHealth()
{
return 20; //Twenty is the number of half hearts your mob will have
}
/**
* Returns the sound this mob makes while it's alive. I'll be teaching how to add custom sounds a little bit later.
*/
protected String getLivingSound()
{
return "mob.cow.say";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.cow.hurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.cow.hurt";
}
/**
* Plays step sound at it's coordinates
*/
protected void playStepSound(int par1, int par2, int par3, int par4)
{
this.playSound("mob.cow.step", 0.15F, 1.0F);
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume()
{
return 0.4F;
}
/**
* Returns the item ID for the item the mob drops on death. If you want it to drop your item, replace Item.leather.itemID with TutorialMain.TutorialItem.itemID
*/
protected int getDropItemId()
{
return TutorialMain.TutorialIngot.itemID;
}
/**
* Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
* par2 - Level of Looting used to kill this mob.
*/
protected void dropFewItems(boolean par1, int par2)
{
int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
int var4;
for (var4 = 0; var4 < var3; ++var4)
{
this.dropItem(Item.leather.itemID, 1); //One is the quantity of things dropped
}
var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2);
for (var4 = 0; var4 < var3; ++var4)
{
if (this.isBurning())
{
this.dropItem(Item.enderPearl.itemID, 1);
}
else
{
this.dropItem(Item.ingotGold.itemID, 1);
}
}
}
/**
* This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
*/
public EntityBrahmin spawnBabyAnimal(EntityAgeable par1EntityAgeable)
{
return new EntityBrahmin(this.worldObj);
}
public EntityAgeable createChild(EntityAgeable par1EntityAgeable)
{
return this.spawnBabyAnimal(par1EntityAgeable);
}
}
Now on to the mobs rendering. Inside your ClientProxy add this under your registerRenderers method:
RenderingRegistry.instance().registerEntityRenderingHandler(EntityTutorialMob.class, new RenderTutorialMob(new ModelCow(), 0.5F));
If you don't add this your entities model will be steve. In this case, your mob will come out as a cow. Now you should be getting an error telling you that you don't have a RenderTutorialMob.class. Go ahead an create that, and then add this to your code.
package blfngl.tutorial.entity;
@SideOnly(Side.CLIENT)
public class RenderTutorialMob extends RenderLiving
{ private static final ResourceLocation resourceLocation = new ResourceLocation("modid:/mob/texture.png");
public RenderTutorialMob(ModelCow par1ModelBase, float par2)
{
super(par1ModelBase, par2);
}
public void renderTutorialMob(EntityTutorialMob par1EntityTutorialMob, double par2, double par4, double par6, float par8, float par9)
{
super.doRenderLiving(par1EntityTutorialMob, par2, par4, par6, par8, par9);
}
public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
{
this.renderTutorialMob((EntityTutorialMob)par1EntityLiving, par2, par4, par6, par8, par9);
}
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
this.renderTutorialMob((EntityTutorialMob)par1Entity, par2, par4, par6, par8, par9);
}
@Override
protected ResourceLocation func_110775_a(Entity entity)
{
return resourceLocation;
}
}
As of 1.6.2, textures are done via the rendering file. The method ResourceLocation is how that's done. So, since I have the phrase modid:/mob/texture.png, the package you place the texture in would be assets.modid.mob.texture.png
After this, you should be done! Enjoy your mob and lets go to armor.
The first thing you want to do is go into your TutorialMain.class and add this to your code under your @init section:
EntityRegistry.registerGlobalEntityID(EntityTutorialMob.class, "TutorialMob", ModLoader.getUniqueEntityId(), 230, 78);
LanguageRegistry.instance().addStringLocalization("entity.TutorialMob.name", "en_US", "Epic Mob");
EntityRegistry.addSpawn(TutorialMob.class, 5, 1, 2, EnumCreatureType.creature, TutorialMain.TutorialBiome); //Go to the biome tutorial here!
EntityRegistry.registerGlobalEntityID(EntityTutorialMob.class is the class file that you will create that defines your mob. "TutorialMob" is the name that minecraft uses to recognize your mob.
ModLoader.getUniqueEntityId() will find a unique number for minecraft to recognize your mob. You can replace this with a number, but then if another mod has the same number with one of it's mobs then they'll conflict.
The numbers after that define the spawn eggs colors. 230, 78 creates a bluish background with black dots. Not really sure what color scale this one uses.
LanguageRegistry.instance().addStringLocalization("entity.TutorialMob.name" is calling the name that you called your mob. en_US sets the language and Epic Mob is the ingame name of your mob.
Now to create the TutorialMob.class. Instead of writing about the code after this section, I'm going to put the comments inside the code.
blfngl.tutorial.entity;
public class EntityTutorialMob extends EntityAnimal
{
public EntityTutorialMob(World par1World)
{
super(par1World);
this.setSize(0.9F, 1.3F);
this.getNavigator().setAvoidsWater(true);
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIPanic(this, 0.38F));
this.tasks.addTask(2, new EntityAIMate(this, 0.2F));
this.tasks.addTask(3, new EntityAITempt(this, 0.25F, Item.wheat.itemID, false));
this.tasks.addTask(4, new EntityAIFollowParent(this, 0.25F));
this.tasks.addTask(5, new EntityAIWander(this, 0.2F));
this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
this.tasks.addTask(7, new EntityAILookIdle(this));
}
/**
* Returns true if the newer Entity AI code should be run. If false, your mob will be like the old mobs, no pathfinding and whatnot.
*/
public boolean isAIEnabled()
{
return true;
}
//Maximum health
public int getMaxHealth()
{
return 20; //Twenty is the number of half hearts your mob will have
}
/**
* Returns the sound this mob makes while it's alive. I'll be teaching how to add custom sounds a little bit later.
*/
protected String getLivingSound()
{
return "mob.cow.say";
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound()
{
return "mob.cow.hurt";
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound()
{
return "mob.cow.hurt";
}
/**
* Plays step sound at it's coordinates
*/
protected void playStepSound(int par1, int par2, int par3, int par4)
{
this.playSound("mob.cow.step", 0.15F, 1.0F);
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume()
{
return 0.4F;
}
/**
* Returns the item ID for the item the mob drops on death. If you want it to drop your item, replace Item.leather.itemID with TutorialMain.TutorialItem.itemID
*/
protected int getDropItemId()
{
return TutorialMain.TutorialIngot.itemID;
}
/**
* Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
* par2 - Level of Looting used to kill this mob.
*/
protected void dropFewItems(boolean par1, int par2)
{
int var3 = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);
int var4;
for (var4 = 0; var4 < var3; ++var4)
{
this.dropItem(Item.leather.itemID, 1); //One is the quantity of things dropped
}
var3 = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2);
for (var4 = 0; var4 < var3; ++var4)
{
if (this.isBurning())
{
this.dropItem(Item.enderPearl.itemID, 1);
}
else
{
this.dropItem(Item.ingotGold.itemID, 1);
}
}
}
/**
* This function is used when two same-species animals in 'love mode' breed to generate the new baby animal.
*/
public EntityBrahmin spawnBabyAnimal(EntityAgeable par1EntityAgeable)
{
return new EntityBrahmin(this.worldObj);
}
public EntityAgeable createChild(EntityAgeable par1EntityAgeable)
{
return this.spawnBabyAnimal(par1EntityAgeable);
}
}
Now on to the mobs rendering. Inside your ClientProxy add this under your registerRenderers method:
RenderingRegistry.instance().registerEntityRenderingHandler(EntityTutorialMob.class, new RenderTutorialMob(new ModelCow(), 0.5F));
If you don't add this your entities model will be steve. In this case, your mob will come out as a cow. Now you should be getting an error telling you that you don't have a RenderTutorialMob.class. Go ahead an create that, and then add this to your code.
package blfngl.tutorial.entity;
@SideOnly(Side.CLIENT)
public class RenderTutorialMob extends RenderLiving
{ private static final ResourceLocation resourceLocation = new ResourceLocation("modid:/mob/texture.png");
public RenderTutorialMob(ModelCow par1ModelBase, float par2)
{
super(par1ModelBase, par2);
}
public void renderTutorialMob(EntityTutorialMob par1EntityTutorialMob, double par2, double par4, double par6, float par8, float par9)
{
super.doRenderLiving(par1EntityTutorialMob, par2, par4, par6, par8, par9);
}
public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
{
this.renderTutorialMob((EntityTutorialMob)par1EntityLiving, par2, par4, par6, par8, par9);
}
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
{
this.renderTutorialMob((EntityTutorialMob)par1Entity, par2, par4, par6, par8, par9);
}
@Override
protected ResourceLocation func_110775_a(Entity entity)
{
return resourceLocation;
}
}
As of 1.6.2, textures are done via the rendering file. The method ResourceLocation is how that's done. So, since I have the phrase modid:/mob/texture.png, the package you place the texture in would be assets.modid.mob.texture.png
After this, you should be done! Enjoy your mob and lets go to armor.