Class LivingEntity

java.lang.Object
net.minestom.server.entity.Entity
net.minestom.server.entity.LivingEntity
All Implemented Interfaces:
Sound.Emitter, HoverEventSource<HoverEvent.ShowEntity>, Shape, EventHandler<EntityEvent>, EquipmentHandler, PermissionHandler, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Schedulable, Viewable
Direct Known Subclasses:
EntityCreature, Player, PlayerProjectile

public class LivingEntity extends Entity implements EquipmentHandler
  • Field Details

    • canPickupItem

      protected boolean canPickupItem
    • itemPickupCooldown

      protected Cooldown itemPickupCooldown
    • isDead

      protected boolean isDead
    • lastDamage

      protected Damage lastDamage
    • expandedBoundingBox

      protected BoundingBox expandedBoundingBox
    • invulnerable

      protected boolean invulnerable
  • Constructor Details

    • LivingEntity

      public LivingEntity(@NotNull @NotNull EntityType entityType, @NotNull @NotNull UUID uuid)
      Constructor which allows to specify an UUID. Only use if you know what you are doing!
    • LivingEntity

      public LivingEntity(@NotNull @NotNull EntityType entityType)
  • Method Details

    • getItemInMainHand

      @NotNull public @NotNull ItemStack getItemInMainHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in main hand.
      Specified by:
      getItemInMainHand in interface EquipmentHandler
      Returns:
      the ItemStack in main hand
    • setItemInMainHand

      public void setItemInMainHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the main hand ItemStack.
      Specified by:
      setItemInMainHand in interface EquipmentHandler
      Parameters:
      itemStack - the main hand ItemStack
    • getItemInOffHand

      @NotNull public @NotNull ItemStack getItemInOffHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in off hand.
      Specified by:
      getItemInOffHand in interface EquipmentHandler
      Returns:
      the item in off hand
    • setItemInOffHand

      public void setItemInOffHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the off hand ItemStack.
      Specified by:
      setItemInOffHand in interface EquipmentHandler
      Parameters:
      itemStack - the off hand ItemStack
    • getHelmet

      @NotNull public @NotNull ItemStack getHelmet()
      Description copied from interface: EquipmentHandler
      Gets the helmet.
      Specified by:
      getHelmet in interface EquipmentHandler
      Returns:
      the helmet
    • setHelmet

      public void setHelmet(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the helmet.
      Specified by:
      setHelmet in interface EquipmentHandler
      Parameters:
      itemStack - the helmet
    • getChestplate

      @NotNull public @NotNull ItemStack getChestplate()
      Description copied from interface: EquipmentHandler
      Gets the chestplate.
      Specified by:
      getChestplate in interface EquipmentHandler
      Returns:
      the chestplate
    • setChestplate

      public void setChestplate(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the chestplate.
      Specified by:
      setChestplate in interface EquipmentHandler
      Parameters:
      itemStack - the chestplate
    • getLeggings

      @NotNull public @NotNull ItemStack getLeggings()
      Description copied from interface: EquipmentHandler
      Gets the leggings.
      Specified by:
      getLeggings in interface EquipmentHandler
      Returns:
      the leggings
    • setLeggings

      public void setLeggings(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the leggings.
      Specified by:
      setLeggings in interface EquipmentHandler
      Parameters:
      itemStack - the leggings
    • getBoots

      @NotNull public @NotNull ItemStack getBoots()
      Description copied from interface: EquipmentHandler
      Gets the boots.
      Specified by:
      getBoots in interface EquipmentHandler
      Returns:
      the boots
    • setBoots

      public void setBoots(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the boots.
      Specified by:
      setBoots in interface EquipmentHandler
      Parameters:
      itemStack - the boots
    • update

      public void update(long time)
      Description copied from class: Entity
      Called each tick.
      Overrides:
      update in class Entity
      Parameters:
      time - time of the update in milliseconds
    • getArrowCount

      public int getArrowCount()
      Gets the amount of arrows in the entity.
      Returns:
      the arrow count
    • setArrowCount

      public void setArrowCount(int arrowCount)
      Changes the amount of arrow stuck in the entity.
      Parameters:
      arrowCount - the arrow count
    • isInvulnerable

      public boolean isInvulnerable()
      Gets if the entity is invulnerable.
      Returns:
      true if the entity is invulnerable
    • setInvulnerable

      public void setInvulnerable(boolean invulnerable)
      Makes the entity vulnerable or invulnerable.
      Parameters:
      invulnerable - should the entity be invulnerable
    • kill

      public void kill()
      Kills the entity, trigger the EntityDeathEvent event.
    • setFireForDuration

      public void setFireForDuration(int duration)
      Sets fire to this entity for a given duration.
      Parameters:
      duration - duration in ticks of the effect
    • setFireForDuration

      public void setFireForDuration(int duration, TemporalUnit temporalUnit)
      Sets fire to this entity for a given duration.
      Parameters:
      duration - duration of the effect
      temporalUnit - unit used to express the duration
      See Also:
    • setFireForDuration

      public void setFireForDuration(Duration duration)
      Sets fire to this entity for a given duration.
      Parameters:
      duration - duration of the effect
      See Also:
    • damage

      public boolean damage(@NotNull @NotNull DamageType type, float amount)
    • damage

      public boolean damage(@NotNull @NotNull Damage damage)
      Damages the entity by a value, the type of the damage also has to be specified.
      Parameters:
      damage - the damage to be applied
      Returns:
      true if damage has been applied, false if it didn't
    • isImmune

      public boolean isImmune(@NotNull @NotNull DamageType type)
      Is this entity immune to the given type of damage?
      Parameters:
      type - the type of damage
      Returns:
      true if this entity is immune to the given type of damage
    • getHealth

      public float getHealth()
      Gets the entity health.
      Returns:
      the entity health
    • setHealth

      public void setHealth(float health)
      Changes the entity health, kill it if health is <= 0 and is not dead yet.
      Parameters:
      health - the new entity health
    • getLastDamageSource

      @Nullable public @Nullable Damage getLastDamageSource()
      Gets the last damage source which damaged of this entity.
      Returns:
      the last damage source, null if not any
    • getMaxHealth

      public float getMaxHealth()
      Gets the entity max health from getAttributeValue(Attribute) Attributes.GENERIC_MAX_HEALTH.
      Returns:
      the entity max health
    • heal

      public void heal()
      Sets the heal of the entity as its max health.

      Retrieved from getAttributeValue(Attribute) with the attribute Attributes.GENERIC_MAX_HEALTH.

    • getAttribute

      @NotNull public @NotNull AttributeInstance getAttribute(@NotNull @NotNull Attribute attribute)
      Retrieves the attribute instance and its modifiers.
      Parameters:
      attribute - the attribute instance to get
      Returns:
      the attribute instance
    • onAttributeChanged

      protected void onAttributeChanged(@NotNull @NotNull AttributeInstance attributeInstance)
      Callback used when an attribute instance has been modified.
      Parameters:
      attributeInstance - the modified attribute instance
    • getAttributeValue

      public float getAttributeValue(@NotNull @NotNull Attribute attribute)
      Retrieves the attribute value.
      Parameters:
      attribute - the attribute value to get
      Returns:
      the attribute value
    • isDead

      public boolean isDead()
      Gets if the entity is dead or not.
      Returns:
      true if the entity is dead
    • canPickupItem

      public boolean canPickupItem()
      Gets if the entity is able to pickup items.
      Returns:
      true if the entity is able to pickup items
    • setCanPickupItem

      public void setCanPickupItem(boolean canPickupItem)
      When set to false, the entity will not be able to pick ItemEntity on the ground.
      Parameters:
      canPickupItem - can the entity pickup item
    • updateNewViewer

      public void updateNewViewer(@NotNull @NotNull Player player)
      Description copied from class: Entity
      Called when a new viewer must be shown. Method can be subject to deadlocking if the target's viewers are also accessed.
      Overrides:
      updateNewViewer in class Entity
      Parameters:
      player - the player to send the packets to
    • setBoundingBox

      public void setBoundingBox(BoundingBox boundingBox)
      Description copied from class: Entity
      Changes the internal entity standing bounding box. When the pose is not standing, a different bounding box may be used for collision.

      WARNING: this does not change the entity hit-box which is client-side.

      Overrides:
      setBoundingBox in class Entity
      Parameters:
      boundingBox - the new bounding box
    • swingMainHand

      public void swingMainHand()
      Sends a EntityAnimationPacket to swing the main hand (can be used for attack animation).
    • swingOffHand

      public void swingOffHand()
      Sends a EntityAnimationPacket to swing the off hand (can be used for attack animation).
    • refreshActiveHand

      public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack)
    • isFlyingWithElytra

      public boolean isFlyingWithElytra()
    • setFlyingWithElytra

      public void setFlyingWithElytra(boolean isFlying)
    • refreshIsDead

      protected void refreshIsDead(boolean isDead)
      Used to change the isDead internal field.
      Parameters:
      isDead - the new field value
    • getPropertiesPacket

      @NotNull protected @NotNull EntityPropertiesPacket getPropertiesPacket()
      Gets an EntityPropertiesPacket for this entity with all of its attributes values.
      Returns:
      an EntityPropertiesPacket linked to this entity
    • getFireDamagePeriod

      public long getFireDamagePeriod()
      Gets the time in ms between two fire damage applications.
      Returns:
      the time in ms
      See Also:
    • setFireDamagePeriod

      public void setFireDamagePeriod(long fireDamagePeriod, @NotNull @NotNull TemporalUnit temporalUnit)
      Changes the delay between two fire damage applications.
      Parameters:
      fireDamagePeriod - the delay
      temporalUnit - the time unit
    • setFireDamagePeriod

      public void setFireDamagePeriod(Duration fireDamagePeriod)
      Changes the delay between two fire damage applications.
      Parameters:
      fireDamagePeriod - the delay
    • setTeam

      public void setTeam(@Nullable @Nullable Team team)
      Changes the Team for the entity.
      Parameters:
      team - The new team
    • getTeam

      @Nullable public @Nullable Team getTeam()
      Gets the Team of the entity.
      Returns:
      the Team
    • getTargetBlockPosition

      @Nullable public @Nullable Point getTargetBlockPosition(int maxDistance)
      Gets the target (not-air) block position of the entity.
      Parameters:
      maxDistance - The max distance to scan before returning null
      Returns:
      The block position targeted by this entity, null if non are found
    • getLivingEntityMeta

      @Nullable public @Nullable LivingEntityMeta getLivingEntityMeta()
      Gets EntityMeta of this entity casted to LivingEntityMeta.
      Returns:
      null if meta of this entity does not inherit LivingEntityMeta, casted value otherwise.
    • takeKnockback

      public void takeKnockback(float strength, double x, double z)
      Applies knockback

      Note: The strength is reduced based on knockback resistance

      Overrides:
      takeKnockback in class Entity
      Parameters:
      strength - the strength of the knockback, 0.4 is the vanilla value for a bare hand hit
      x - knockback on x axle, for default knockback use the following formula
      sin(attacker.yaw * (pi/180))
      z - knockback on z axle, for default knockback use the following formula
      -cos(attacker.yaw * (pi/180))