Interface LivingEntity

All Superinterfaces:
Attributable, Audience, CommandSender, Damageable, DataComponentView, Entity, Frictional, HoverEventSource<HoverEvent.ShowEntity>, Metadatable, Nameable, Permissible, PersistentDataHolder, PersistentDataViewHolder, Pointered, ProjectileSource, ServerOperator, Sound.Emitter
All Known Subinterfaces:
AbstractCow, AbstractHorse, AbstractNautilus, AbstractSkeleton, AbstractVillager, Ageable, Allay, Ambient, Animals, Armadillo, ArmorStand, Axolotl, Bat, Bee, Blaze, Bogged, Breedable, Breeze, Camel, CamelHusk, Cat, CaveSpider, ChestedHorse, Chicken, Cod, CollarColorable, ComplexLivingEntity, CopperGolem, Cow, Creaking, Creature, Creeper, Dolphin, Donkey, Drowned, ElderGuardian, EnderDragon, Enderman, Endermite, Enemy, Evoker, Fish, Flying, Fox, Frog, Ghast, Giant, GlowSquid, Goat, Golem, Guardian, HappyGhast, Hoglin, Horse, HumanEntity, Husk, Illager, Illusioner, IronGolem, Llama, MagmaCube, Mannequin, Mob, Monster, Mule, MushroomCow, Nautilus, NPC, Ocelot, Panda, Parched, Parrot, Phantom, Pig, Piglin, PiglinAbstract, PiglinBrute, PigZombie, Pillager, Player, PolarBear, PufferFish, Rabbit, Raider, RangedEntity, Ravager, Salmon, SchoolableFish, Sheep, Shulker, Silverfish, Skeleton, SkeletonHorse, Slime, Sniffer, Snowman, Spellcaster, Spider, Squid, Steerable, Stray, Strider, Tadpole, Tameable, TraderLlama, TropicalFish, Turtle, Vex, Villager, Vindicator, WanderingTrader, Warden, WaterMob, Witch, Wither, WitherSkeleton, Wolf, Zoglin, Zombie, ZombieHorse, ZombieNautilus, ZombieVillager

public interface LivingEntity extends Attributable, Damageable, ProjectileSource, Frictional
Represents a living entity, such as a monster or player
Since:
1.0.0
  • 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
      Since:
      1.0.0
    • getEyeHeight

      double getEyeHeight(boolean ignorePose)
      Gets the height of the living entity's eyes above its Location.
      Parameters:
      ignorePose - if set to true, the effects of pose changes, eg sneaking and gliding will be ignored
      Returns:
      height of the living entity's eyes above its location
      Since:
      1.0.0
    • getEyeLocation

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

      @NotNull @NotNull List<Block> getLineOfSight(@Nullable @Nullable 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. This method considers all blocks as 1x1x1 in size.

      Parameters:
      transparent - Set 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
      Since:
      1.8
    • getTargetBlock

      @NotNull @NotNull Block getTargetBlock(@Nullable @Nullable Set<Material> transparent, int maxDistance)
      Gets the block that the living entity has targeted.

      This method considers all blocks as 1x1x1 in size. To take exact block collision shapes into account, see getTargetBlockExact(int, FluidCollisionMode).

      Parameters:
      transparent - Set 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
      Since:
      1.8
    • getTargetBlock

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable default @Nullable Block getTargetBlock(int maxDistance)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the block that the living entity has targeted, ignoring fluids
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      block that the living entity has targeted, or null if no block is within maxDistance
    • getTargetBlock

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable @Nullable Block getTargetBlock(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the block that the living entity has targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      fluidMode - whether to check fluids or not
      Returns:
      block that the living entity has targeted, or null if no block is within maxDistance
    • getTargetBlockFace

      @Nullable default BlockFace getTargetBlockFace(int maxDistance)
      Gets the blockface of that block that the living entity has targeted, ignoring fluids
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      blockface of the block that the living entity has targeted, or null if no block is targeted
      Since:
      1.13.1
    • getTargetBlockFace

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the blockface of that block that the living entity has targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      fluidMode - whether to check fluids or not
      Returns:
      blockface of the block that the living entity has targeted, or null if no block is targeted
    • getTargetBlockFace

      @Nullable BlockFace getTargetBlockFace(int maxDistance, @NotNull @NotNull FluidCollisionMode fluidMode)
      Gets the blockface of that block that the living entity has targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      fluidMode - whether to check fluids or not
      Returns:
      blockface of the block that the living entity has targeted, or null if no block is targeted
      Since:
      1.19.3
    • getTargetBlockInfo

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable default TargetBlockInfo getTargetBlockInfo(int maxDistance)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets information about the block the living entity has targeted, ignoring fluids
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      TargetBlockInfo about the block the living entity has targeted, or null if no block is targeted
    • getTargetBlockInfo

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull TargetBlockInfo.FluidMode fluidMode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets information about the block the living entity has targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      fluidMode - whether to check fluids or not
      Returns:
      TargetBlockInfo about the block the living entity has targeted, or null if no block is targeted
    • getTargetEntity

      @Nullable default @Nullable Entity getTargetEntity(int maxDistance)
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      entity being targeted, or null if no entity is targeted
      Since:
      1.13.1
    • getTargetEntity

      @Nullable @Nullable Entity getTargetEntity(int maxDistance, boolean ignoreBlocks)
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      ignoreBlocks - true to scan through blocks
      Returns:
      entity being targeted, or null if no entity is targeted
      Since:
      1.13.1
    • getTargetEntityInfo

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable default TargetEntityInfo getTargetEntityInfo(int maxDistance)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      TargetEntityInfo about the entity being targeted, or null if no entity is targeted
    • rayTraceEntities

      @Nullable default @Nullable RayTraceResult rayTraceEntities(int maxDistance)
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      Returns:
      RayTraceResult about the entity being targeted, or null if no entity is targeted
      Since:
      1.19.3
    • getTargetEntityInfo

      @Deprecated(forRemoval=true, since="1.19.3") @Nullable TargetEntityInfo getTargetEntityInfo(int maxDistance, boolean ignoreBlocks)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      ignoreBlocks - true to scan through blocks
      Returns:
      TargetEntityInfo about the entity being targeted, or null if no entity is targeted
    • rayTraceEntities

      @Nullable @Nullable RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks)
      Gets information about the entity being targeted
      Parameters:
      maxDistance - this is the maximum distance to scan
      ignoreBlocks - true to scan through blocks
      Returns:
      RayTraceResult about the entity being targeted, or null if no entity is targeted
      Since:
      1.19.3
    • getLastTwoTargetBlocks

      @NotNull @NotNull List<Block> getLastTwoTargetBlocks(@Nullable @Nullable 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. This method considers all blocks as 1x1x1 in size.

      Parameters:
      transparent - Set 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
      Since:
      1.8
    • getTargetBlockExact

      @Nullable default @Nullable Block getTargetBlockExact(int maxDistance)
      Gets the block that the living entity has targeted.

      This takes the blocks' precise collision shapes into account. Fluids are ignored.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      Parameters:
      maxDistance - the maximum distance to scan
      Returns:
      block that the living entity has targeted
      Since:
      1.13.2
      See Also:
    • getTargetBlockExact

      @Nullable @Nullable Block getTargetBlockExact(int maxDistance, @NotNull @NotNull FluidCollisionMode fluidCollisionMode)
      Gets the block that the living entity has targeted.

      This takes the blocks' precise collision shapes into account.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      Parameters:
      maxDistance - the maximum distance to scan
      fluidCollisionMode - the fluid collision mode
      Returns:
      block that the living entity has targeted
      Since:
      1.13.2
      See Also:
    • rayTraceBlocks

      @Nullable default @Nullable RayTraceResult rayTraceBlocks(double maxDistance)
      Performs a ray trace that provides information on the targeted block.

      This takes the blocks' precise collision shapes into account. Fluids are ignored.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      Parameters:
      maxDistance - the maximum distance to scan
      Returns:
      information on the targeted block, or null if there is no targeted block in range
      Since:
      1.13.2
      See Also:
    • rayTraceBlocks

      @Nullable @Nullable RayTraceResult rayTraceBlocks(double maxDistance, @NotNull @NotNull FluidCollisionMode fluidCollisionMode)
      Performs a ray trace that provides information on the targeted block.

      This takes the blocks' precise collision shapes into account.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      Parameters:
      maxDistance - the maximum distance to scan
      fluidCollisionMode - the fluid collision mode
      Returns:
      information on the targeted block, or null if there is no targeted block in range
      Since:
      1.13.2
      See Also:
    • getRemainingAir

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

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

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

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

      @Nullable @Deprecated(forRemoval=true, since="1.20.4") @Nullable ItemStack getItemInUse()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the item that the player is using (eating food, drawing back a bow, blocking, etc.)
      Returns:
      the item being used by the player, or null if they are not using an item
    • getItemInUseTicks

      @Deprecated(forRemoval=true, since="1.20.4") int getItemInUseTicks()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Gets the number of ticks remaining for the current item's usage.
      Returns:
      The number of ticks remaining
    • setItemInUseTicks

      @Deprecated(forRemoval=true, since="1.20.4") void setItemInUseTicks(int ticks)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the number of ticks that remain for the current item's usage. Applies to items that take time to use, like eating food, drawing a bow, or throwing a trident.
      Parameters:
      ticks - The number of ticks remaining
    • getArrowCooldown

      @NonNegative int getArrowCooldown()
      Gets the time in ticks until the next arrow leaves the entity's body.
      Returns:
      ticks until arrow leaves
      Since:
      1.16.2
    • setArrowCooldown

      void setArrowCooldown(@NonNegative int ticks)
      Sets the time in ticks until the next arrow leaves the entity's body.

      A value of 0 will cause the server to re-calculate the time on the next tick.

      Parameters:
      ticks - time until arrow leaves
      Since:
      1.16.2
    • getArrowsInBody

      @NonNegative int getArrowsInBody()
      Gets the amount of arrows in an entity's body.
      Returns:
      amount of arrows in body
      Since:
      1.16.2
    • setArrowsInBody

      default void setArrowsInBody(@NonNegative int count)
      Set the amount of arrows in the entity's body.

      Does not fire the ArrowBodyCountChangeEvent.

      Parameters:
      count - amount of arrows in entity's body
      Since:
      1.16.2
    • setArrowsInBody

      void setArrowsInBody(@NonNegative int count, boolean fireEvent)
      Set the amount of arrows in the entity's body.
      Parameters:
      count - amount of arrows in entity's body
      fireEvent - whether to fire the ArrowBodyCountChangeEvent event
      Since:
      1.19.3
    • setNextArrowRemoval

      @Deprecated(since="1.21.10") default void setNextArrowRemoval(@NonNegative int ticks)
      Deprecated.
      Sets the amount of ticks before the next arrow gets removed from the entities body.

      A value of 0 will cause the server to re-calculate the amount of ticks on the next tick.

      Parameters:
      ticks - Amount of ticks
      Since:
      1.20.4
    • getNextArrowRemoval

      @Deprecated(since="1.21.10") default @NonNegative int getNextArrowRemoval()
      Deprecated.
      Gets the amount of ticks before the next arrow gets removed from the entities body.
      Returns:
      ticks Amount of ticks
      Since:
      1.20.4
    • getBeeStingerCooldown

      @NonNegative int getBeeStingerCooldown()
      Gets the time in ticks until the next bee stinger leaves the entity's body.
      Returns:
      ticks until bee stinger leaves
      Since:
      1.17.1
    • setBeeStingerCooldown

      void setBeeStingerCooldown(@NonNegative int ticks)
      Sets the time in ticks until the next stinger leaves the entity's body.

      A value of 0 will cause the server to re-calculate the time on the next tick.

      Parameters:
      ticks - time until bee stinger leaves
      Since:
      1.17.1
    • getBeeStingersInBody

      @NonNegative int getBeeStingersInBody()
      Gets the amount of bee stingers in an entity's body.
      Returns:
      amount of bee stingers in body
      Since:
      1.17.1
    • setBeeStingersInBody

      void setBeeStingersInBody(@NonNegative int count)
      Set the amount of bee stingers in the entity's body.
      Parameters:
      count - amount of bee stingers in entity's body
      Since:
      1.17.1
    • setNextBeeStingerRemoval

      @Deprecated(since="1.21.10") default void setNextBeeStingerRemoval(@NonNegative int ticks)
      Sets the amount of ticks before the next bee stinger gets removed from the entities body.

      A value of 0 will cause the server to re-calculate the amount of ticks on the next tick.

      Parameters:
      ticks - Amount of ticks
      Since:
      1.20.4
    • getNextBeeStingerRemoval

      @Deprecated(since="1.21.10") default @NonNegative int getNextBeeStingerRemoval()
      Deprecated.
      Gets the amount of ticks before the next bee stinger gets removed from the entities body.
      Returns:
      ticks Amount of ticks
      Since:
      1.20.4
    • 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
      Since:
      1.0.0
    • setMaximumNoDamageTicks

      void setMaximumNoDamageTicks(int ticks)
      Sets the living entity's current maximum no damage ticks.
      Parameters:
      ticks - maximum amount of no damage ticks
      Since:
      1.0.0
    • 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
      Since:
      1.0.0
    • setLastDamage

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

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

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

      int getNoActionTicks()
      Get the ticks that this entity has performed no action.

      The details of what "no action ticks" entails varies from entity to entity and cannot be specifically defined. Some examples include squid using this value to determine when to swim, raiders for when they are to be expelled from raids, or creatures (such as withers) as a requirement to be despawned.

      Returns:
      amount of no action ticks
      Since:
      1.20.1
    • setNoActionTicks

      void setNoActionTicks(int ticks)
      Set the ticks that this entity has performed no action.

      The details of what "no action ticks" entails varies from entity to entity and cannot be specifically defined. Some examples include squid using this value to determine when to swim, raiders for when they are to be expelled from raids, or creatures (such as withers) as a requirement to be despawned.

      Parameters:
      ticks - amount of no action ticks
      Since:
      1.20.1
    • getKiller

      Gets the player identified as the killer of the living entity.

      May be null.

      Returns:
      killer player, or null if none found
      Since:
      1.1.0
    • setKiller

      void setKiller(@Nullable @Nullable Player killer)
      Sets the player identified as the killer of the living entity.
      Parameters:
      killer - player
      Since:
      1.12.1
    • addPotionEffect

      default boolean addPotionEffect(@NotNull @NotNull PotionEffect effect)
      Adds the given PotionEffect to the living entity.

      Note: PotionEffect.getHiddenPotionEffect() is ignored when adding the effect to the entity.

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

      @Deprecated(since="1.15.2") boolean addPotionEffect(@NotNull @NotNull PotionEffect effect, boolean force)
      Deprecated.
      no need to force since multiple effects of the same type are now supported.
      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
      Since:
      1.1.0
    • addPotionEffects

      boolean addPotionEffects(@NotNull @NotNull Collection<PotionEffect> effects)
      Attempts to add all of the given PotionEffect to the living entity.

      Note: PotionEffect.getHiddenPotionEffect() is ignored when adding the effect to the entity.

      Parameters:
      effects - the effects to add
      Returns:
      whether all of the effects could be added
      Since:
      1.1.0
    • hasPotionEffect

      boolean hasPotionEffect(@NotNull @NotNull 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
      Since:
      1.1.0
    • getPotionEffect

      Returns the active PotionEffect of the specified type.

      If the effect is not present on the entity then null will be returned.

      Parameters:
      type - the potion type to check
      Returns:
      the effect active on this entity, or null if not active.
      Since:
      1.10.2
    • removePotionEffect

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

      @NotNull @NotNull Collection<PotionEffect> getActivePotionEffects()
      Returns all currently active PotionEffects on the living entity.
      Returns:
      a collection of PotionEffects
      Since:
      1.1.0
    • clearActivePotionEffects

      boolean clearActivePotionEffects()
      Removes all active potion effects for this entity.
      Returns:
      true if any were removed
      Since:
      1.20.1
    • hasLineOfSight

      boolean hasLineOfSight(@NotNull @NotNull 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
      Since:
      1.3.1
    • hasLineOfSight

      boolean hasLineOfSight(@NotNull @NotNull Location location)
      Checks whether the living entity has block line of sight to the given block.

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

      Parameters:
      location - the location to determine line of sight to
      Returns:
      true if there is a line of sight, false if not
      Since:
      1.16.5
    • 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
      Since:
      1.4.5
    • setRemoveWhenFarAway

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

      Gets the inventory with the equipment worn by the living entity.
      Returns:
      the living entity's inventory
      Since:
      1.4.5
    • 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
      Since:
      1.4.5
    • getCanPickupItems

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

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

      Gets the entity that is currently leading this entity.
      Returns:
      the entity holding the leash
      Throws:
      IllegalStateException - if not currently leashed
      Since:
      1.6.2
    • setLeashHolder

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

      This method has no effect on players. Non-living entities excluding leashes will not persist as leash holders.

      Parameters:
      holder - the entity to leash this entity to, or null to unleash
      Returns:
      whether the operation was successful
      Since:
      1.6.2
    • isGliding

      boolean isGliding()
      Checks to see if an entity is gliding, such as using an Elytra.
      Returns:
      True if this entity is gliding.
      Since:
      1.9.4
    • setGliding

      void setGliding(boolean gliding)
      Makes entity start or stop gliding. This will work even if an Elytra is not equipped, but will be reverted by the server immediately after unless an event-cancelling mechanism is put in place.
      Parameters:
      gliding - True if the entity is gliding.
      Since:
      1.9.4
    • isSwimming

      boolean isSwimming()
      Checks to see if an entity is swimming.
      Returns:
      True if this entity is swimming.
      Since:
      1.13
    • setSwimming

      @Deprecated void setSwimming(boolean swimming)
      Deprecated.
      This does nothing and is immediately reverted by the server, in the next tick
      Makes entity start or stop swimming. This may have unexpected results if the entity is not in water.
      Parameters:
      swimming - True if the entity is swimming.
      Since:
      1.13
    • isRiptiding

      boolean isRiptiding()
      Checks to see if an entity is currently riptiding.
      Returns:
      True if this entity is currently riptiding.
      Since:
      1.13
    • setRiptiding

      void setRiptiding(boolean riptiding)
      Makes entity start or stop riptiding.

      Note: This does not damage attackable entities.

      Parameters:
      riptiding - whether the entity should start riptiding.
      Since:
      1.21.1
      See Also:
    • isSleeping

      boolean isSleeping()
      Returns whether this entity is slumbering.
      Returns:
      slumber state
      Since:
      1.14
    • isClimbing

      boolean isClimbing()
      Gets if the entity is climbing.
      Returns:
      if the entity is climbing
      Since:
      1.17
    • setAI

      void setAI(boolean ai)
      Sets whether an entity will have AI. The entity will be completely unable to move if it has no AI.
      Parameters:
      ai - whether the mob will have AI or not.
      Since:
      1.9.4
    • hasAI

      boolean hasAI()
      Checks whether an entity has AI. The entity will be completely unable to move if it has no AI.
      Returns:
      true if the entity has AI, otherwise false.
      Since:
      1.9.4
    • attack

      void attack(@NotNull @NotNull Entity target)
      Makes this entity attack the given entity with a melee attack. Attack damage is calculated by the server from the attributes and equipment of this mob, and knockback is applied to target as appropriate.
      Parameters:
      target - entity to attack.
      Since:
      1.15.2
    • swingMainHand

      void swingMainHand()
      Makes this entity swing their main hand. This method does nothing if this entity does not have an animation for swinging their main hand.
      Since:
      1.15.2
    • swingOffHand

      void swingOffHand()
      Makes this entity swing their off hand. This method does nothing if this entity does not have an animation for swinging their off hand.
      Since:
      1.15.2
    • playHurtAnimation

      void playHurtAnimation(float yaw)
      Makes this entity flash red as if they were damaged.
      Parameters:
      yaw - The direction the damage is coming from in relation to the entity, where 0 is in front of the player, 90 is to the right, 180 is behind, and 270 is to the left
      Since:
      1.20.1
    • setCollidable

      void setCollidable(boolean collidable)
      Set if this entity will be subject to collisions with other entities.

      Exemptions to this rule can be managed with getCollidableExemptions()

      Note that the client may predict the collision between itself and another entity, resulting in this flag not working for player collisions. This method should therefore only be used to set the collision status of non-player entities.

      To control player collisions, use Team.Option.COLLISION_RULE in combination with a Scoreboard and a Team.

      Parameters:
      collidable - collision status
      Since:
      1.9.4
    • isCollidable

      boolean isCollidable()
      Gets if this entity is subject to collisions with other entities.

      Some entities might be exempted from the collidable rule of this entity. Use getCollidableExemptions() to get these.

      Please note that this method returns only the custom collidable state, not whether the entity is non-collidable for other reasons such as being dead.

      Note that the client may predict the collision between itself and another entity, resulting in this flag not being accurate for player collisions. This method should therefore only be used to check the collision status of non-player entities.

      To check the collision behavior for a player, use Team.Option.COLLISION_RULE in combination with a Scoreboard and a Team.

      Returns:
      collision status
      Since:
      1.9.4
    • getCollidableExemptions

      @NotNull @NotNull Set<UUID> getCollidableExemptions()
      Gets a mutable set of UUIDs of the entities which are exempt from the entity's collidable rule and which's collision with this entity will behave the opposite of it.

      This set can be modified to add or remove exemptions.

      For example if collidable is true and an entity is in the exemptions set then it will not collide with it. Similarly if collidable is false and an entity is in this set then it will still collide with it.

      Note these exemptions are not (currently) persistent.

      Note that the client may predict the collision between itself and another entity, resulting in those exemptions not being accurate for player collisions. This method should therefore only be used to exempt non-player entities.

      To exempt collisions for a player, use Team.Option.COLLISION_RULE in combination with a Scoreboard and a Team.

      Returns:
      the collidable exemption set
      Since:
      1.16.1
    • getMemory

      @Nullable <T> T getMemory(@NotNull @NotNull MemoryKey<T> memoryKey)
      Returns the value of the memory specified.

      Note that the value is null when the specific entity does not have that value by default.

      Type Parameters:
      T - the type of the return value
      Parameters:
      memoryKey - memory to access
      Returns:
      an instance of the memory section value or null if not present
      Since:
      1.14.1
    • setMemory

      <T> void setMemory(@NotNull @NotNull MemoryKey<T> memoryKey, @Nullable T memoryValue)
      Sets the value of the memory specified.

      Note that the value will not be persisted when the specific entity does not have that value by default.

      Type Parameters:
      T - the type of the passed value
      Parameters:
      memoryKey - the memory to access
      memoryValue - a typed memory value
      Since:
      1.14.1
    • getHurtSound

      @Nullable @Nullable Sound getHurtSound()
      Get the Sound this entity will make when damaged.
      Returns:
      the hurt sound, or null if the entity does not make any sound
      Since:
      1.19.2
    • getDeathSound

      @Nullable @Nullable Sound getDeathSound()
      Get the Sound this entity will make on death.
      Returns:
      the death sound, or null if the entity does not make any sound
      Since:
      1.19.2
    • getFallDamageSound

      @NotNull @NotNull Sound getFallDamageSound(int fallHeight)
      Get the Sound this entity will make when falling from the given height (in blocks). The sound will often differ between either a small or a big fall damage sound if the height exceeds 4 blocks.
      Parameters:
      fallHeight - the fall height in blocks
      Returns:
      the fall damage sound
      Since:
      1.19.2
      See Also:
    • getFallDamageSoundSmall

      @NotNull @NotNull Sound getFallDamageSoundSmall()
      Get the Sound this entity will make when falling from a small height.
      Returns:
      the fall damage sound
      Since:
      1.19.2
    • getFallDamageSoundBig

      @NotNull @NotNull Sound getFallDamageSoundBig()
      Get the Sound this entity will make when falling from a large height.
      Returns:
      the fall damage sound
      Since:
      1.19.2
    • getDrinkingSound

      @NotNull @NotNull Sound getDrinkingSound(@NotNull @NotNull ItemStack itemStack)
      Get the Sound this entity will make when drinking the given ItemStack.
      Parameters:
      itemStack - the item stack being drank
      Returns:
      the drinking sound
      Since:
      1.19.2
    • getEatingSound

      @NotNull @NotNull Sound getEatingSound(@NotNull @NotNull ItemStack itemStack)
      Get the Sound this entity will make when eating the given ItemStack.
      Parameters:
      itemStack - the item stack being eaten
      Returns:
      the eating sound
      Since:
      1.19.2
    • canBreatheUnderwater

      boolean canBreatheUnderwater()
      Returns true if this entity can breathe underwater and will not take suffocation damage when its air supply reaches zero.
      Returns:
      true if the entity can breathe underwater
      Since:
      1.19.2
    • getCategory

      @NotNull @Deprecated(since="1.20.5", forRemoval=true) @Contract("-> fail") @NotNull EntityCategory getCategory()
      Deprecated, for removal: This API element is subject to removal in a future version.
      entity groupings are now managed by tags, not categories
      Get the category to which this entity belongs. Categories may subject this entity to additional effects, benefits or debuffs.
      Returns:
      the entity category
    • getArrowsStuck

      @Deprecated default @NonNegative int getArrowsStuck()
      Deprecated.
      Get the number of arrows stuck in this entity
      Returns:
      Number of arrows stuck
      Since:
      1.9.4
    • setArrowsStuck

      @Deprecated default void setArrowsStuck(@NonNegative int arrows)
      Deprecated.
      use setArrowsInBody(int, boolean). This method previously fired ArrowBodyCountChangeEvent so if you want to retain exact functionality, pass true for fireEvent.
      Set the number of arrows stuck in this entity
      Parameters:
      arrows - Number of arrows to stick in this entity
      Since:
      1.9.4
    • getShieldBlockingDelay

      @Deprecated(since="1.21.9") default int getShieldBlockingDelay()
      Deprecated.
      no longer applicable, check the blocks_attacks component on the shield
      Get the delay (in ticks) before blocking is effective for this entity
      Returns:
      Delay in ticks
      Since:
      1.12.2
    • setShieldBlockingDelay

      @Deprecated(since="1.21.9") default void setShieldBlockingDelay(int delay)
      Deprecated.
      no longer applicable, use the blocks_attacks component on the shield
      Set the delay (in ticks) before blocking is effective for this entity
      Parameters:
      delay - Delay in ticks
      Since:
      1.12.2
    • getSidewaysMovement

      float getSidewaysMovement()
      Retrieves the sideways movement direction of the entity.

      The returned value ranges from -1 to 1, where:

      • Positive 1 represents movement to the left.
      • Negative 1 represents movement to the right.
      Please note that for entities of type Player, this value will only return whole numbers depending on what keys are held, see Player.getCurrentInput().

      This method specifically provides information about the entity's sideways movement, whereas Entity.getVelocity() returns a vector representing the entity's overall current momentum.

      Returns:
      Sideways movement direction, ranging from -1 (right) to 1 (left).
      Since:
      1.20.2
    • getUpwardsMovement

      float getUpwardsMovement()
      Retrieves the upwards movement direction of the entity.

      The returned value ranges from -1 to 1, where:

      • Positive 1 represents upward movement.
      • Negative 1 represents downward movement.
      Please note that for entities of type Player, this value is never updated.

      This method specifically provides information about the entity's vertical movement, whereas Entity.getVelocity() returns a vector representing the entity's overall current momentum.

      Returns:
      Upwards movement direction, ranging from -1 (downward) to 1 (upward).
      Since:
      1.20.2
    • getForwardsMovement

      float getForwardsMovement()
      Retrieves the forwards movement direction of the entity.

      The returned value ranges from -1 to 1, where:

      • Positive 1 represents movement forwards.
      • Negative 1 represents movement backwards.
      Please note that for entities of type Player, this value will only return whole numbers depending on what keys are held, see Player.getCurrentInput().

      This method specifically provides information about the entity's forward and backward movement, whereas Entity.getVelocity() returns a vector representing the entity's overall current momentum.

      Returns:
      Forwards movement direction, ranging from -1 (backward) to 1 (forward).
      Since:
      1.20.2
    • startUsingItem

      @Experimental void startUsingItem(@NotNull EquipmentSlot hand)
      Starts using the item in the specified hand, making it the currently active item. When, for example, called on a skeleton, this will cause it to start drawing its bow.

      Only HAND or OFF_HAND may be used for the hand parameter.

      When used on a player, the client will stop using the item if right click is held down.

      This method does not make any guarantees about the effect of this method as such depends on the entity and its state.

      Parameters:
      hand - the hand that contains the item to be used
      Since:
      1.20.4
    • completeUsingActiveItem

      @Experimental void completeUsingActiveItem()
      Finishes using the currently active item. When, for example, a skeleton is drawing its bow, this will cause it to release and fire the arrow.

      This method does not make any guarantees about the effect of this method as such depends on the entity and its state.

      Since:
      1.20.4
    • getActiveItem

      @NotNull ItemStack getActiveItem()
      Gets the item being actively "used" or consumed.
      Returns:
      the item
      Since:
      1.12.2
    • clearActiveItem

      void clearActiveItem()
      Interrupts any ongoing active "usage" or consumption or an item.
      Since:
      1.16.4
    • getActiveItemRemainingTime

      int getActiveItemRemainingTime()
      Gets the remaining number of ticks for getActiveItem()'s usage.
      Returns:
      remaining ticks to use getActiveItem()
      Since:
      1.20.4
    • setActiveItemRemainingTime

      void setActiveItemRemainingTime(@Range(from=0L,to=2147483647L) int ticks)
      Sets the number of ticks that remain for getActiveItem()'s usage.

      Valid values are between 0 and the max item use duration for the specific item type.

      Parameters:
      ticks - time in ticks remaining
      Since:
      1.20.4
    • hasActiveItem

      boolean hasActiveItem()
      Gets if the entity is using an item (eating, drinking, etc).
      Returns:
      true if using an item
      Since:
      1.20.4
    • getActiveItemUsedTime

      int getActiveItemUsedTime()
      Get how long the getActiveItem() has been in use for.
      Returns:
      time used in ticks
      Since:
      1.20.4
    • getActiveItemHand

      @NotNull EquipmentSlot getActiveItemHand()
      Get the hand using the active item. Will be either EquipmentSlot.HAND or EquipmentSlot.OFF_HAND.
      Returns:
      the hand being used
      Since:
      1.20.4
    • getItemUseRemainingTime

      @Obsolete(since="1.20.4") default int getItemUseRemainingTime()
      Gets remaining time a player needs to keep hands raised with an item to finish using it.
      Returns:
      remaining ticks to use the item
      Since:
      1.12.2
      See Also:
    • getHandRaisedTime

      @Obsolete(since="1.20.4") default int getHandRaisedTime()
      Get how long the entity's hands have been raised (Charging Bow attack, using a potion, etc)
      Returns:
      Get how long the players hands have been raised (Charging Bow attack, using a potion, etc)
      Since:
      1.12.2
      See Also:
    • isHandRaised

      @Obsolete(since="1.20.4") default boolean isHandRaised()
      Whether this entity is using or charging an attack (Bow pulled back, drinking potion, eating food)
      Returns:
      whether this entity is using or charging an attack (Bow pulled back, drinking potion, eating food)
      Since:
      1.12.2
      See Also:
    • getHandRaised

      @NotNull @Obsolete(since="1.20.4") default EquipmentSlot getHandRaised()
      Gets the hand raised by this living entity. Will be either EquipmentSlot.HAND or EquipmentSlot.OFF_HAND.
      Returns:
      the hand raised
      Since:
      1.16.5
      See Also:
    • isJumping

      boolean isJumping()
      Get entity jump state.

      Jump state will be true when the entity has been marked to jump.

      Returns:
      entity jump state.
      Since:
      1.15.2
    • setJumping

      void setJumping(boolean jumping)
      Set entity jump state

      Setting to true will mark the entity to jump.

      Setting to false will unmark the entity to jump but will not stop a jump already in-progress.

      Parameters:
      jumping - entity jump state
      Since:
      1.15.2
    • playPickupItemAnimation

      default void playPickupItemAnimation(@NotNull @NotNull Item item)
      Plays pickup item animation towards this entity.

      This will remove the item on the client.

      Quantity is inferred to be that of the Item.

      Parameters:
      item - item to pickup
      Since:
      1.16.2
    • playPickupItemAnimation

      void playPickupItemAnimation(@NotNull @NotNull Item item, int quantity)
      Plays pickup item animation towards this entity.

      This will remove the item on the client.

      Parameters:
      item - item to pickup
      quantity - quantity of item
      Since:
      1.16.2
    • getHurtDirection

      float getHurtDirection()
      Gets player hurt direction
      Returns:
      hurt direction
      Since:
      1.16.4
    • setHurtDirection

      @Deprecated void setHurtDirection(float hurtDirection)
      Sets player hurt direction
      Parameters:
      hurtDirection - hurt direction
      Since:
      1.16.4
    • swingHand

      default void swingHand(@NotNull EquipmentSlot hand)
      Makes this entity swing their hand.

      This method does nothing if this entity does not have an animation for swinging their hand.

      Parameters:
      hand - hand to be swung, either EquipmentSlot.HAND or EquipmentSlot.OFF_HAND
      Throws:
      IllegalArgumentException - if invalid hand is passed
      Since:
      1.19.2
    • knockback

      void knockback(double strength, double directionX, double directionZ)
      Knocks back this entity from a specific direction with a specified strength. Mechanics such as knockback resistance will be factored in. The direction specified in this method will be the direction of the source of the knockback, so the entity will be pushed in the opposite direction.
      Parameters:
      strength - The strength of the knockback. Must be greater than 0.
      directionX - The relative x position of the knockback source direction
      directionZ - The relative z position of the knockback source direction
      Since:
      1.19.2
    • broadcastSlotBreak

      void broadcastSlotBreak(@NotNull EquipmentSlot slot)
      Notifies all clients tracking this entity that the item in the slot of this entity broke.

      NOTE: this does not mutate any entity state

      Parameters:
      slot - the slot
      Since:
      1.19.2
    • broadcastSlotBreak

      void broadcastSlotBreak(@NotNull EquipmentSlot slot, @NotNull @NotNull Collection<Player> players)
      Notifies specified players that the item in the slot of this entity broke.

      NOTE: this does not mutate any entity state

      Parameters:
      slot - the slot
      players - the players to notify
      Since:
      1.19.2
    • damageItemStack

      @NotNull @NotNull ItemStack damageItemStack(@NotNull @NotNull ItemStack stack, int amount)
      Damages the itemstack in this slot by the specified amount.

      This runs all logic associated with damaging an itemstack like gamemode and enchantment checks, events, stat changes, and advancement triggers.

      Parameters:
      stack - the itemstack to damage
      amount - the amount of damage to do
      Returns:
      the damaged itemstack, or an empty stack if it broke. There are no guarantees the returned itemstack is the same instance
      Since:
      1.19.2
    • damageItemStack

      void damageItemStack(@NotNull EquipmentSlot slot, int amount)
      Damages the itemstack in this slot by the specified amount.

      This runs all logic associated with damaging an itemstack like gamemode and enchantment checks, events, stat changes, advancement triggers, and notifying clients to play break animations.

      Parameters:
      slot - the slot of the stack to damage
      amount - the amount of damage to do
      Since:
      1.19.2
    • getBodyYaw

      float getBodyYaw()
      Gets entity body yaw
      Returns:
      entity body yaw
      Since:
      1.19.3
      See Also:
    • setBodyYaw

      void setBodyYaw(float bodyYaw)
      Sets entity body yaw
      Parameters:
      bodyYaw - new entity body yaw
      Since:
      1.19.3
      See Also:
    • canUseEquipmentSlot

      boolean canUseEquipmentSlot(@NotNull EquipmentSlot slot)
      Checks whether this entity can use the equipment slot.
      For example, not all entities may have EquipmentSlot.BODY.
      Parameters:
      slot - equipment slot
      Returns:
      whether this entity can use the equipment slot
      Since:
      1.20.6
    • getCombatTracker

      Gets the entity's combat tracker
      Returns:
      the entity's combat tracker
      Since:
      1.21.6
    • setWaypointStyle

      void setWaypointStyle(@Nullable @Nullable Key key)
      Sets the visual style of the waypoint icon using the specified Key.

      Minecraft has the keys "minecraft:bowtie" and "minecraft:default" built in.

      Parameters:
      key - the key representing the style, or null to use the default style
      Since:
      1.21.11
      See Also:
    • setWaypointColor

      void setWaypointColor(@Nullable @Nullable Color color)
      Sets the color of the waypoint icon.
      Parameters:
      color - the new color to apply to the waypoint icon, or null to use the default color. While the color may contain alpha values, the client does not receive them.
      Since:
      1.21.11
      See Also:
    • getWaypointStyle

      @NotNull @NotNull Key getWaypointStyle()
      Gets the current visual style of the waypoint icon.
      Returns:
      the Key representing the icon's style
      Since:
      1.21.11
      See Also:
    • getWaypointColor

      @Nullable @Nullable Color getWaypointColor()
      Gets the current color of the waypoint icon, if any.
      Returns:
      the icon's color, or null if the default color is used. While the color may contain alpha values, the client does not receive them.
      Since:
      1.21.11
      See Also: