Java Code Examples for net.minecraft.entity.EntityLivingBase#getEyeHeight()

The following examples show how to use net.minecraft.entity.EntityLivingBase#getEyeHeight() . 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: EntityMage.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
protected void attackWithPotion(EntityLivingBase target) {
	double targetY = target.posY + (double) target.getEyeHeight() - 1.100000023841858D;
	double targetX = target.posX + target.motionX - this.posX;
	double d2 = targetY - this.posY;
	double targetZ = target.posZ + target.motionZ - this.posZ;

	float f = MathHelper.sqrt(targetX * targetX + targetZ * targetZ);
	PotionType potiontype = PotionTypes.HARMING;

	if (f >= 8.0F && !target.isPotionActive(MobEffects.SLOWNESS)) {
		potiontype = PotionTypes.SLOWNESS;
	} else if (target.getHealth() >= 8.0F && !target.isPotionActive(MobEffects.POISON)) {
		potiontype = PotionTypes.POISON;
	} else if (f <= 3.0F && !target.isPotionActive(MobEffects.WEAKNESS) && this.rand.nextFloat() < 0.25F) {
		potiontype = PotionTypes.WEAKNESS;
	}

	EntityPotion entitypotion = new EntityPotion(this.world, this,
			PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potiontype));
	entitypotion.rotationPitch -= -20.0F;
	entitypotion.shoot(targetX, d2 + (double) (f * 0.2F), targetZ, 0.75F, 8.0F);

	this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0F,
			0.8F + this.rand.nextFloat() * 0.4F);
	this.world.spawnEntity(entitypotion);
}
 
Example 2
Source File: SwitchHeldItemAndRotationPacket.java    From Cyberware with MIT License 6 votes vote down vote up
public static void faceEntity(Entity player, Entity entityIn)
{
	double d0 = entityIn.posX - player.posX;
	double d2 = entityIn.posZ - player.posZ;
	double d1;

	if (entityIn instanceof EntityLivingBase)
	{
		EntityLivingBase entitylivingbase = (EntityLivingBase)entityIn;
		d1 = entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() - (player.posY + (double)player.getEyeHeight());
	}
	else
	{
		d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (player.posY + (double)player.getEyeHeight());
	}

	double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
	float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
	float f1 = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
	player.rotationPitch = f1;
	player.rotationYaw = f;
}
 
Example 3
Source File: EntityLaser.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
public EntityLaser(World par1World, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase, float par4, float par5) {
    super(par1World);
    this.renderDistanceWeight = 10.0D;
    this.shootingEntity = par2EntityLivingBase;

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

    if (d3 >= 1.0E-7D) {
        float f2 = (float) (Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f3 = (float) (-(Math.atan2(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(par2EntityLivingBase.posX + d4, this.posY, par2EntityLivingBase.posZ + d5, f2, f3);
        this.yOffset = 0.0F;
        float f4 = (float) d3 * 0.2F;
        this.setThrowableHeading(d0, d1 + (double) f4, d2, par4, par5);
    }
}
 
Example 4
Source File: EntityLaser.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
public EntityLaser(World par1World, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase, float par4, float par5) {
	super(par1World);
	this.renderDistanceWeight = 10.0D;
	this.shootingEntity = par2EntityLivingBase;

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

	if (d3 >= 1.0E-7D) {
		float f2 = (float) (Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
		float f3 = (float) (-(Math.atan2(d1, d3) * 180.0D / Math.PI));
		double d4 = d0 / d3;
		double d5 = d2 / d3;
		this.setLocationAndAngles(par2EntityLivingBase.posX + d4, this.posY, par2EntityLivingBase.posZ + d5, f2, f3);
		this.yOffset = 0.0F;
		float f4 = (float) d3 * 0.2F;
		this.setThrowableHeading(d0, d1 + (double) f4, d2, par4, par5);
	}
}
 
Example 5
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
public void attackEntityWithRangedAttack(EntityLivingBase entity, float rangeRatio) {   
  //the EntityPotion class validates if this potion is throwable, and if not it logs error "ThrownPotion entity {} has no item?!
  if(attackTimer <= 0 && getHeldItem(EnumHand.MAIN_HAND).getItem() == Items.SPLASH_POTION && !isHealing) {

    attackedWithPotion = entity;

    double x = entity.posX + entity.motionX - posX;
    double y = entity.posY + entity.getEyeHeight() - 1.100000023841858D - posY;
    double z = entity.posZ + entity.motionZ - posZ;
    float groundDistance = MathHelper.sqrt(x * x + z * z);

    ItemStack potion = getHeldItem(EnumHand.MAIN_HAND);
    attackTimer = getHeldItem(EnumHand.MAIN_HAND).getMaxItemUseDuration();

    EntityPotion entitypotion = new EntityPotion(world, this, potion);
    entitypotion.rotationPitch -= -20.0F;
    entitypotion.setThrowableHeading(x, y + groundDistance * 0.2F, z, 0.75F, 8.0F);
    world.spawnEntity(entitypotion);

    setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
  }
}
 
Example 6
Source File: BlockHelper.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
public static EnumFacing getVerticalFacingFromEntity(BlockPos pos, EntityLivingBase living)
{
    double d = living.posY + living.getEyeHeight();

    if (d - pos.getY() > 2.0D)
        return EnumFacing.UP;
    else
        return EnumFacing.DOWN;
}
 
Example 7
Source File: PLUtil.java    From Production-Line with MIT License 5 votes vote down vote up
public static EnumFacing getFacingFromEntity(BlockPos pos, EntityLivingBase entity) {
    if (MathHelper.abs((float)entity.posX - (float)pos.getX()) < 2.0F && MathHelper.abs((float)entity.posZ - (float)pos.getZ()) < 2.0F) {
        double d0 = entity.posY + (double)entity.getEyeHeight();

        if (d0 - (double)pos.getY() > 2.0D) {
            return EnumFacing.UP;
        }

        if ((double)pos.getY() - d0 > 0.0D) {
            return EnumFacing.DOWN;
        }
    }

    return entity.getHorizontalFacing().getOpposite();
}
 
Example 8
Source File: EntityEnderArrow.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public EntityEnderArrow(World worldIn, EntityLivingBase shooter, EntityLivingBase par3EntityLivingBase, float par4, float par5)
{
    super(worldIn);
    this.shootingEntity = shooter;
    this.shooterUUID = shooter.getUniqueID();

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

        if (((EntityPlayer)shooter).capabilities.isCreativeMode)
        {
            this.canBePickedUp = 2;
        }
    }

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

    if (d3 >= 1.0E-7D)
    {
        float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
        float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
        double d4 = d0 / d3;
        double d5 = d2 / d3;
        this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f2, f3);
        float f4 = (float)d3 * 0.2F;
        this.shoot(d0, d1 + (double)f4, d2, par4, par5);
    }
}
 
Example 9
Source File: BlockUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static EnumFacing get3dOrientation(EntityLivingBase entity, BlockPos pos) {
	if (MathHelper.abs((float)entity.posX - pos.getX()) < 2.0F && MathHelper.abs((float)entity.posZ - pos.getZ()) < 2.0F) {
		final double entityEyes = entity.posY + entity.getEyeHeight();
		if (entityEyes - pos.getY() > 2.0D) return EnumFacing.DOWN;
		if (pos.getY() - entityEyes > 0.0D) return EnumFacing.UP;
	}

	return entity.getHorizontalFacing();
}
 
Example 10
Source File: EntityFukumame.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public EntityFukumame(World par1World, EntityLivingBase par2EntityLiving) {
    this(par1World, par2EntityLiving.posX, par2EntityLiving.posY + (double) par2EntityLiving.getEyeHeight() - 0.1D, par2EntityLiving.posZ);
    this.isCrit = this.chkdate();
    this.thrower = par2EntityLiving;
    this.ignoreEntity = par2EntityLiving;
}