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

The following examples show how to use net.minecraft.entity.EntityLivingBase#getHealth() . 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: ItemTofuForceCore.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);

    if (entityIn instanceof EntityLivingBase) {
        EntityLivingBase entityLivingBase = (EntityLivingBase) entityIn;

        if (entityLivingBase.ticksExisted % 400 == 0 && isUsable(stack)) {
            if (entityLivingBase.getHealth() < entityLivingBase.getMaxHealth()) {
                if (getEnergy(stack) >= 5) {
                    drain(stack, 5, false);

                } else {
                    stack.damageItem(1, (EntityLivingBase) entityIn);
                }
                entityLivingBase.heal(1);
            }
        }
    }
}
 
Example 2
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTick(LivingEvent.LivingUpdateEvent event) {
	EntityLivingBase e = event.getEntityLiving();
	if(e.isPotionActive(ModPotions.TIME_SLOW) && timeScale(e) == 0) {
		boolean shouldFreeze = true;
		if(e.isDead || e.getHealth() <= 0) {
			shouldFreeze = false;
		}
		if(e instanceof EntityDragon && ((EntityDragon) e).getPhaseManager().getCurrentPhase().getType() == PhaseList.DYING) {
			shouldFreeze = false;
		}
		if(shouldFreeze) {
			handleImportantEntityTicks(e);
			event.setCanceled(true);
		}
	}
}
 
Example 3
Source File: EntityMoment.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static EntityMoment fromPreviousMoment(Entity entity, EntityMoment previous) {
	if (previous == null)
		return new EntityMoment(entity);

	Double x, y, z;
	Float yaw, pitch;
	Float health = null;
	Integer food = null;
	Float saturation = null, exhaustion = null;
	x = (previous.x == null || entity.posX != previous.x) ? entity.posX : null;
	y = (previous.y == null || entity.posY != previous.y) ? entity.posY : null;
	z = (previous.z == null || entity.posZ != previous.z) ? entity.posZ : null;
	yaw = (previous.yaw == null || entity.rotationYaw != previous.yaw) ? entity.rotationYaw : null;
	pitch = (previous.pitch == null || entity.rotationPitch != previous.pitch) ? entity.rotationPitch : null;
	if (entity instanceof EntityLivingBase) {
		EntityLivingBase living = (EntityLivingBase) entity;
		health = (previous.health == null || living.getHealth() != previous.health) ? living.getHealth() : null;
		if (entity instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) living;
			food = (previous.food == null || player.getFoodStats().getFoodLevel() != previous.food) ? player.getFoodStats().getFoodLevel() : null;
			saturation = (previous.saturation == null || player.getFoodStats().getSaturationLevel() != previous.saturation) ? player.getFoodStats().getSaturationLevel() : null;
			exhaustion = (previous.exhaustion == null || exhaustionGetter.invoke(player.getFoodStats()) != previous.saturation) ? (Float) exhaustionGetter.invoke(player.getFoodStats()) : null;
		}
	}
	return new EntityMoment(x, y, z, yaw, pitch, health, food, saturation, exhaustion);
}
 
Example 4
Source File: EntityMoment.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean matches(Entity entity) {
	if (x != null && entity.posX != x) return false;
	if (y != null && entity.posY != y) return false;
	if (z != null && entity.posZ != z) return false;
	if (yaw != null && entity.rotationYaw != yaw) return false;
	if (pitch != null && entity.rotationPitch != pitch) return false;
	if (entity instanceof EntityLivingBase) {
		EntityLivingBase living = (EntityLivingBase) entity;
		if (health != null && living.getHealth() != health) return false;
		if (entity instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) living;
			if (food != null && player.getFoodStats().getFoodLevel() != food) return false;
			return saturation == null || !(player.getFoodStats().getSaturationLevel() != saturation);
		}
	}

	return true;
}
 
Example 5
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 6
Source File: ItemDiamondTofuSword.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public boolean hitEntity(ItemStack itemStack, EntityLivingBase targetEntity, EntityLivingBase attacker)
{
    // Drain
    Float healthBeforeAttack = (float) attacker.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
    float damage = healthBeforeAttack - targetEntity.getHealth();
    if (damage > 0.0f)
    {
        int lvl = EnchantmentHelper.getEnchantmentLevel(EnchantmentLoader.Drain, itemStack);
        attacker.heal(damage * (lvl * 0.1f + 0.1f));
    }
    return super.hitEntity(itemStack, targetEntity, attacker);
}
 
Example 7
Source File: KillAuraModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkFilter(Entity entity) {
    boolean ret = false;

    if (this.players.getValue() && entity instanceof EntityPlayer && entity != Minecraft.getMinecraft().player && Seppuku.INSTANCE.getFriendManager().isFriend(entity) == null && !entity.getName().equals(Minecraft.getMinecraft().player.getName())) {
        ret = true;
    }

    if (this.mobs.getValue() && entity instanceof IMob) {
        ret = true;
    }

    if (this.animals.getValue() && entity instanceof IAnimals && !(entity instanceof IMob)) {
        ret = true;
    }

    if (this.vehicles.getValue() && (entity instanceof EntityBoat || entity instanceof EntityMinecart || entity instanceof EntityMinecartContainer)) {
        ret = true;
    }

    if (this.projectiles.getValue() && (entity instanceof EntityShulkerBullet || entity instanceof EntityFireball)) {
        ret = true;
    }

    if (entity instanceof EntityLivingBase) {
        final EntityLivingBase entityLivingBase = (EntityLivingBase) entity;
        if (entityLivingBase.getHealth() <= 0) {
            ret = false;
        }
    }

    return ret;
}
 
Example 8
Source File: ESP.java    From ForgeHax with MIT License 4 votes vote down vote up
@Override
public double draw(
  SurfaceBuilder builder,
  EntityLivingBase living,
  double topX,
  double topY,
  double botX,
  double botY,
  double width,
  double height) {
  float hp =
    MathHelper.clamp(living.getHealth(), 0, living.getMaxHealth()) / living.getMaxHealth();
  double x = topX - (HEALTHBAR_WIDTH / 2);
  double y = topY - HEALTHBAR_HEIGHT - 2;
  int color =
    (living.getHealth() + living.getAbsorptionAmount() > living.getMaxHealth())
      ? Colors.YELLOW.toBuffer()
      : Color.of(
        (int) ((255 - hp) * 255),
        (int) (255 * hp),
        0,
        255).toBuffer(); // if above 20 hp bar is yellow
  
  builder
    .reset() // clean up from previous uses
    .push()
    .task(SurfaceBuilder::enableBlend)
    .task(SurfaceBuilder::disableTexture2D)
    .beginQuads()
    .color(Colors.BLACK.toBuffer())
    .rectangle(x, y, HEALTHBAR_WIDTH, HEALTHBAR_HEIGHT)
    .end()
    .reset()
    .beginQuads()
    .color(color)
    .rectangle(
      x + 1.D, y + 1.D, ((double) HEALTHBAR_WIDTH - 2.D) * hp, HEALTHBAR_HEIGHT - 2.D)
    .end()
    .task(SurfaceBuilder::disableBlend)
    .task(SurfaceBuilder::enableTexture2D)
    .pop();
  
  return HEALTHBAR_HEIGHT + 1.D;
}