Java Code Examples for net.minecraft.entity.EntityLivingBase.getEntityBoundingBox()

The following are Jave code examples for showing how to use getEntityBoundingBox() of the net.minecraft.entity.EntityLivingBase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: NemesisSystem   File: NemesisActions.java   Source Code and License Vote up 6 votes
public static void throwPearl(EntityLiving entity, EntityLivingBase target) {
	World world = entity.getEntityWorld();
	EntityEnderPearl pearl = new EntityEnderPearl(world, entity);

	double dX = target.posX - entity.posX;
	double dY = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - pearl.posY;
	double dZ = target.posZ - entity.posZ;

	double distanceSq = dX * dX + dY * dY + dZ * dZ;

	if (distanceSq < 20) {
		return;
	}

	double levelDistance = MathHelper.sqrt(dX * dX + dZ * dZ);

	pearl.setThrowableHeading(dX, dY + levelDistance * 0.20000000298023224D, dZ, 1.6F,
			(float) (14 - world.getDifficulty().getDifficultyId() * 4));

	entity.playSound(SoundEvents.ENTITY_ENDERPEARL_THROW, 1.0F, 1.0F / (world.rand.nextFloat() * 0.4F + 0.8F));

	world.spawnEntity(pearl);
}
 
Example 2
Project: Halloween   File: EntityUtils.java   Source Code and License Vote up 6 votes
/**
 * Checks to make sure the light is not too bright where the mob is spawning
 * Adapted from net.minecraft.entity.monster.EntityMob#isValidLightLevel
 *
 */
private static boolean EntityMob_isValidLightLevel(EntityLivingBase entity)
{
	BlockPos pos = new BlockPos(entity.posX, entity.getEntityBoundingBox().minY, entity.posZ);
	if (entity.world.getLightFor(EnumSkyBlock.SKY, pos) > entity.world.rand.nextInt(32))
	{
		return false;
	}
	else
	{
		int i = entity.world.getLightFromNeighbors(pos);
		if (entity.world.isThundering())
		{
			int j = entity.world.getSkylightSubtracted();
			entity.world.setSkylightSubtracted(10);
			i = entity.world.getLightFromNeighbors(pos);
			entity.world.setSkylightSubtracted(j);
		}
		return i <= entity.world.rand.nextInt(8);
	}
}
 
Example 3
Project: Backmemed   File: EntityGhast.java   Source Code and License Vote up 5 votes
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    double d0 = 64.0D;

    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.world;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            double d1 = 4.0D;
            Vec3d vec3d = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.xCoord * 4.0D);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.zCoord * 4.0D);
            world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3d.xCoord * 4.0D;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3d.zCoord * 4.0D;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 4
Project: CustomWorldGen   File: EntityGhast.java   Source Code and License Vote up 5 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    double d0 = 64.0D;

    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.worldObj;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            double d1 = 4.0D;
            Vec3d vec3d = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.xCoord * 4.0D);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.zCoord * 4.0D);
            world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3d.xCoord * 4.0D;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3d.zCoord * 4.0D;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 5
Project: DecompiledMinecraft   File: EntityArrow.java   Source Code and License Vote up 5 votes
public EntityArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
{
    super(worldIn);
    this.renderDistanceWeight = 10.0D;
    this.shootingEntity = shooter;

    if (shooter instanceof EntityPlayer)
    {
        this.canBePickedUp = 1;
    }

    this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
    double d0 = p_i1755_3_.posX - shooter.posX;
    double d1 = p_i1755_3_.getEntityBoundingBox().minY + (double)(p_i1755_3_.height / 3.0F) - this.posY;
    double d2 = p_i1755_3_.posZ - shooter.posZ;
    double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D)
    {
        float f = (float)(MathHelper.func_181159_b(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f1 = (float)(-(MathHelper.func_181159_b(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
        float f2 = (float)(d3 * 0.20000000298023224D);
        this.setThrowableHeading(d0, d1 + (double)f2, d2, p_i1755_4_, p_i1755_5_);
    }
}
 
Example 6
Project: DecompiledMinecraft   File: EntityArrow.java   Source Code and License Vote up 5 votes
public EntityArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
{
    super(worldIn);
    this.renderDistanceWeight = 10.0D;
    this.shootingEntity = shooter;

    if (shooter instanceof EntityPlayer)
    {
        this.canBePickedUp = 1;
    }

    this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
    double d0 = p_i1755_3_.posX - shooter.posX;
    double d1 = p_i1755_3_.getEntityBoundingBox().minY + (double)(p_i1755_3_.height / 3.0F) - this.posY;
    double d2 = p_i1755_3_.posZ - shooter.posZ;
    double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D)
    {
        float f = (float)(MathHelper.func_181159_b(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f1 = (float)(-(MathHelper.func_181159_b(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
        float f2 = (float)(d3 * 0.20000000298023224D);
        this.setThrowableHeading(d0, d1 + (double)f2, d2, p_i1755_4_, p_i1755_5_);
    }
}
 
Example 7
Project: Backmemed   File: AbstractSkeleton.java   Source Code and License Vote up 5 votes
/**
 * Attack the specified entity using a ranged attack.
 *  
 * @param distanceFactor How far the target is, normalized and clamped between 0.1 and 1.0
 */
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
{
    EntityArrow entityarrow = this.func_190726_a(distanceFactor);
    double d0 = target.posX - this.posX;
    double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - entityarrow.posY;
    double d2 = target.posZ - this.posZ;
    double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
    entityarrow.setThrowableHeading(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float)(14 - this.world.getDifficulty().getDifficultyId() * 4));
    this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.world.spawnEntityInWorld(entityarrow);
}
 
Example 8
Project: BaseClient   File: EntityArrow.java   Source Code and License Vote up 5 votes
public EntityArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_)
{
    super(worldIn);
    this.renderDistanceWeight = 10.0D;
    this.shootingEntity = shooter;

    if (shooter instanceof EntityPlayer)
    {
        this.canBePickedUp = 1;
    }

    this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
    double d0 = p_i1755_3_.posX - shooter.posX;
    double d1 = p_i1755_3_.getEntityBoundingBox().minY + (double)(p_i1755_3_.height / 3.0F) - this.posY;
    double d2 = p_i1755_3_.posZ - shooter.posZ;
    double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);

    if (d3 >= 1.0E-7D)
    {
        float f = (float)(MathHelper.func_181159_b(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f1 = (float)(-(MathHelper.func_181159_b(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
        float f2 = (float)(d3 * 0.20000000298023224D);
        this.setThrowableHeading(d0, d1 + (double)f2, d2, p_i1755_4_, p_i1755_5_);
    }
}
 
Example 9
Project: BaseClient   File: EntityGhast.java   Source Code and License Vote up 5 votes
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    double d0 = 64.0D;

    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < d0 * d0 && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.worldObj;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playAuxSFXAtEntity((EntityPlayer)null, 1007, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            double d1 = 4.0D;
            Vec3 vec3 = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3.xCoord * d1);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3.zCoord * d1);
            world.playAuxSFXAtEntity((EntityPlayer)null, 1008, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3.xCoord * d1;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3.zCoord * d1;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 10
Project: BaseClient   File: EntityGhast.java   Source Code and License Vote up 5 votes
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    double d0 = 64.0D;

    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < d0 * d0 && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.worldObj;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playAuxSFXAtEntity((EntityPlayer)null, 1007, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            double d1 = 4.0D;
            Vec3 vec3 = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3.xCoord * d1);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3.zCoord * d1);
            world.playAuxSFXAtEntity((EntityPlayer)null, 1008, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3.xCoord * d1;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3.zCoord * d1;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 11
Project: Backmemed   File: EntityAIAttackMelee.java   Source Code and License Vote up 5 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.attacker.getAttackTarget();
    this.attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
    double d0 = this.attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
    --this.delayCounter;

    if ((this.longMemory || this.attacker.getEntitySenses().canSee(entitylivingbase)) && this.delayCounter <= 0 && (this.targetX == 0.0D && this.targetY == 0.0D && this.targetZ == 0.0D || entitylivingbase.getDistanceSq(this.targetX, this.targetY, this.targetZ) >= 1.0D || this.attacker.getRNG().nextFloat() < 0.05F))
    {
        this.targetX = entitylivingbase.posX;
        this.targetY = entitylivingbase.getEntityBoundingBox().minY;
        this.targetZ = entitylivingbase.posZ;
        this.delayCounter = 4 + this.attacker.getRNG().nextInt(7);

        if (d0 > 1024.0D)
        {
            this.delayCounter += 10;
        }
        else if (d0 > 256.0D)
        {
            this.delayCounter += 5;
        }

        if (!this.attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.speedTowardsTarget))
        {
            this.delayCounter += 15;
        }
    }

    this.attackTick = Math.max(this.attackTick - 1, 0);
    this.checkAndPerformAttack(entitylivingbase, d0);
}
 
Example 12
Project: DecompiledMinecraft   File: EntityBlaze.java   Source Code and License Vote up 4 votes
public void updateTask()
{
    --this.field_179468_c;
    EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
    double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);

    if (d0 < 4.0D)
    {
        if (this.field_179468_c <= 0)
        {
            this.field_179468_c = 20;
            this.blaze.attackEntityAsMob(entitylivingbase);
        }

        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }
    else if (d0 < 256.0D)
    {
        double d1 = entitylivingbase.posX - this.blaze.posX;
        double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
        double d3 = entitylivingbase.posZ - this.blaze.posZ;

        if (this.field_179468_c <= 0)
        {
            ++this.field_179467_b;

            if (this.field_179467_b == 1)
            {
                this.field_179468_c = 60;
                this.blaze.setOnFire(true);
            }
            else if (this.field_179467_b <= 4)
            {
                this.field_179468_c = 6;
            }
            else
            {
                this.field_179468_c = 100;
                this.field_179467_b = 0;
                this.blaze.setOnFire(false);
            }

            if (this.field_179467_b > 1)
            {
                float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
                this.blaze.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);

                for (int i = 0; i < 1; ++i)
                {
                    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.worldObj, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
                    entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
                    this.blaze.worldObj.spawnEntityInWorld(entitysmallfireball);
                }
            }
        }

        this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
    }
    else
    {
        this.blaze.getNavigator().clearPathEntity();
        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }

    super.updateTask();
}
 
Example 13
Project: CustomWorldGen   File: EntityAIAttackMelee.java   Source Code and License Vote up 4 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.attacker.getAttackTarget();
    this.attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
    double d0 = this.attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
    --this.delayCounter;

    if ((this.longMemory || this.attacker.getEntitySenses().canSee(entitylivingbase)) && this.delayCounter <= 0 && (this.targetX == 0.0D && this.targetY == 0.0D && this.targetZ == 0.0D || entitylivingbase.getDistanceSq(this.targetX, this.targetY, this.targetZ) >= 1.0D || this.attacker.getRNG().nextFloat() < 0.05F))
    {
        this.targetX = entitylivingbase.posX;
        this.targetY = entitylivingbase.getEntityBoundingBox().minY;
        this.targetZ = entitylivingbase.posZ;
        this.delayCounter = 4 + this.attacker.getRNG().nextInt(7);

        if (this.canPenalize)
        {
            this.delayCounter += failedPathFindingPenalty;
            if (this.attacker.getNavigator().getPath() != null)
            {
                net.minecraft.pathfinding.PathPoint finalPathPoint = this.attacker.getNavigator().getPath().getFinalPathPoint();
                if (finalPathPoint != null && entitylivingbase.getDistanceSq(finalPathPoint.xCoord, finalPathPoint.yCoord, finalPathPoint.zCoord) < 1)
                    failedPathFindingPenalty = 0;
                else
                    failedPathFindingPenalty += 10;
            }
            else
            {
                failedPathFindingPenalty += 10;
            }
        }

        if (d0 > 1024.0D)
        {
            this.delayCounter += 10;
        }
        else if (d0 > 256.0D)
        {
            this.delayCounter += 5;
        }

        if (!this.attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.speedTowardsTarget))
        {
            this.delayCounter += 15;
        }
    }

    this.attackTick = Math.max(this.attackTick - 1, 0);
    this.checkAndPerformAttack(entitylivingbase, d0);
}
 
Example 14
Project: DecompiledMinecraft   File: EntityAIAttackOnCollide.java   Source Code and License Vote up 4 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.attacker.getAttackTarget();
    this.attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
    double d0 = this.attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
    double d1 = this.func_179512_a(entitylivingbase);
    --this.delayCounter;

    if ((this.longMemory || this.attacker.getEntitySenses().canSee(entitylivingbase)) && this.delayCounter <= 0 && (this.targetX == 0.0D && this.targetY == 0.0D && this.targetZ == 0.0D || entitylivingbase.getDistanceSq(this.targetX, this.targetY, this.targetZ) >= 1.0D || this.attacker.getRNG().nextFloat() < 0.05F))
    {
        this.targetX = entitylivingbase.posX;
        this.targetY = entitylivingbase.getEntityBoundingBox().minY;
        this.targetZ = entitylivingbase.posZ;
        this.delayCounter = 4 + this.attacker.getRNG().nextInt(7);

        if (d0 > 1024.0D)
        {
            this.delayCounter += 10;
        }
        else if (d0 > 256.0D)
        {
            this.delayCounter += 5;
        }

        if (!this.attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.speedTowardsTarget))
        {
            this.delayCounter += 15;
        }
    }

    this.attackTick = Math.max(this.attackTick - 1, 0);

    if (d0 <= d1 && this.attackTick <= 0)
    {
        this.attackTick = 20;

        if (this.attacker.getHeldItem() != null)
        {
            this.attacker.swingItem();
        }

        this.attacker.attackEntityAsMob(entitylivingbase);
    }
}
 
Example 15
Project: Backmemed   File: EntityBlaze.java   Source Code and License Vote up 4 votes
public void updateTask()
{
    --this.attackTime;
    EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
    double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);

    if (d0 < 4.0D)
    {
        if (this.attackTime <= 0)
        {
            this.attackTime = 20;
            this.blaze.attackEntityAsMob(entitylivingbase);
        }

        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }
    else if (d0 < this.func_191523_f() * this.func_191523_f())
    {
        double d1 = entitylivingbase.posX - this.blaze.posX;
        double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
        double d3 = entitylivingbase.posZ - this.blaze.posZ;

        if (this.attackTime <= 0)
        {
            ++this.attackStep;

            if (this.attackStep == 1)
            {
                this.attackTime = 60;
                this.blaze.setOnFire(true);
            }
            else if (this.attackStep <= 4)
            {
                this.attackTime = 6;
            }
            else
            {
                this.attackTime = 100;
                this.attackStep = 0;
                this.blaze.setOnFire(false);
            }

            if (this.attackStep > 1)
            {
                float f = MathHelper.sqrt(MathHelper.sqrt(d0)) * 0.5F;
                this.blaze.world.playEvent((EntityPlayer)null, 1018, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);

                for (int i = 0; i < 1; ++i)
                {
                    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.world, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
                    entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
                    this.blaze.world.spawnEntityInWorld(entitysmallfireball);
                }
            }
        }

        this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
    }
    else
    {
        this.blaze.getNavigator().clearPathEntity();
        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }

    super.updateTask();
}
 
Example 16
Project: CustomWorldGen   File: EntitySkeleton.java   Source Code and License Vote up 4 votes
/**
 * Attack the specified entity using a ranged attack.
 *  
 * @param distanceFactor How far the target is, normalized and clamped between 0.1 and 1.0
 */
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor)
{
    EntityTippedArrow entitytippedarrow = new EntityTippedArrow(this.worldObj, this);
    double d0 = target.posX - this.posX;
    double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - entitytippedarrow.posY;
    double d2 = target.posZ - this.posZ;
    double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
    entitytippedarrow.setThrowableHeading(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float)(14 - this.worldObj.getDifficulty().getDifficultyId() * 4));
    int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
    int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
    DifficultyInstance difficultyinstance = this.worldObj.getDifficultyForLocation(new BlockPos(this));
    entitytippedarrow.setDamage((double)(distanceFactor * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.getDifficulty().getDifficultyId() * 0.11F));

    if (i > 0)
    {
        entitytippedarrow.setDamage(entitytippedarrow.getDamage() + (double)i * 0.5D + 0.5D);
    }

    if (j > 0)
    {
        entitytippedarrow.setKnockbackStrength(j);
    }

    boolean flag = this.isBurning() && difficultyinstance.isHard() && this.rand.nextBoolean() || this.getSkeletonType() == SkeletonType.WITHER;
    flag = flag || EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, this) > 0;

    if (flag)
    {
        entitytippedarrow.setFire(100);
    }

    ItemStack itemstack = this.getHeldItem(EnumHand.OFF_HAND);

    if (itemstack != null && itemstack.getItem() == Items.TIPPED_ARROW)
    {
        entitytippedarrow.setPotionEffect(itemstack);
    }
    else if (this.getSkeletonType() == SkeletonType.STRAY)
    {
        entitytippedarrow.addEffect(new PotionEffect(MobEffects.SLOWNESS, 600));
    }

    this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entitytippedarrow);
}
 
Example 17
Project: BaseClient   File: EntityBlaze.java   Source Code and License Vote up 4 votes
public void updateTask()
{
    --this.field_179468_c;
    EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
    double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);

    if (d0 < 4.0D)
    {
        if (this.field_179468_c <= 0)
        {
            this.field_179468_c = 20;
            this.blaze.attackEntityAsMob(entitylivingbase);
        }

        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }
    else if (d0 < 256.0D)
    {
        double d1 = entitylivingbase.posX - this.blaze.posX;
        double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
        double d3 = entitylivingbase.posZ - this.blaze.posZ;

        if (this.field_179468_c <= 0)
        {
            ++this.field_179467_b;

            if (this.field_179467_b == 1)
            {
                this.field_179468_c = 60;
                this.blaze.setOnFire(true);
            }
            else if (this.field_179467_b <= 4)
            {
                this.field_179468_c = 6;
            }
            else
            {
                this.field_179468_c = 100;
                this.field_179467_b = 0;
                this.blaze.setOnFire(false);
            }

            if (this.field_179467_b > 1)
            {
                float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
                this.blaze.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);

                for (int i = 0; i < 1; ++i)
                {
                    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.worldObj, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
                    entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
                    this.blaze.worldObj.spawnEntityInWorld(entitysmallfireball);
                }
            }
        }

        this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
    }
    else
    {
        this.blaze.getNavigator().clearPathEntity();
        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }

    super.updateTask();
}
 
Example 18
Project: BaseClient   File: EntityAIAttackOnCollide.java   Source Code and License Vote up 4 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.attacker.getAttackTarget();
    this.attacker.getLookHelper().setLookPositionWithEntity(entitylivingbase, 30.0F, 30.0F);
    double d0 = this.attacker.getDistanceSq(entitylivingbase.posX, entitylivingbase.getEntityBoundingBox().minY, entitylivingbase.posZ);
    double d1 = this.func_179512_a(entitylivingbase);
    --this.delayCounter;

    if ((this.longMemory || this.attacker.getEntitySenses().canSee(entitylivingbase)) && this.delayCounter <= 0 && (this.targetX == 0.0D && this.targetY == 0.0D && this.targetZ == 0.0D || entitylivingbase.getDistanceSq(this.targetX, this.targetY, this.targetZ) >= 1.0D || this.attacker.getRNG().nextFloat() < 0.05F))
    {
        this.targetX = entitylivingbase.posX;
        this.targetY = entitylivingbase.getEntityBoundingBox().minY;
        this.targetZ = entitylivingbase.posZ;
        this.delayCounter = 4 + this.attacker.getRNG().nextInt(7);

        if (d0 > 1024.0D)
        {
            this.delayCounter += 10;
        }
        else if (d0 > 256.0D)
        {
            this.delayCounter += 5;
        }

        if (!this.attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.speedTowardsTarget))
        {
            this.delayCounter += 15;
        }
    }

    this.attackTick = Math.max(this.attackTick - 1, 0);

    if (d0 <= d1 && this.attackTick <= 0)
    {
        this.attackTick = 20;

        if (this.attacker.getHeldItem() != null)
        {
            this.attacker.swingItem();
        }

        this.attacker.attackEntityAsMob(entitylivingbase);
    }
}
 
Example 19
Project: BaseClient   File: EntityBlaze.java   Source Code and License Vote up 4 votes
public void updateTask()
{
    --this.field_179468_c;
    EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
    double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);

    if (d0 < 4.0D)
    {
        if (this.field_179468_c <= 0)
        {
            this.field_179468_c = 20;
            this.blaze.attackEntityAsMob(entitylivingbase);
        }

        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }
    else if (d0 < 256.0D)
    {
        double d1 = entitylivingbase.posX - this.blaze.posX;
        double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
        double d3 = entitylivingbase.posZ - this.blaze.posZ;

        if (this.field_179468_c <= 0)
        {
            ++this.field_179467_b;

            if (this.field_179467_b == 1)
            {
                this.field_179468_c = 60;
                this.blaze.setOnFire(true);
            }
            else if (this.field_179467_b <= 4)
            {
                this.field_179468_c = 6;
            }
            else
            {
                this.field_179468_c = 100;
                this.field_179467_b = 0;
                this.blaze.setOnFire(false);
            }

            if (this.field_179467_b > 1)
            {
                float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
                this.blaze.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);

                for (int i = 0; i < 1; ++i)
                {
                    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.worldObj, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
                    entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
                    this.blaze.worldObj.spawnEntityInWorld(entitysmallfireball);
                }
            }
        }

        this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
    }
    else
    {
        this.blaze.getNavigator().clearPathEntity();
        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }

    super.updateTask();
}
 
Example 20
Project: CustomWorldGen   File: EntityBlaze.java   Source Code and License Vote up 4 votes
/**
 * Updates the task
 */
public void updateTask()
{
    --this.attackTime;
    EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
    double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);

    if (d0 < 4.0D)
    {
        if (this.attackTime <= 0)
        {
            this.attackTime = 20;
            this.blaze.attackEntityAsMob(entitylivingbase);
        }

        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }
    else if (d0 < 256.0D)
    {
        double d1 = entitylivingbase.posX - this.blaze.posX;
        double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
        double d3 = entitylivingbase.posZ - this.blaze.posZ;

        if (this.attackTime <= 0)
        {
            ++this.attackStep;

            if (this.attackStep == 1)
            {
                this.attackTime = 60;
                this.blaze.setOnFire(true);
            }
            else if (this.attackStep <= 4)
            {
                this.attackTime = 6;
            }
            else
            {
                this.attackTime = 100;
                this.attackStep = 0;
                this.blaze.setOnFire(false);
            }

            if (this.attackStep > 1)
            {
                float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
                this.blaze.worldObj.playEvent((EntityPlayer)null, 1018, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);

                for (int i = 0; i < 1; ++i)
                {
                    EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.worldObj, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
                    entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
                    this.blaze.worldObj.spawnEntityInWorld(entitysmallfireball);
                }
            }
        }

        this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
    }
    else
    {
        this.blaze.getNavigator().clearPathEntity();
        this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
    }

    super.updateTask();
}