How can I gain access to a player instance in a Minecraft mod?

Posted by Andrew Graber on Game Development See other posts from Game Development or by Andrew Graber
Published on 2013-06-28T06:11:15Z Indexed on 2013/06/28 10:30 UTC
Read the original article Hit count: 278

Filed under:
|

I'm creating Minecraft mod with a pickaxe that takes away experience when you break a block. The method for taking away experience from a player is addExperience on EntityPlayer, so I need to get an instance of EntityPlayer for the player using my pickaxe when the pickaxe breaks a block, so that I can remove the appropriate amount of experience.

My pickaxe class currently looks like this:

public class ExperiencePickaxe extends ItemPickaxe {

public ExperiencePickaxe(int ItemID, EnumToolMaterial material){
    super(ItemID, material);
}

public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
{
    if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
    {
        EntityPlayer e = new EntityPlayer(); // create an instance
        e.addExperience(-1);
    }

    return true;
}
}

Obviously, I cannot actually create a new EntityPlayer since it is an abstract class. How can I get access to the player using my pickaxe?

© Game Development or respective owner

Related posts about java

Related posts about minecraft