Class LivingEntity
java.lang.Object
net.minestom.server.entity.Entity
net.minestom.server.entity.LivingEntity
- All Implemented Interfaces:
Identified, Pointered, Sound.Emitter, HoverEventSource<HoverEvent.ShowEntity>, Shape, DataComponent.Holder, EventHandler<EntityEvent>, EquipmentHandler, Snapshotable, Taggable, TagReadable, TagWritable, AcquirableSource<Entity>, Tickable, Schedulable, Viewable
- Direct Known Subclasses:
EntityCreature, Player
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected BoundingBoxprotected booleanprotected booleanprotected Cooldownprotected DamageIDs of modifiers that are protected from removal by methods likeAttributeInstance.clearModifiers().Fields inherited from class Entity
boundingBox, collidesWithEntities, currentChunk, ENTITY_POINTERS_SUPPLIER, entityMeta, entityType, gravityTickCount, hasPhysics, headRotation, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, preventBlockPlacement, previousPosition, removed, trackingUpdate, vehicle, velocity, viewEngine, viewers -
Constructor Summary
ConstructorsConstructorDescriptionLivingEntity(EntityType entityType) LivingEntity(EntityType entityType, UUID uuid) Constructor which allows to specify an UUID. -
Method Summary
Modifier and TypeMethodDescriptionAcquirable<? extends LivingEntity> Obtains anAcquirable.booleanGets 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(RegistryKey<DamageType> type, float amount) voidSets thepointof the bed in which the entity is sleeping in.intGets the amount of arrows in the entity.getAttribute(Attribute attribute) Retrieves the attribute instance and its modifiers.Retrieves allAttributeInstances on this entity.doublegetAttributeValue(Attribute attribute) Retrieves the attribute value.getEquipment(EquipmentSlot slot) Gets the equipment in a specific slot.intGets the amount of ticks this entity is on fire for.floatGets the entity health.Gets the last damage source which damaged of this entity.GetsEntityMetaof this entity casted toLivingEntityMeta.protected EntityAttributesPacketGets anEntityAttributesPacketfor this entity with all of its attributes values.getTargetBlockPosition(int maxDistance) Gets the target (not-air) block position of the entity.getTeam()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(RegistryKey<DamageType> type) Is this entity immune to the given type of damage?booleanGets if the entity is invulnerable.voidkill()Kills the entity, trigger theEntityDeathEventevent.voidleaveBed()Kicks the entity out of the bed.protected voidonAttributeChanged(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.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.voidsetEquipment(EquipmentSlot slot, ItemStack itemStack) voidsetFireTicks(int ticks) Sets this entity on fire for the given ticks.voidsetFlyingWithElytra(boolean isFlying) voidsetHealth(float health) Changes the entity health, kill it ifhealthis <= 0 and is not dead yet.voidsetInvulnerable(boolean invulnerable) Makes the entity vulnerable or invulnerable.voidsetSprinting(boolean sprinting) Makes the entity sprint.voidChanges theTeamfor the entity.protected booleanCheck if this entity should send anEntityAttributesPacket.voidSends aEntityAnimationPacketto swing the main hand (can be used for attack animation).voidswingMainHand(boolean fromClient) Sends aEntityAnimationPacketto swing the main hand (can be used for attack animation).voidSends aEntityAnimationPacketto swing the off hand (can be used for attack animation).voidswingOffHand(boolean fromClient) Sends 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.voidupdateEquipmentAttributes(ItemStack oldItemStack, ItemStack newItemStack, EquipmentSlot slot) Updates the current attributes of the living entity based onvoidupdateNewViewer(Player player) Called when a new viewer must be shown.Methods inherited from class Entity
addEffect, addPassenger, addViewer, asHoverEvent, autoViewEntities, clearEffects, despawn, editEntityMeta, eventNode, generateId, get, getAcquirable, getActiveEffects, getAerodynamics, getAliveTicks, getAttachEntityPacket, getBoundingBox, getChunk, getCustomName, getDistance, getDistance, getDistanceSquared, getDistanceSquared, getEffect, getEffectLevel, getEntityId, getEntityMeta, getEntityType, getEyeHeight, getGravityTickCount, getHeadRotation, getInstance, getLeashedEntities, getLeashHolder, getLineOfSight, getLineOfSightEntity, getMetadataPacket, getPassengers, getPassengersPacket, getPose, getPosition, getPreviousPosition, getSpawnPacket, getSynchronizationTicks, getUuid, getVehicle, getVelocity, getVelocityForPacket, getVelocityPacket, getViewers, hasEffect, hasEntityCollision, hasLineOfSight, hasLineOfSight, hasNoGravity, hasPassenger, hasPredictableViewers, hasVelocity, identity, intersectBox, intersectBoxSwept, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOccluded, isOnFire, isOnGround, isRemoved, isSilent, isSneaking, isSprinting, lookAt, lookAt, movementTick, pointers, preventBlockPlacement, refreshCoordinate, refreshCurrentChunk, refreshPosition, refreshPosition, refreshPosition, relativeEnd, relativeStart, remove, remove, removeEffect, removePassenger, removeViewer, scheduleNextTick, scheduler, scheduleRemove, scheduleRemove, set, setAerodynamics, setAutoViewable, setAutoViewEntities, setBoundingBox, setCustomName, setCustomNameVisible, setGlowing, setInstance, setInstance, setInstance, setInvisible, setLeashHolder, setNoGravity, setPose, setPositionInternal, setSilent, setSneaking, setSynchronizationTicks, setVelocity, setView, setView, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, teleport, teleport, teleport, teleport, teleport, tick, triggerStatus, updateCollisions, updateOldViewer, updatePose, updateSnapshot, updateViewableRule, updateViewableRule, updateViewerRule, updateViewerRuleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataComponent.Holder
get, hasMethods inherited from interface EquipmentHandler
getBodyEquipment, getBoots, getChestplate, getEquipmentsPacket, getHelmet, getItemInHand, getItemInMainHand, getItemInOffHand, getLeggings, hasEquipment, setBodyEquipment, setBoots, setChestplate, setHelmet, setItemInHand, setItemInMainHand, setItemInOffHand, setLeggings, syncEquipment, syncEquipmentMethods inherited from interface HoverEventSource
asHoverEventMethods inherited from interface Pointered
get, getOrDefault, getOrDefaultFromMethods inherited from interface Shape
intersectEntity, isFaceFullMethods inherited from interface Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTagMethods inherited from interface Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Field Details
-
PROTECTED_MODIFIERS
IDs of modifiers that are protected from removal by methods likeAttributeInstance.clearModifiers(). -
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
-
setSprinting
public void setSprinting(boolean sprinting) Description copied from class:EntityMakes the entity sprint.WARNING: this will not work on the client itself.
- Overrides:
setSprintingin classEntity- Parameters:
sprinting- true to make the entity sprint
-
getEquipment
Description copied from interface:EquipmentHandlerGets the equipment in a specific slot.- Specified by:
getEquipmentin interfaceEquipmentHandler- Parameters:
slot- the equipment to get the item from- Returns:
- the equipment
ItemStack
-
setEquipment
- Specified by:
setEquipmentin interfaceEquipmentHandler
-
updateEquipmentAttributes
@Internal public void updateEquipmentAttributes(ItemStack oldItemStack, ItemStack newItemStack, EquipmentSlot slot) Updates the current attributes of the living entity based on- Parameters:
oldItemStack- The ItemStack that has been removed, modifiers on this stack will be removed from the entitynewItemStack- The ItemStack that has been added, modifiers on this stack will be added to the entityslot- The slot that changed, this will determine what modifiers are actually changed
-
update
-
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. -
getFireTicks
public int getFireTicks()Gets the amount of ticks this entity is on fire for.- Returns:
- the remaining duration of fire in ticks, 0 if not on fire
-
setFireTicks
public void setFireTicks(int ticks) Sets this entity on fire for the given ticks.- Parameters:
ticks- duration of fire in ticks
-
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
-
heal
public void heal()Sets the heal of the entity as its max health.Retrieved from
getAttributeValue(Attribute)with the attributeAttributes.MAX_HEALTH. -
getAttribute
Retrieves the attribute instance and its modifiers.- Parameters:
attribute- the attribute instance to get- Returns:
- the attribute instance
-
getAttributes
Retrieves allAttributeInstances on this entity.- Returns:
- a collection of all attribute instances on this entity
-
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
-
shouldSendAttributes
protected boolean shouldSendAttributes()Check if this entity should send anEntityAttributesPacket. This is true for players and entities whose spawn type isLIVING, but false for others.- Returns:
- true if this entity needs to send attributes, false otherwise
-
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). -
swingMainHand
Sends aEntityAnimationPacketto swing the main hand (can be used for attack animation).- Parameters:
fromClient- if true, broadcast only to viewers
-
swingOffHand
Sends aEntityAnimationPacketto swing the off hand (can be used for attack animation).- Parameters:
fromClient- if true, broadcast only to viewers
-
refreshActiveHand
public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) -
leaveBed
public void leaveBed()Kicks the entity out of the bed. -
enterBed
Sets thepointof the bed in which the entity is sleeping in.- Parameters:
point- the position of the bed
-
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 anEntityAttributesPacketfor this entity with all of its attributes values.- Returns:
- an
EntityAttributesPacketlinked to this entity
-
setTeam
-
getTeam
-
getTargetBlockPosition
-
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))
-
acquirable
Description copied from interface:AcquirableSourceObtains anAcquirable. To safely perform operations on this object, the user must callAcquirable.sync(Consumer),Acquirable.applySync(Function), orAcquirable.lock()(followed by a subsequent unlock) on the Acquirable instance.- Specified by:
acquirablein interfaceAcquirableSource<Entity>- Overrides:
acquirablein classEntity- Returns:
- an Acquirable which can be used to synchronize access to this object
-