Interface LivingEntity

All Superinterfaces:
Entity, HoverEventSource<HoverEvent.ShowEntity>, SchedulerSource, Sound.Emitter, Sound.Source.Provider
All Known Subinterfaces:
Damageable, Mob, Player

public interface LivingEntity extends Entity
An entity with health that can be hurt and killed.
Since:
0.1.0
  • Method Details

    • health

      float health()
      Returns:
      the current health in half-hearts, between 0 and maxHealth()
    • setHealth

      void setHealth(float health)
      Parameters:
      health - the health to set, clamped between 0 and maxHealth()
    • maxHealth

      float maxHealth()
      Returns:
      the health ceiling in half-hearts
    • absorptionAmount

      float absorptionAmount()
      Returns:
      the yellow absorption hearts soaking damage before health() does
    • setAbsorptionAmount

      void setAbsorptionAmount(float absorption)
      Parameters:
      absorption - the absorption hearts to set; negative values are treated as 0
    • headYaw

      float headYaw()
      Returns:
      the current head yaw
    • setHeadYaw

      void setHeadYaw(float headYaw)
      Parameters:
      headYaw - the head yaw to set
    • armor

      default double armor()
      Returns:
      the armor points reducing incoming damage, 0 when unarmored
    • armorToughness

      default double armorToughness()
      Returns:
      the armor toughness softening the armor falloff on heavy hits
    • knockbackResistance

      default double knockbackResistance()
      Returns:
      the fraction of knockback ignored, between 0 (none) and 1 (immune)
    • fireTicks

      int fireTicks()
      Returns:
      the remaining ticks this entity keeps burning, 0 when not on fire
    • setFireTicks

      void setFireTicks(int ticks)
      Parameters:
      ticks - the burning ticks to set; 0 extinguishes the entity
    • equipment

      default ItemStack equipment(EquipmentSlot slot)
      Parameters:
      slot - the equipment slot
      Returns:
      the stack worn or held in slot, ItemStack.EMPTY when the slot is empty or the entity has none
    • addEffect

      boolean addEffect(MobEffectInstance effect)
      Applies a status effect. When the entity already has an effect of the same type, the two are merged the vanilla way: a higher amplifier replaces it, and an equal one only refreshes a longer duration. Fires an EntityEffectEvent.
      Parameters:
      effect - the effect to apply
      Returns:
      true if the effects of the entity changed
      Since:
      0.1.0
    • effect

      Returns the running effect of a type, or empty when the entity does not have it.
      Parameters:
      type - the effect, for instance MobEffectKeys.SPEED
      Returns:
      the running effect of a type, or empty when the entity does not have it
      Since:
      0.1.0
    • hasEffect

      boolean hasEffect(TypedKey<MobEffect> type)
      Returns true if the entity has an effect of this type.
      Parameters:
      type - the effect, for instance MobEffectKeys.SPEED
      Returns:
      true if the entity has an effect of this type
      Since:
      0.1.0
    • activeEffects

      Collection<MobEffectInstance> activeEffects()
      Returns a snapshot of the running effects.
      Returns:
      a snapshot of the running effects
      Since:
      0.1.0
    • removeEffect

      boolean removeEffect(TypedKey<MobEffect> type)
      Removes an effect. Fires an EntityEffectEvent.
      Parameters:
      type - the effect to remove
      Returns:
      true if the entity had the effect and it was removed
      Since:
      0.1.0
    • clearEffects

      boolean clearEffects()
      Removes every effect, firing an EntityEffectEvent for each.
      Returns:
      true if at least one effect was removed
      Since:
      0.1.0
    • damage

      default boolean damage(DamageSource source, float amount)
      Hurts this entity, running the full pipeline: invulnerability frames, armor, absorption, events, client packets and death.
      Parameters:
      source - the origin of the hit
      amount - the damage in half-hearts before reduction; <= 0 is ignored
      Returns:
      true if health or absorption was actually removed
      Since:
      0.1.0
    • kill

      default void kill(@Nullable Entity killer)
      Kills this entity outright, bypassing armor and invulnerability.
      Parameters:
      killer - the entity credited with the kill, or null
      Since:
      0.1.0
    • heal

      default void heal(float amount)
      Parameters:
      amount - the health to restore in half-hearts; <= 0 is ignored
      Since:
      0.1.0
    • isDead

      default boolean isDead()
      Returns:
      true when this entity has run out of health
    • isAlive

      default boolean isAlive()
      Returns:
      true when this entity is still in the world and has health left