Package net.minestom.server.entity
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
-
Nested Class Summary
Nested classes/interfaces inherited from class net.minestom.server.entity.Entity
Entity.Pose -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected BoundingBoxprotected booleanprotected booleanprotected Cooldownprotected DamageFields inherited from class net.minestom.server.entity.Entity
boundingBox, currentChunk, entityMeta, entityType, gravityTickCount, hasCollision, hasPhysics, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, previousPosition, removed, trackingUpdate, uuid, vehicle, velocity, viewEngine, viewers -
Constructor Summary
ConstructorsConstructorDescriptionLivingEntity(@NotNull EntityType entityType) LivingEntity(@NotNull EntityType entityType, @NotNull UUID uuid) Constructor which allows to specify an UUID. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets if the entity is able to pickup items.booleanDamages the entity by a value, the type of the damage also has to be specified.booleandamage(@NotNull DamageType type, float amount) intGets the amount of arrows in the entity.@NotNull AttributeInstancegetAttribute(@NotNull Attribute attribute) Retrieves the attribute instance and its modifiers.floatgetAttributeValue(@NotNull Attribute attribute) Retrieves the attribute value.@NotNull ItemStackgetBoots()Gets the boots.@NotNull ItemStackGets the chestplate.longGets the time in ms between two fire damage applications.floatGets the entity health.@NotNull ItemStackGets the helmet.@NotNull ItemStackGets theItemStackin main hand.@NotNull ItemStackGets theItemStackin off hand.@Nullable DamageGets the last damage source which damaged of this entity.@NotNull ItemStackGets the leggings.@Nullable LivingEntityMetaGetsEntityMetaof this entity casted toLivingEntityMeta.floatGets the entity max health fromgetAttributeValue(Attribute)Attributes.GENERIC_MAX_HEALTH.protected @NotNull EntityPropertiesPacketGets anEntityPropertiesPacketfor this entity with all of its attributes values.@Nullable PointgetTargetBlockPosition(int maxDistance) Gets the target (not-air) block position of the entity.@Nullable TeamgetTeam()Gets theTeamof the entity.voidheal()Sets the heal of the entity as its max health.booleanisDead()Gets if the entity is dead or not.booleanbooleanisImmune(@NotNull DamageType type) Is this entity immune to the given type of damage?booleanGets if the entity is invulnerable.voidkill()Kills the entity, trigger theEntityDeathEventevent.protected voidonAttributeChanged(@NotNull AttributeInstance attributeInstance) Callback used when an attribute instance has been modified.voidrefreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) protected voidrefreshIsDead(boolean isDead) Used to change theisDeadinternal field.voidsetArrowCount(int arrowCount) Changes the amount of arrow stuck in the entity.voidChanges the boots.voidsetBoundingBox(BoundingBox boundingBox) Changes the internal entity standing bounding box.voidsetCanPickupItem(boolean canPickupItem) When set to false, the entity will not be able to pickItemEntityon the ground.voidsetChestplate(@NotNull ItemStack itemStack) Changes the chestplate.voidsetFireDamagePeriod(long fireDamagePeriod, @NotNull TemporalUnit temporalUnit) Changes the delay between two fire damage applications.voidsetFireDamagePeriod(Duration fireDamagePeriod) Changes the delay between two fire damage applications.voidsetFireForDuration(int duration) Sets fire to this entity for a given duration.voidsetFireForDuration(int duration, TemporalUnit temporalUnit) Sets fire to this entity for a given duration.voidsetFireForDuration(Duration duration) Sets fire to this entity for a given duration.voidsetFlyingWithElytra(boolean isFlying) voidsetHealth(float health) Changes the entity health, kill it ifhealthis <= 0 and is not dead yet.voidChanges the helmet.voidsetInvulnerable(boolean invulnerable) Makes the entity vulnerable or invulnerable.voidsetItemInMainHand(@NotNull ItemStack itemStack) Changes the main handItemStack.voidsetItemInOffHand(@NotNull ItemStack itemStack) Changes the off handItemStack.voidsetLeggings(@NotNull ItemStack itemStack) Changes the leggings.voidChanges theTeamfor the entity.voidSends aEntityAnimationPacketto swing the main hand (can be used for attack animation).voidSends aEntityAnimationPacketto swing the off hand (can be used for attack animation).voidtakeKnockback(float strength, double x, double z) Applies knockbackvoidupdate(long time) Called each tick.voidupdateNewViewer(@NotNull Player player) Called when a new viewer must be shown.Methods inherited from class net.minestom.server.entity.Entity
addEffect, addPassenger, addViewer, asHoverEvent, autoViewEntities, clearEffects, despawn, editEntityMeta, eventNode, generateId, getAcquirable, getActiveEffects, getAerodynamics, getAliveTicks, getAllPermissions, getAttachEntityPacket, getBoundingBox, getChunk, getCustomName, getDistance, getDistance, getDistanceSquared, getDistanceSquared, getEffect, getEffectLevel, getEntity, getEntity, getEntityId, getEntityMeta, getEntityType, getEyeHeight, getGravityTickCount, getInstance, getLeashedEntities, getLeashHolder, getLineOfSight, getLineOfSightEntity, getMetadataPacket, getPassengers, getPassengersPacket, getPose, getPosition, getPreviousPosition, getSynchronizationTicks, getUuid, getVehicle, getVelocity, getVelocityForPacket, getVelocityPacket, getViewers, hasCollision, hasEffect, hasLineOfSight, hasLineOfSight, hasNoGravity, hasPassenger, hasPredictableViewers, hasVelocity, intersectBox, intersectBoxSwept, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOccluded, isOnFire, isOnGround, isRemoved, isSilent, isSneaking, isSprinting, lookAt, lookAt, movementTick, refreshCoordinate, refreshCurrentChunk, refreshPosition, refreshPosition, refreshPosition, relativeEnd, relativeStart, remove, remove, removeEffect, removePassenger, removeViewer, scheduleNextTick, scheduler, scheduleRemove, scheduleRemove, setAerodynamics, setAutoViewable, setAutoViewEntities, setBoundingBox, setCustomName, setCustomNameVisible, setGlowing, setInstance, setInstance, setInstance, setInvisible, setLeashHolder, setNoGravity, setOnFire, setPose, setSilent, setSneaking, setSprinting, setSynchronizationTicks, setUuid, setVelocity, setView, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, teleport, tick, triggerStatus, updateOldViewer, updatePose, updateSnapshot, updateViewableRule, updateViewableRule, updateViewerRule, updateViewerRuleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, hasEquipment, setEquipment, setItemInHand, syncEquipmentMethods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEventMethods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, getPermission, hasPermission, hasPermission, hasPermission, removePermission, removePermissionMethods inherited from interface net.minestom.server.collision.Shape
intersectEntity, isFaceFullMethods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Field Details
-
canPickupItem
protected boolean canPickupItem -
itemPickupCooldown
-
isDead
protected boolean isDead -
lastDamage
-
expandedBoundingBox
-
invulnerable
protected boolean invulnerable
-
-
Constructor Details
-
LivingEntity
Constructor which allows to specify an UUID. Only use if you know what you are doing! -
LivingEntity
-
-
Method Details
-
getItemInMainHand
Description copied from interface:EquipmentHandlerGets theItemStackin main hand.- Specified by:
getItemInMainHandin interfaceEquipmentHandler- Returns:
- the
ItemStackin main hand
-
setItemInMainHand
Description copied from interface:EquipmentHandlerChanges the main handItemStack.- Specified by:
setItemInMainHandin interfaceEquipmentHandler- Parameters:
itemStack- the main handItemStack
-
getItemInOffHand
Description copied from interface:EquipmentHandlerGets theItemStackin off hand.- Specified by:
getItemInOffHandin interfaceEquipmentHandler- Returns:
- the item in off hand
-
setItemInOffHand
Description copied from interface:EquipmentHandlerChanges the off handItemStack.- Specified by:
setItemInOffHandin interfaceEquipmentHandler- Parameters:
itemStack- the off handItemStack
-
getHelmet
Description copied from interface:EquipmentHandlerGets the helmet.- Specified by:
getHelmetin interfaceEquipmentHandler- Returns:
- the helmet
-
setHelmet
Description copied from interface:EquipmentHandlerChanges the helmet.- Specified by:
setHelmetin interfaceEquipmentHandler- Parameters:
itemStack- the helmet
-
getChestplate
Description copied from interface:EquipmentHandlerGets the chestplate.- Specified by:
getChestplatein interfaceEquipmentHandler- Returns:
- the chestplate
-
setChestplate
Description copied from interface:EquipmentHandlerChanges the chestplate.- Specified by:
setChestplatein interfaceEquipmentHandler- Parameters:
itemStack- the chestplate
-
getLeggings
Description copied from interface:EquipmentHandlerGets the leggings.- Specified by:
getLeggingsin interfaceEquipmentHandler- Returns:
- the leggings
-
setLeggings
Description copied from interface:EquipmentHandlerChanges the leggings.- Specified by:
setLeggingsin interfaceEquipmentHandler- Parameters:
itemStack- the leggings
-
getBoots
Description copied from interface:EquipmentHandlerGets the boots.- Specified by:
getBootsin interfaceEquipmentHandler- Returns:
- the boots
-
setBoots
Description copied from interface:EquipmentHandlerChanges the boots.- Specified by:
setBootsin interfaceEquipmentHandler- Parameters:
itemStack- the boots
-
update
public void update(long time) Description copied from class:EntityCalled each tick. -
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 theEntityDeathEventevent. -
setFireForDuration
public void setFireForDuration(int duration) Sets fire to this entity for a given duration.- Parameters:
duration- duration in ticks of the effect
-
setFireForDuration
Sets fire to this entity for a given duration.- Parameters:
duration- duration of the effecttemporalUnit- unit used to express the duration- See Also:
-
setFireForDuration
Sets fire to this entity for a given duration.- Parameters:
duration- duration of the effect- See Also:
-
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
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 ifhealthis <= 0 and is not dead yet.- Parameters:
health- the new entity health
-
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 fromgetAttributeValue(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 attributeAttributes.GENERIC_MAX_HEALTH. -
getAttribute
Retrieves the attribute instance and its modifiers.- Parameters:
attribute- the attribute instance to get- Returns:
- the attribute instance
-
onAttributeChanged
Callback used when an attribute instance has been modified.- Parameters:
attributeInstance- the modified attribute instance
-
getAttributeValue
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 pickItemEntityon the ground.- Parameters:
canPickupItem- can the entity pickup item
-
updateNewViewer
Description copied from class:EntityCalled when a new viewer must be shown. Method can be subject to deadlocking if the target's viewers are also accessed.- Overrides:
updateNewViewerin classEntity- Parameters:
player- the player to send the packets to
-
setBoundingBox
Description copied from class:EntityChanges 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:
setBoundingBoxin classEntity- Parameters:
boundingBox- the new bounding box
-
swingMainHand
public void swingMainHand()Sends aEntityAnimationPacketto swing the main hand (can be used for attack animation). -
swingOffHand
public void swingOffHand()Sends aEntityAnimationPacketto 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 theisDeadinternal field.- Parameters:
isDead- the new field value
-
getPropertiesPacket
Gets anEntityPropertiesPacketfor this entity with all of its attributes values.- Returns:
- an
EntityPropertiesPacketlinked 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
Changes the delay between two fire damage applications.- Parameters:
fireDamagePeriod- the delaytemporalUnit- the time unit
-
setFireDamagePeriod
Changes the delay between two fire damage applications.- Parameters:
fireDamagePeriod- the delay
-
setTeam
Changes theTeamfor the entity.- Parameters:
team- The new team
-
getTeam
Gets theTeamof the entity.- Returns:
- the
Team
-
getTargetBlockPosition
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
GetsEntityMetaof this entity casted toLivingEntityMeta.- 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 knockbackNote: The strength is reduced based on knockback resistance
- Overrides:
takeKnockbackin classEntity- Parameters:
strength- the strength of the knockback, 0.4 is the vanilla value for a bare hand hitx- knockback on x axle, for default knockback use the following formulasin(attacker.yaw * (pi/180))
z- knockback on z axle, for default knockback use the following formula-cos(attacker.yaw * (pi/180))
-