Interface LivingEntity

All Superinterfaces:
CommandSender, Damageable, Entity, Metadatable, Permissible, ProjectileSource, ServerOperator
All Known Subinterfaces:
Ageable, Ambient, Animals, ArmorStand, Bat, Blaze, CaveSpider, Chicken, ComplexLivingEntity, Cow, Creature, Creeper, EnderDragon, Enderman, Endermite, Flying, Ghast, Giant, Golem, Guardian, Horse, HumanEntity, IronGolem, MagmaCube, Monster, MushroomCow, NPC, Ocelot, Pig, PigZombie, Player, Rabbit, Sheep, Silverfish, Skeleton, Slime, Snowman, Spider, Squid, Villager, WaterMob, Witch, Wither, Wolf, Zombie

public interface LivingEntity
extends Entity, Damageable, ProjectileSource
Represents a living entity, such as a monster or player
  • Method Details

    • getEyeHeight

      double getEyeHeight()
      Gets the height of the living entity's eyes above its Location.
      Returns:
      height of the living entity's eyes above its location
    • getEyeHeight

      double getEyeHeight​(boolean ignoreSneaking)
      Gets the height of the living entity's eyes above its Location.
      Parameters:
      ignoreSneaking - if set to true, the effects of sneaking will be ignored
      Returns:
      height of the living entity's eyes above its location
    • getEyeLocation

      Location getEyeLocation()
      Get a Location detailing the current eye position of the living entity.
      Returns:
      a location at the eyes of the living entity
    • getLineOfSight

      @Deprecated java.util.List<Block> getLineOfSight​(java.util.HashSet<java.lang.Byte> transparent, int maxDistance)
      Deprecated.
      Magic value
      Gets all blocks along the living entity's line of sight.

      This list contains all blocks from the living entity's eye position to target inclusive.

      Parameters:
      transparent - HashSet containing all transparent block IDs (set to null for only air)
      maxDistance - this is the maximum distance to scan (may be limited by server by at least 100 blocks, no less)
      Returns:
      list containing all blocks along the living entity's line of sight
    • getLineOfSight

      java.util.List<Block> getLineOfSight​(java.util.Set<Material> transparent, int maxDistance)
      Gets all blocks along the living entity's line of sight.

      This list contains all blocks from the living entity's eye position to target inclusive.

      Parameters:
      transparent - HashSet containing all transparent block Materials (set to null for only air)
      maxDistance - this is the maximum distance to scan (may be limited by server by at least 100 blocks, no less)
      Returns:
      list containing all blocks along the living entity's line of sight
    • getTargetBlock

      @Deprecated Block getTargetBlock​(java.util.HashSet<java.lang.Byte> transparent, int maxDistance)
      Deprecated.
      Magic value
      Gets the block that the living entity has targeted.
      Parameters:
      transparent - HashSet containing all transparent block IDs (set to null for only air)
      maxDistance - this is the maximum distance to scan (may be limited by server by at least 100 blocks, no less)
      Returns:
      block that the living entity has targeted
    • getTargetBlock

      Block getTargetBlock​(java.util.Set<Material> transparent, int maxDistance)
      Gets the block that the living entity has targeted.
      Parameters:
      transparent - HashSet containing all transparent block Materials (set to null for only air)
      maxDistance - this is the maximum distance to scan (may be limited by server by at least 100 blocks, no less)
      Returns:
      block that the living entity has targeted
    • getLastTwoTargetBlocks

      @Deprecated java.util.List<Block> getLastTwoTargetBlocks​(java.util.HashSet<java.lang.Byte> transparent, int maxDistance)
      Deprecated.
      Magic value
      Gets the last two blocks along the living entity's line of sight.

      The target block will be the last block in the list.

      Parameters:
      transparent - HashSet containing all transparent block IDs (set to null for only air)
      maxDistance - this is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks
      Returns:
      list containing the last 2 blocks along the living entity's line of sight
    • getLastTwoTargetBlocks

      java.util.List<Block> getLastTwoTargetBlocks​(java.util.Set<Material> transparent, int maxDistance)
      Gets the last two blocks along the living entity's line of sight.

      The target block will be the last block in the list.

      Parameters:
      transparent - HashSet containing all transparent block Materials (set to null for only air)
      maxDistance - this is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks
      Returns:
      list containing the last 2 blocks along the living entity's line of sight
    • throwEgg

      @Deprecated Egg throwEgg()
      Deprecated.
      use launchProjectile(Egg.class) instead
      Throws an egg from the living entity.
      Returns:
      the egg thrown
    • throwSnowball

      @Deprecated Snowball throwSnowball()
      Deprecated.
      use launchProjectile(Snowball.class) instead
      Throws a snowball from the living entity.
      Returns:
      the snowball thrown
    • shootArrow

      @Deprecated Arrow shootArrow()
      Deprecated.
      use launchProjectile(Arrow.class) instead
      Shoots an arrow from the living entity.
      Returns:
      the arrow shot
    • getRemainingAir

      int getRemainingAir()
      Returns the amount of air that the living entity has remaining, in ticks.
      Returns:
      amount of air remaining
    • setRemainingAir

      void setRemainingAir​(int ticks)
      Sets the amount of air that the living entity has remaining, in ticks.
      Parameters:
      ticks - amount of air remaining
    • getMaximumAir

      int getMaximumAir()
      Returns the maximum amount of air the living entity can have, in ticks.
      Returns:
      maximum amount of air
    • setMaximumAir

      void setMaximumAir​(int ticks)
      Sets the maximum amount of air the living entity can have, in ticks.
      Parameters:
      ticks - maximum amount of air
    • getMaximumNoDamageTicks

      int getMaximumNoDamageTicks()
      Returns the living entity's current maximum no damage ticks.

      This is the maximum duration in which the living entity will not take damage.

      Returns:
      maximum no damage ticks
    • setMaximumNoDamageTicks

      void setMaximumNoDamageTicks​(int ticks)
      Sets the living entity's current maximum no damage ticks.
      Parameters:
      ticks - maximum amount of no damage ticks
    • getLastDamage

      double getLastDamage()
      Returns the living entity's last damage taken in the current no damage ticks time.

      Only damage higher than this amount will further damage the living entity.

      Returns:
      damage taken since the last no damage ticks time period
    • _INVALID_getLastDamage

      @Deprecated int _INVALID_getLastDamage()
      Deprecated.
      This method exists for legacy reasons to provide backwards compatibility. It will not exist at runtime and should not be used under any circumstances.
      Returns:
      damage taken since the last no damage ticks time period
    • setLastDamage

      void setLastDamage​(double damage)
      Sets the damage dealt within the current no damage ticks time period.
      Parameters:
      damage - amount of damage
    • _INVALID_setLastDamage

      @Deprecated void _INVALID_setLastDamage​(int damage)
      Deprecated.
      This method exists for legacy reasons to provide backwards compatibility. It will not exist at runtime and should not be used under any circumstances.
      Parameters:
      damage - amount of damage
    • getNoDamageTicks

      int getNoDamageTicks()
      Returns the living entity's current no damage ticks.
      Returns:
      amount of no damage ticks
    • setNoDamageTicks

      void setNoDamageTicks​(int ticks)
      Sets the living entity's current no damage ticks.
      Parameters:
      ticks - amount of no damage ticks
    • getKiller

      Player getKiller()
      Gets the player identified as the killer of the living entity.

      May be null.

      Returns:
      killer player, or null if none found
    • addPotionEffect

      boolean addPotionEffect​(PotionEffect effect)
      Adds the given PotionEffect to the living entity.

      Only one potion effect can be present for a given PotionEffectType.

      Parameters:
      effect - PotionEffect to be added
      Returns:
      whether the effect could be added
    • addPotionEffect

      boolean addPotionEffect​(PotionEffect effect, boolean force)
      Adds the given PotionEffect to the living entity.

      Only one potion effect can be present for a given PotionEffectType.

      Parameters:
      effect - PotionEffect to be added
      force - whether conflicting effects should be removed
      Returns:
      whether the effect could be added
    • addPotionEffects

      boolean addPotionEffects​(java.util.Collection<PotionEffect> effects)
      Attempts to add all of the given PotionEffect to the living entity.
      Parameters:
      effects - the effects to add
      Returns:
      whether all of the effects could be added
    • hasPotionEffect

      boolean hasPotionEffect​(PotionEffectType type)
      Returns whether the living entity already has an existing effect of the given PotionEffectType applied to it.
      Parameters:
      type - the potion type to check
      Returns:
      whether the living entity has this potion effect active on them
    • removePotionEffect

      void removePotionEffect​(PotionEffectType type)
      Removes any effects present of the given PotionEffectType.
      Parameters:
      type - the potion type to remove
    • getActivePotionEffects

      java.util.Collection<PotionEffect> getActivePotionEffects()
      Returns all currently active PotionEffects on the living entity.
      Returns:
      a collection of PotionEffects
    • hasLineOfSight

      boolean hasLineOfSight​(Entity other)
      Checks whether the living entity has block line of sight to another.

      This uses the same algorithm that hostile mobs use to find the closest player.

      Parameters:
      other - the entity to determine line of sight to
      Returns:
      true if there is a line of sight, false if not
    • getRemoveWhenFarAway

      boolean getRemoveWhenFarAway()
      Returns if the living entity despawns when away from players or not.

      By default, animals are not removed while other mobs are.

      Returns:
      true if the living entity is removed when away from players
    • setRemoveWhenFarAway

      void setRemoveWhenFarAway​(boolean remove)
      Sets whether or not the living entity despawns when away from players or not.
      Parameters:
      remove - the removal status
    • getEquipment

      EntityEquipment getEquipment()
      Gets the inventory with the equipment worn by the living entity.
      Returns:
      the living entity's inventory
    • setCanPickupItems

      void setCanPickupItems​(boolean pickup)
      Sets whether or not the living entity can pick up items.
      Parameters:
      pickup - whether or not the living entity can pick up items
    • getCanPickupItems

      boolean getCanPickupItems()
      Gets if the living entity can pick up items.
      Returns:
      whether or not the living entity can pick up items
    • isLeashed

      boolean isLeashed()
      Returns whether the entity is currently leashed.
      Returns:
      whether the entity is leashed
    • getLeashHolder

      Entity getLeashHolder() throws java.lang.IllegalStateException
      Gets the entity that is currently leading this entity.
      Returns:
      the entity holding the leash
      Throws:
      java.lang.IllegalStateException - if not currently leashed
    • setLeashHolder

      boolean setLeashHolder​(Entity holder)
      Sets the leash on this entity to be held by the supplied entity.

      This method has no effect on EnderDragons, Withers, Players, or Bats. Non-living entities excluding leashes will not persist as leash holders.

      Parameters:
      holder - the entity to leash this entity to
      Returns:
      whether the operation was successful