Modding 1.4.7: Basic Mob Part 4: Sound, Texture, Armor and Updating

The Entity file still isn’t done. You will need quite a bit more code to finish it. This is the Entity file from the last tutorial.


package tutorial;

import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBreakDoor;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
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;
this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIBreakDoor(this));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, this.moveSpeed, false));
        this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(4, new EntityAIWander(this, this.moveSpeed));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, true));
}

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

protected boolean isAIEnabled()
    {
        return true;
    }

public int getMaxHealth() 
{
return 20;
}

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


The first method for this tutorial has to do with how the mob will look.


public String getTexture()
    {
return “/Tutorial/Tutorialmob.png”;
    }


This method will place the texture on the mob. The way it’s set up right now you will have a Tutorialmob.png inside of the Tutorial folder. This Tutorial folder will be inside of the minecraft.jar or your mod.zip.

If you want to give your mob a certain amount of armor you will need this method.


public int getTotalArmorValue()
    {
        return 2;
    }


This is in half armors so 20 is a full bar.

Another pretty important method inside of an Entity file is the onLivingUpdate. In here you will have code that will make something burn in the sun or drop an egg.


public void onLivingUpdate()
    {
        if (this.worldObj.isDaytime() && !this.worldObj.isRemote)
        {
            float var1 = this.getBrightness(1.0F);

            if (var1 > 0.5F && this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)) && this.rand.nextFloat() * 30.0F < (var1 – 0.4F) * 2.0F)
            {
                this.setFire(8);
            }
        }

        super.onLivingUpdate();
    }


The way the method is set up right now will make it check if it is daytime. Then it will make sure that the mob isn’t under a block. If it isn’t it will set it on fire.

Another thing that you probalby want your mob to have is sounds. These are the methods used for that.


protected String getLivingSound()
    {
        return “mob.zombie.say”;
    }

    protected String getHurtSound()
    {
        return “mob.zombie.hurt”;
    }
    
    protected String getDeathSound()
    {
        return “mob.zombie.death”;
    }
    
    protected void playStepSound(int par1, int par2, int par3, int par4)
    {
        this.worldObj.playSoundAtEntity(this, “mob.zombie.step”, 0.15F, 1.0F);
    }


All of the method names should be pretty obvious. The first one is the sound that it will make when it lives, the second when it get’s hurt, the third when it dies and the fourth when it walks. You can add custom sounds to Minecraft, but that will be for a later tutorial. If you don’t want the mob to make any sound you can just return null in the first 3 methods. You can just leave out the third method to also get that away.

The whole file should now look something like this.


package tutorial.common;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBreakDoor;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
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;
this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIBreakDoor(this));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, this.moveSpeed, false));
        this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
        this.tasks.addTask(4, new EntityAIWander(this, this.moveSpeed));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, true));
}

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

protected boolean isAIEnabled()
    {
        return true;
    }

public int getMaxHealth() 
{
return 20;
}

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

public String getTexture()
    {
return “/Tutorial/Tutorialmob.png”;
    }

public int getTotalArmorValue()
    {
        return 2;
    }

public void onLivingUpdate()
    {
        if (this.worldObj.isDaytime() && !this.worldObj.isRemote)
        {
            float var1 = this.getBrightness(1.0F);

            if (var1 > 0.5F && this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)) && this.rand.nextFloat() * 30.0F < (var1 – 0.4F) * 2.0F)
            {
                this.setFire(8);
            }
        }

        super.onLivingUpdate();
    }

protected String getLivingSound()
    {
        return “mob.zombie.say”;
    }

    protected String getHurtSound()
    {
        return “mob.zombie.hurt”;
    }
    
    protected String getDeathSound()
    {
        return “mob.zombie.death”;
    }
    
    protected void playStepSound(int par1, int par2, int par3, int par4)
    {
        this.worldObj.playSoundAtEntity(this, “mob.zombie.step”, 0.15F, 1.0F);
    }
}


In the next tutorail will be even more on the Entity.
The source code will be avaliable at the end of the last Entity tutorial.

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