Java Code Examples for net.minecraft.entity.item.EntityItem#getDistanceToEntity()

The following examples show how to use net.minecraft.entity.item.EntityItem#getDistanceToEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoCEntityBear.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onLivingUpdate()
{
    super.onLivingUpdate();

    if (mouthCounter > 0 && ++mouthCounter > 30)
    {
        mouthCounter = 0;
    }

    if (attackCounter > 0 && ++attackCounter > 100)
    {
        attackCounter = 0;
    }

    if ((MoCreatures.isServer()) && !getIsAdult() && (rand.nextInt(250) == 0))
    {
        setEdad(getEdad() + 1);
        if (getEdad() >= 100)
        {
            setAdult(true);
        }
    }
    /**
     * panda bears and cubs will sit down every now and then
     */
    if ((MoCreatures.isServer()) && (getType() == 3 || (!getIsAdult() && getEdad() < 60)) && (rand.nextInt(300) == 0))
    {
        setBearState(2);
    }

    /**
     * Sitting bears will resume on fours stance every now and then
     */
    if ((MoCreatures.isServer()) && (getBearState() == 2) && (rand.nextInt(800) == 0))
    {
        setBearState(0);
    }

    /**
     * Adult non panda bears will stand on hind legs if close to player
     */

    if ((MoCreatures.isServer()) && standingCounter == 0 && getBearState() != 2 && getIsAdult() && getType() != 3 && (rand.nextInt(500) == 0))
    {
        standingCounter = 1;
        EntityPlayer entityplayer1 = worldObj.getClosestPlayerToEntity(this, 8D);
        if (entityplayer1 != null)
        {
            setBearState(1);
        }
    }

    if ((MoCreatures.isServer()) && standingCounter > 0 && ++standingCounter > 50)
    {
        standingCounter = 0;
        setBearState(0);
    }

    if (MoCreatures.isServer() && getType() == 3 && (deathTime == 0) && getBearState() != 2)
    {
        EntityItem entityitem = getClosestItem(this, 12D, Item.reed.itemID, Item.sugar.itemID);
        if (entityitem != null)
        {

            float f = entityitem.getDistanceToEntity(this);
            if (f > 2.0F)
            {
                getMyOwnPath(entityitem, f);
            }
            if ((f < 2.0F) && (entityitem != null) && (deathTime == 0))
            {
                entityitem.setDead();
                worldObj.playSoundAtEntity(this, "eating", 1.0F, 1.0F + ((rand.nextFloat() - rand.nextFloat()) * 0.2F));
                //setTamed(true);
                health = getMaxHealth();
            }

        }
    }
}