Class Entity
- All Implemented Interfaces:
Sound.Emitter
,HoverEventSource<HoverEvent.ShowEntity>
,Shape
,EventHandler<EntityEvent>
,PermissionHandler
,Snapshotable
,Taggable
,TagReadable
,TagWritable
,AcquirableSource<Entity>
,Tickable
,Schedulable
,Viewable
- Direct Known Subclasses:
EntityProjectile
,ExperienceOrb
,ItemEntity
,LivingEntity
To create your own entity you probably want to extend LivingEntity
or EntityCreature
instead.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BoundingBox
protected boolean
protected Chunk
protected EntityMeta
protected EntityType
protected int
protected boolean
protected Instance
protected Pos
protected boolean
protected MetadataHolder
protected boolean
protected Pos
protected boolean
protected Pos
protected boolean
protected final EntityTracker.Update
<Entity> protected Entity
protected Vec
protected final net.minestom.server.entity.EntityView
-
Constructor Summary
ConstructorsConstructorDescriptionEntity
(@NotNull EntityType entityType) Entity
(@NotNull EntityType entityType, @NotNull UUID uuid) -
Method Summary
Modifier and TypeMethodDescription@NotNull Acquirable
<? extends Entity> Obtains anAcquirable
.void
Adds an effect to an entity.void
addPassenger
(@NotNull Entity entity) Adds a new passenger to this entity.final boolean
Adds a viewer.@NotNull HoverEvent
<HoverEvent.ShowEntity> asHoverEvent
(@NotNull UnaryOperator<HoverEvent.ShowEntity> op) boolean
Gets if surrounding entities are automatically visible by this.void
Removes all the effects currently applied to the entity.protected void
despawn()
Called right before an entity is removed<TMeta extends EntityMeta>
voideditEntityMeta
(Class<TMeta> metaClass, Consumer<TMeta> editor) Do a batch edit of this entity's metadata.@NotNull EventNode
<EntityEvent> static int
Generate and return a new unique entity id.<T extends Entity>
@NotNull Acquirable<T> Deprecated.@NotNull List
<@NotNull TimedPotion> Gets all the potion effect of this entity.@NotNull Aerodynamics
Gets the aerodynamics; how the entity behaves in the air.long
Gets the number of ticks this entity has been active for.@NotNull Set
<Permission> Returns all permissions associated to this handler.protected @NotNull AttachEntityPacket
@NotNull BoundingBox
Returns the current bounding box (based on pose).@Nullable Chunk
getChunk()
Convenient method to get the entity current chunk.@Nullable Component
Gets the entity custom name.double
getDistance
(@NotNull Point point) double
getDistance
(@NotNull Entity entity) Gets the distance between two entities.double
getDistanceSquared
(@NotNull Point point) double
getDistanceSquared
(@NotNull Entity entity) Gets the distance squared between two entities.@Nullable TimedPotion
getEffect
(@NotNull PotionEffect effect) Gets the TimedPotion of the specified effect.int
getEffectLevel
(@NotNull PotionEffect effect) Gets the level of the specified effect.int
Each entity has an unique id (server-wide) which will change after a restart.@NotNull EntityMeta
Gets metadata of this entity.@NotNull EntityType
Returns the entity type.double
Gets the entity eye height.int
Gets the number of tick this entity has been applied gravity.@UnknownNullability Instance
Gets the entity current instance.Gets the entities that this entity is leashing.@Nullable Entity
Gets the current leash holder.getLineOfSight
(int maxDistance) Gets the line of sight of the entity.@Nullable Entity
getLineOfSightEntity
(double range, Predicate<Entity> predicate) Gets first entity on the line of sight of the current one that matches the given predicate.@NotNull EntityMetaDataPacket
Gets anEntityMetaDataPacket
sent when adding viewers.Gets the entity passengers.protected @NotNull SetPassengersPacket
@NotNull Entity.Pose
getPose()
Gets the current entity pose.@NotNull Pos
Gets the entity position.@NotNull Pos
Gets the previous entity position.long
Returns the current synchronization interval.@NotNull UUID
getUuid()
Gets the entityUUID
.@Nullable Entity
Gets the entity vehicle or null.@NotNull Vec
Gets the entity current velocity.protected @NotNull Vec
protected @NotNull EntityVelocityPacket
Gets all the viewers of this viewable element.boolean
hasEffect
(@NotNull PotionEffect effect) If the entity has the specified effect.boolean
boolean
hasLineOfSight
(Entity entity) boolean
hasLineOfSight
(Entity entity, boolean exactView) Raycasts current entity's eye position to target eye position.boolean
Gets the noGravity metadata field.boolean
Gets if the entity has any passenger.boolean
Gets if this entity's viewers (surrounding players) can be predicted from surrounding chunks.boolean
Gets if the entity currently has a velocity applied.boolean
intersectBox
(@NotNull Point positionRelative, @NotNull BoundingBox boundingBox) Checks if two bounding boxes intersect.boolean
intersectBoxSwept
(@NotNull Point rayStart, @NotNull Point rayDirection, @NotNull Point shapePos, @NotNull BoundingBox moving, @NotNull SweepResult finalResult) Checks if a moving bounding box will hit this shape.boolean
isActive()
Returns false just after instantiation, set to true after callingsetInstance(Instance)
.boolean
Gets if this entity is automatically sent to surrounding players.boolean
Gets the custom name visible metadata field.boolean
Gets if the entity is glowing or not.boolean
Gets if the entity is invisible or not.boolean
isOccluded
(@NotNull Shape shape, @NotNull BlockFace face) boolean
isOnFire()
Gets if the entity is on fire.boolean
boolean
Gets if this entity has been removed.boolean
isSilent()
boolean
Gets if the entity is sneaking.boolean
Gets if the player is sprinting.void
Changes the view of the entity so that it looks in a direction to the given position if it is different from the entity's current position.void
Changes the view of the entity so that it looks in a direction to the given entity.protected void
boolean
protected void
refreshCoordinate
(Point newPosition) Used to refresh the entity and its passengers position - put the entity in the right instance chunk - update the viewable chunks (load and unload) - add/remove players from the viewers list ifisAutoViewable()
is enabledprotected void
refreshCurrentChunk
(Chunk currentChunk) void
refreshPosition
(@NotNull Pos newPosition) void
refreshPosition
(@NotNull Pos newPosition, boolean ignoreView) void
refreshPosition
(@NotNull Pos newPosition, boolean ignoreView, boolean sendPackets) Updates internal fields and sends updates.@NotNull Point
Relative End@NotNull Point
Relative Startvoid
remove()
Removes the entity from the server immediately.protected void
remove
(boolean permanent) void
removeEffect
(@NotNull PotionEffect effect) Removes effect from entity, if it has it.void
removePassenger
(@NotNull Entity entity) Removes a passenger to this entity.final boolean
removeViewer
(@NotNull Player player) Removes a viewer.void
scheduleNextTick
(@NotNull Consumer<Entity> callback) Schedules a task to be run during the next entity tick.@NotNull Scheduler
void
scheduleRemove
(long delay, @NotNull TemporalUnit temporalUnit) Triggersremove()
after the specified time.void
scheduleRemove
(Duration delay) Triggersremove()
after the specified time.void
setAerodynamics
(@NotNull Aerodynamics aerodynamics) Sets the aerodynamics; how the entity behaves in the air.void
setAutoViewable
(boolean autoViewable) Decides if this entity should be auto-viewable by nearby players.void
setAutoViewEntities
(boolean autoViewer) Decides if surrounding entities must be visible.void
setBoundingBox
(double width, double height, double depth) Changes the internal entity standing bounding box.void
setBoundingBox
(BoundingBox boundingBox) Changes the internal entity standing bounding box.void
setCustomName
(@Nullable Component customName) Changes the entity custom name.void
setCustomNameVisible
(boolean customNameVisible) Changes the internal custom name visible field and send aEntityMetaDataPacket
to update the entity state to its viewers.void
setGlowing
(boolean glowing) Sets or remove the entity glowing effect.setInstance
(@NotNull Instance instance) Changes the entity instance.setInstance
(@NotNull Instance instance, @NotNull Point spawnPosition) setInstance
(@NotNull Instance instance, @NotNull Pos spawnPosition) Changes the entity instance, i.e.void
setInvisible
(boolean invisible) Changes the internal invisible value and send aEntityMetaDataPacket
to make visible or invisible the entity to its viewers.void
setLeashHolder
(@Nullable Entity entity) Sets the leash holder to this entity.void
setNoGravity
(boolean noGravity) Changes the noGravity metadata field and change the gravity behaviour accordingly.void
setPose
(@NotNull Entity.Pose pose) Changes the entity pose.void
setSilent
(boolean silent) void
setSneaking
(boolean sneaking) Makes the entity sneak.void
setSprinting
(boolean sprinting) Makes the entity sprint.void
setSynchronizationTicks
(long ticks) Set the tick period until this entity's position is synchronized.void
setVelocity
(@NotNull Vec velocity) Changes the entity velocity and callsEntityVelocityEvent
.void
setView
(float yaw, float pitch) Changes the view of the entity.void
spawn()
Called when a new instance is set.void
switchEntityType
(@NotNull EntityType entityType) Changes the entity type of this entity.void
Asks for a position synchronization to happen during next entity tick.protected void
Used to synchronize entity position with viewers by sending anEntityTeleportPacket
andEntityHeadLookPacket
to viewers.@NotNull TagHandler
void
takeKnockback
(float strength, double x, double z) Applies knockback to the entity@NotNull CompletableFuture
<Void> @NotNull CompletableFuture
<Void> @NotNull CompletableFuture
<Void> Teleports the entity only if the chunk atposition
is loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.void
tick
(long time) Updates the entity, called every tick.void
triggerStatus
(byte status) Entity statuses can be found here.void
update
(long time) Called each tick.protected void
void
updateNewViewer
(@NotNull Player player) Called when a new viewer must be shown.void
updateOldViewer
(@NotNull Player player) Called when a viewer must be destroyed.protected void
@NotNull EntitySnapshot
updateSnapshot
(@NotNull SnapshotUpdater updater) Updates the currently cached snapshot if required.void
void
updateViewableRule
(@Nullable Predicate<Player> predicate) void
void
updateViewerRule
(@Nullable Predicate<Entity> predicate) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent
Methods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, getPermission, hasPermission, hasPermission, hasPermission, removePermission, removePermission
Methods inherited from interface net.minestom.server.collision.Shape
intersectEntity, isFaceFull
Methods inherited from interface net.minestom.server.tag.Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, updateAndGetTag, updateTag
Methods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Field Details
-
instance
-
currentChunk
-
position
-
previousPosition
-
lastSyncedPosition
-
onGround
protected boolean onGround -
boundingBox
-
vehicle
-
velocity
-
lastVelocityWasZero
protected boolean lastVelocityWasZero -
hasPhysics
protected boolean hasPhysics -
collidesWithEntities
protected boolean collidesWithEntities -
preventBlockPlacement
protected boolean preventBlockPlacement -
gravityTickCount
protected int gravityTickCount -
trackingUpdate
-
viewEngine
protected final net.minestom.server.entity.EntityView viewEngine -
viewers
-
removed
protected boolean removed -
entityType
-
metadata
-
entityMeta
-
-
Constructor Details
-
Entity
-
Entity
-
-
Method Details
-
scheduleNextTick
Schedules a task to be run during the next entity tick.- Parameters:
callback
- the task to execute during the next entity tick
-
generateId
public static int generateId()Generate and return a new unique entity id.Useful if you want to spawn entities using packet but don't risk to have duplicated id.
- Returns:
- a newly generated entity id
-
update
public void update(long time) Called each tick.- Parameters:
time
- time of the update in milliseconds
-
spawn
public void spawn()Called when a new instance is set. -
despawn
protected void despawn()Called right before an entity is removed -
isOnGround
public boolean isOnGround() -
getEntityMeta
Gets metadata of this entity. You may want to cast it to specific implementation.- Returns:
- metadata of this entity.
-
editEntityMeta
public <TMeta extends EntityMeta> void editEntityMeta(Class<TMeta> metaClass, Consumer<TMeta> editor) Do a batch edit of this entity's metadata. -
teleport
@NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks, @MagicConstant(flagsFromClass=RelativeFlags.class) int flags, boolean shouldConfirm) Teleports the entity only if the chunk atposition
is loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.- Parameters:
position
- the teleport positionchunks
- the chunk indexes to load before teleporting the entity, indexes are fromChunkUtils.getChunkIndex(int, int)
, can be null or empty to only load the chunk atposition
flags
- flags used to teleport the entity relatively rather than absolutely useRelativeFlags
to see available flagsshouldConfirm
- if false, the teleportation will be done without confirmation- Throws:
IllegalStateException
- if you try to teleport an entity before settings its instance
-
teleport
@NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks, @MagicConstant(flagsFromClass=RelativeFlags.class) int flags) -
teleport
-
setView
public void setView(float yaw, float pitch) Changes the view of the entity.- Parameters:
yaw
- the new yawpitch
- the new pitch
-
lookAt
Changes the view of the entity so that it looks in a direction to the given position if it is different from the entity's current position.- Parameters:
point
- the point to look at.
-
lookAt
Changes the view of the entity so that it looks in a direction to the given entity.- Parameters:
entity
- the entity to look at.- Throws:
IllegalArgumentException
- if the entities are not in the same instance
-
isAutoViewable
public boolean isAutoViewable()Gets if this entity is automatically sent to surrounding players. True by default.- Returns:
- true if the entity is automatically viewable for close players, false otherwise
-
setAutoViewable
public void setAutoViewable(boolean autoViewable) Decides if this entity should be auto-viewable by nearby players.- Parameters:
autoViewable
- true to add surrounding players, false to remove- See Also:
-
updateViewableRule
-
updateViewableRule
public void updateViewableRule() -
autoViewEntities
public boolean autoViewEntities()Gets if surrounding entities are automatically visible by this. True by default.- Returns:
- true if surrounding entities are visible by this
-
setAutoViewEntities
public void setAutoViewEntities(boolean autoViewer) Decides if surrounding entities must be visible.- Parameters:
autoViewer
- true to add view surrounding entities, false to remove
-
updateViewerRule
-
updateViewerRule
public void updateViewerRule() -
addViewer
Description copied from interface:Viewable
Adds a viewer. -
removeViewer
Description copied from interface:Viewable
Removes a viewer.- Specified by:
removeViewer
in interfaceViewable
- Parameters:
player
- the viewer to remove- Returns:
- true if the player has been removed, false otherwise (could be because he was not a viewer)
-
updateNewViewer
Called when a new viewer must be shown. Method can be subject to deadlocking if the target's viewers are also accessed.- Parameters:
player
- the player to send the packets to
-
updateOldViewer
Called when a viewer must be destroyed. Method can be subject to deadlocking if the target's viewers are also accessed.- Parameters:
player
- the player to send the packets to
-
getViewers
Description copied from interface:Viewable
Gets all the viewers of this viewable element.- Specified by:
getViewers
in interfaceViewable
- Returns:
- A Set containing all the element's viewers
-
hasPredictableViewers
public boolean hasPredictableViewers()Gets if this entity's viewers (surrounding players) can be predicted from surrounding chunks. -
switchEntityType
Changes the entity type of this entity.Works by changing the internal entity type field and by calling
removeViewer(Player)
followed byaddViewer(Player)
to all current viewers.Be aware that this only change the visual of the entity, the
BoundingBox
will not be modified.- Parameters:
entityType
- the new entity type
-
getAllPermissions
Description copied from interface:PermissionHandler
Returns all permissions associated to this handler. The returned collection should be modified only by subclasses.- Specified by:
getAllPermissions
in interfacePermissionHandler
- Returns:
- the permissions of this handler.
-
tick
public void tick(long time) Updates the entity, called every tick.Ignored if
getInstance()
returns null. -
movementTick
@Internal protected void movementTick() -
getAliveTicks
public long getAliveTicks()Gets the number of ticks this entity has been active for.- Returns:
- the number of ticks this entity has been active for
-
getEntityId
public int getEntityId()Each entity has an unique id (server-wide) which will change after a restart.- Returns:
- the unique entity id
- See Also:
-
getEntityType
Returns the entity type.- Returns:
- the entity type
-
getUuid
Gets the entityUUID
.- Returns:
- the entity unique id
-
isActive
public boolean isActive()Returns false just after instantiation, set to true after callingsetInstance(Instance)
.- Returns:
- true if the entity has been linked to an instance, false otherwise
-
getBoundingBox
Returns the current bounding box (based on pose). Is used to check collision with coordinates or other blocks/entities.- Returns:
- the entity bounding box
-
setBoundingBox
public void setBoundingBox(double width, double height, double depth) 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.
- Parameters:
width
- the bounding box X sizeheight
- the bounding box Y sizedepth
- the bounding box Z size
-
setBoundingBox
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.
- Parameters:
boundingBox
- the new bounding box
-
getChunk
Convenient method to get the entity current chunk.- Returns:
- the entity chunk, can be null even if unlikely
-
refreshCurrentChunk
-
getInstance
Gets the entity current instance.- Returns:
- the entity instance, can be null if the entity doesn't have an instance yet
-
setInstance
public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance, @NotNull @NotNull Pos spawnPosition) Changes the entity instance, i.e. spawns it.- Parameters:
instance
- the new instance of the entityspawnPosition
- the spawn position for the entity.- Returns:
- a
CompletableFuture
called once the entity's instance has been set, this is due to chunks needing to load - Throws:
IllegalStateException
- ifinstance
has not been registered inInstanceManager
-
setInstance
public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance, @NotNull @NotNull Point spawnPosition) -
setInstance
Changes the entity instance.- Parameters:
instance
- the new instance of the entity- Returns:
- a
CompletableFuture
called once the entity's instance has been set, this is due to chunks needing to load - Throws:
NullPointerException
- ifinstance
is nullIllegalStateException
- ifinstance
has not been registered inInstanceManager
-
getVelocity
Gets the entity current velocity.- Returns:
- the entity current velocity
-
setVelocity
Changes the entity velocity and callsEntityVelocityEvent
.The final velocity can be cancelled or modified by the event.
- Parameters:
velocity
- the new entity velocity
-
hasVelocity
public boolean hasVelocity()Gets if the entity currently has a velocity applied.- Returns:
- true if the entity is moving
-
getAerodynamics
Gets the aerodynamics; how the entity behaves in the air.- Returns:
- the aerodynamic properties this entity is using
-
setAerodynamics
Sets the aerodynamics; how the entity behaves in the air.- Parameters:
aerodynamics
- the new aerodynamic properties
-
getGravityTickCount
public int getGravityTickCount()Gets the number of tick this entity has been applied gravity.- Returns:
- the number of tick of which gravity has been consequently applied
-
getDistance
-
getDistance
Gets the distance between two entities.- Parameters:
entity
- the entity to get the distance from- Returns:
- the distance between this and
entity
-
getDistanceSquared
-
getDistanceSquared
Gets the distance squared between two entities.- Parameters:
entity
- the entity to get the distance from- Returns:
- the distance squared between this and
entity
-
getVehicle
Gets the entity vehicle or null.- Returns:
- the entity vehicle, or null if there is not any
-
addPassenger
Adds a new passenger to this entity.- Parameters:
entity
- the new passenger- Throws:
NullPointerException
- ifentity
is nullIllegalStateException
- ifgetInstance()
returns null or the passenger cannot be added
-
removePassenger
Removes a passenger to this entity.- Parameters:
entity
- the passenger to remove- Throws:
NullPointerException
- ifentity
is nullIllegalStateException
- ifgetInstance()
returns null
-
hasPassenger
public boolean hasPassenger()Gets if the entity has any passenger.- Returns:
- true if the entity has any passenger, false otherwise
-
getPassengers
Gets the entity passengers.- Returns:
- an unmodifiable list containing all the entity passengers
-
getPassengersPacket
-
getLeashedEntities
Gets the entities that this entity is leashing.- Returns:
- an unmodifiable list containing all the leashed entities
-
getLeashHolder
Gets the current leash holder.- Returns:
- the entity leashing this entity, null if no leash holder
-
setLeashHolder
Sets the leash holder to this entity.- Parameters:
entity
- the new leash holder
-
getAttachEntityPacket
-
triggerStatus
public void triggerStatus(byte status) Entity statuses can be found here.- Parameters:
status
- the status to trigger
-
isOnFire
public boolean isOnFire()Gets if the entity is on fire.- Returns:
- true if the entity is in fire, false otherwise
-
isSneaking
public boolean isSneaking()Gets if the entity is sneaking.WARNING: this can be bypassed by hacked client, this is only what the client told the server.
- Returns:
- true if the player is sneaking
-
setSneaking
public void setSneaking(boolean sneaking) Makes the entity sneak.WARNING: this will not work for the client itself.
- Parameters:
sneaking
- true to make the entity sneak
-
isSprinting
public boolean isSprinting()Gets if the player is sprinting.WARNING: this can be bypassed by hacked client, this is only what the client told the server.
- Returns:
- true if the player is sprinting
-
setSprinting
public void setSprinting(boolean sprinting) Makes the entity sprint.WARNING: this will not work on the client itself.
- Parameters:
sprinting
- true to make the entity sprint
-
isInvisible
public boolean isInvisible()Gets if the entity is invisible or not.- Returns:
- true if the entity is invisible, false otherwise
-
setInvisible
public void setInvisible(boolean invisible) Changes the internal invisible value and send aEntityMetaDataPacket
to make visible or invisible the entity to its viewers.- Parameters:
invisible
- true to set the entity invisible, false otherwise
-
isGlowing
public boolean isGlowing()Gets if the entity is glowing or not.- Returns:
- true if the entity is glowing, false otherwise
-
setGlowing
public void setGlowing(boolean glowing) Sets or remove the entity glowing effect.- Parameters:
glowing
- true to make the entity glows, false otherwise
-
getPose
Gets the current entity pose.- Returns:
- the entity pose
-
setPose
Changes the entity pose.The internal
crouched
andswimming
field will be updated accordingly.- Parameters:
pose
- the new entity pose
-
updatePose
protected void updatePose() -
getCustomName
Gets the entity custom name.- Returns:
- the custom name of the entity, null if there is not
-
setCustomName
Changes the entity custom name.- Parameters:
customName
- the custom name of the entity, null to remove it
-
isCustomNameVisible
public boolean isCustomNameVisible()Gets the custom name visible metadata field.- Returns:
- true if the custom name is visible, false otherwise
-
setCustomNameVisible
public void setCustomNameVisible(boolean customNameVisible) Changes the internal custom name visible field and send aEntityMetaDataPacket
to update the entity state to its viewers.- Parameters:
customNameVisible
- true to make the custom name visible, false otherwise
-
isSilent
public boolean isSilent() -
setSilent
public void setSilent(boolean silent) -
hasNoGravity
public boolean hasNoGravity()Gets the noGravity metadata field.- Returns:
- true if the entity ignore gravity, false otherwise
-
setNoGravity
public void setNoGravity(boolean noGravity) Changes the noGravity metadata field and change the gravity behaviour accordingly.- Parameters:
noGravity
- should the entity ignore gravity
-
refreshPosition
@Internal public void refreshPosition(@NotNull @NotNull Pos newPosition, boolean ignoreView, boolean sendPackets) Updates internal fields and sends updates.- Parameters:
newPosition
- the new position
-
refreshPosition
-
refreshPosition
-
refreshCoordinate
Used to refresh the entity and its passengers position - put the entity in the right instance chunk - update the viewable chunks (load and unload) - add/remove players from the viewers list ifisAutoViewable()
is enabledWARNING: unsafe, should only be used internally in Minestom. Use
teleport(Pos)
instead.- Parameters:
newPosition
- the new position
-
getPosition
Gets the entity position.- Returns:
- the current position of the entity
-
getPreviousPosition
Gets the previous entity position.- Returns:
- the previous position of the entity
-
getEyeHeight
public double getEyeHeight()Gets the entity eye height.- Returns:
- the entity eye height
-
getActiveEffects
Gets all the potion effect of this entity.- Returns:
- an unmodifiable list of all this entity effects
-
addEffect
Adds an effect to an entity.- Parameters:
potion
- The potion to add
-
removeEffect
Removes effect from entity, if it has it.- Parameters:
effect
- The effect to remove
-
hasEffect
If the entity has the specified effect.- Parameters:
effect
- the effect to check
-
getEffect
Gets the TimedPotion of the specified effect.- Parameters:
effect
- the effect type- Returns:
- the effect, null if not found
-
getEffectLevel
Gets the level of the specified effect.- Parameters:
effect
- the effect type- Returns:
- the effect level, -1 if not found
-
clearEffects
public void clearEffects()Removes all the effects currently applied to the entity. -
remove
public void remove()Removes the entity from the server immediately.WARNING: this does not trigger
EntityDeathEvent
. -
remove
protected void remove(boolean permanent) -
isRemoved
public boolean isRemoved()Gets if this entity has been removed.- Returns:
- true if this entity is removed
-
scheduleRemove
Triggersremove()
after the specified time.- Parameters:
delay
- the time before removing the entity, 0 to cancel the removingtemporalUnit
- the unit of the delay
-
scheduleRemove
Triggersremove()
after the specified time.- Parameters:
delay
- the time before removing the entity
-
getVelocityForPacket
-
getVelocityPacket
-
getMetadataPacket
Gets anEntityMetaDataPacket
sent when adding viewers. Used for synchronization.- Returns:
- The
EntityMetaDataPacket
related to this entity
-
synchronizePosition
@Internal protected void synchronizePosition()Used to synchronize entity position with viewers by sending anEntityTeleportPacket
andEntityHeadLookPacket
to viewers. -
synchronizeNextTick
public void synchronizeNextTick()Asks for a position synchronization to happen during next entity tick. -
getSynchronizationTicks
public long getSynchronizationTicks()Returns the current synchronization interval. The default value isServerFlag.ENTITY_SYNCHRONIZATION_TICKS
but can be overridden per entity withsetSynchronizationTicks(long)
.- Returns:
- The current synchronization ticks
-
setSynchronizationTicks
public void setSynchronizationTicks(long ticks) Set the tick period until this entity's position is synchronized.- Parameters:
ticks
- the new synchronization tick period
-
asHoverEvent
@NotNull public @NotNull HoverEvent<HoverEvent.ShowEntity> asHoverEvent(@NotNull @NotNull UnaryOperator<HoverEvent.ShowEntity> op) - Specified by:
asHoverEvent
in interfaceHoverEventSource<HoverEvent.ShowEntity>
-
tagHandler
- Specified by:
tagHandler
in interfaceTaggable
-
scheduler
- Specified by:
scheduler
in interfaceSchedulable
-
updateSnapshot
Description copied from interface:Snapshotable
Updates the currently cached snapshot if required. The updater can be used to retrieve references to other snapshots while avoiding circular dependency. Be careful to do not storeupdater
anywhere as its data will change when building requested references.This method is not thread-safe, and targeted at internal use since its execution rely on safe-points (e.g. end of ticks)
- Specified by:
updateSnapshot
in interfaceSnapshotable
- Parameters:
updater
- the snapshot updater/context- Returns:
- the updated snapshot
-
eventNode
- Specified by:
eventNode
in interfaceEventHandler<EntityEvent>
-
takeKnockback
public void takeKnockback(float strength, double x, double z) Applies knockback to the entity- 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))
-
getLineOfSight
Gets the line of sight of the entity.- Parameters:
maxDistance
- The max distance to scan- Returns:
- A list of
points
in this entities line of sight
-
hasLineOfSight
Raycasts current entity's eye position to target eye position.- Parameters:
entity
- the entity to be checked.exactView
- if set to TRUE, checks whether target is IN the line of sight of the current one; otherwise checks if the current entity can rotate so that target will be in its line of sight.- Returns:
- true if the ray reaches the target bounding box before hitting a block.
-
hasLineOfSight
- Parameters:
entity
- the entity to be checked.- Returns:
- if the current entity has line of sight to the given one.
- See Also:
-
getLineOfSightEntity
Gets first entity on the line of sight of the current one that matches the given predicate.- Parameters:
range
- max length of the line of sight of the current entity to be checked.predicate
- optional predicate- Returns:
- resulting entity whether there're any, null otherwise.
-
isOccluded
- Specified by:
isOccluded
in interfaceShape
-
intersectBox
public boolean intersectBox(@NotNull @NotNull Point positionRelative, @NotNull @NotNull BoundingBox boundingBox) Description copied from interface:Shape
Checks if two bounding boxes intersect.- Specified by:
intersectBox
in interfaceShape
- Parameters:
positionRelative
- Relative position of bounding box to check withboundingBox
- Bounding box to check for intersections with- Returns:
- is an intersection found
-
intersectBoxSwept
public boolean intersectBoxSwept(@NotNull @NotNull Point rayStart, @NotNull @NotNull Point rayDirection, @NotNull @NotNull Point shapePos, @NotNull @NotNull BoundingBox moving, @NotNull @NotNull SweepResult finalResult) Description copied from interface:Shape
Checks if a moving bounding box will hit this shape.- Specified by:
intersectBoxSwept
in interfaceShape
- Parameters:
rayStart
- Position of the moving shaperayDirection
- Movement vectorshapePos
- Position of this shapemoving
- Bounding Box of moving shapefinalResult
- Stores final SweepResult- Returns:
- is an intersection found
-
relativeStart
Description copied from interface:Shape
Relative Start- Specified by:
relativeStart
in interfaceShape
- Returns:
- Start of shape
-
relativeEnd
Description copied from interface:Shape
Relative End- Specified by:
relativeEnd
in interfaceShape
- Returns:
- End of shape
-
hasEntityCollision
public boolean hasEntityCollision() -
preventBlockPlacement
public boolean preventBlockPlacement() -
updateCollisions
protected void updateCollisions() -
getAcquirable
Deprecated.It's preferred to useAcquirableSource.acquirable()
instead, as it is overridden by subclassesAcquires this entity.- Type Parameters:
T
- the type of object to be acquired- Returns:
- the acquirable for this entity
-
acquirable
Description copied from interface:AcquirableSource
Obtains anAcquirable
. To safely perform operations on this object, the user must callAcquirable.sync(Consumer)
,Acquirable.async(Consumer)
, orAcquirable.lock()
(followed by a subsequent unlock) on the Acquirable instance.- Specified by:
acquirable
in interfaceAcquirableSource<Entity>
- Returns:
- an Acquirable which can be used to synchronize access to this object
-
AcquirableSource.acquirable()
instead, as it is overridden by subclasses