Modding 1.4.7: Basic Mob Part 5: Drops

Yet again there is more code that you will have to add to your Entity file before it is done. This is the 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.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);
    }
}


To add a mob drop to your mob you will need this method.


protected int getDropItemId()
    {
        return Item.ingotGold.itemID;
    }


The thing it returns is the item or block it will drop when the mob dies.

You can also add a rare drop to your mob.


protected void dropRareDrop(int par1)
    {
        switch (this.rand.nextInt(2))
        {
            case 0:
                this.dropItem(Item.ingotIron.itemID, 1);
                break;
            case 1:
                this.dropItem(Item.helmetSteel.itemID, 1);
                break;
        }
    }


The items or blocks you add in here will not drop every time.
The 2 inside of the line that starts with switch is the number of different items your mob can drop when it will drop a rare drop. In this case there is the ingotIron and the helmetSteel so there are 2 things it could drop.
Inside of the brackets there is case 0:. This checks if the random number inside of the switch is 0. If it is it will do the code below. So it will drop the iron ingot. The same for the iron helmet.
The number after the item or block is the amount it will drop. Of course you can use a this.rand.nextInt() in there as well to drop a random amount of items as well.

There is one more way of dropping something when it dies that you can add to your mob.


protected void dropFewItems(boolean par1, int par2)
    {
    if(this.rand.nextInt(3) == 0)
    {
    this.dropItem(Item.appleRed.itemID, 1);
    }
    }


You can use this method instead of the dropRareDrop and getDropItemId, but you can also add a combination of the three.
This method is used to only drop something a random amount of times. In this case it drops about once every three mobs. It will drop 1 apple.

The whole file should now look something like this.


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.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);
    }
    
    protected int getDropItemId()
    {
        return Item.ingotGold.itemID;
    }
    
    protected void dropRareDrop(int par1)
    {
        switch (this.rand.nextInt(2))
        {
            case 0:
                this.dropItem(Item.ingotIron.itemID, 1);
                break;
            case 1:
                this.dropItem(Item.helmetSteel.itemID, 1);
                break;
        }
    }
    
    protected void dropFewItems(boolean par1, int par2)
    {
    if(this.rand.nextInt(3) == 0)
    {
    this.dropItem(Item.appleRed.itemID, 1);
    }
    }
}


This is all of the code that you need in a basic mob Entity file. In the next tutorial I will show you how to add a mob egg for your mob. After that there will be a tutorial on a Model and Render files.

The source code will be available at the end of the last basic Mob 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="">