Class Entity
- All Implemented Interfaces:
Sound.Emitter,HoverEventSource<HoverEvent.ShowEntity>,Shape,EventHandler<EntityEvent>,PermissionHandler,Snapshotable,Taggable,TagReadable,TagWritable,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 BoundingBoxprotected Chunkprotected EntityMetaprotected EntityTypeprotected intprotected booleanprotected booleanprotected Instanceprotected Posprotected booleanprotected Metadataprotected booleanprotected Posprotected Posprotected booleanprotected final EntityTracker.Update<Entity> protected UUIDprotected Entityprotected Vecprotected final net.minestom.server.entity.EntityView -
Constructor Summary
ConstructorsConstructorDescriptionEntity(@NotNull EntityType entityType) Entity(@NotNull EntityType entityType, @NotNull UUID uuid) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an effect to an entity.voidaddPassenger(@NotNull Entity entity) Adds a new passenger to this entity.final booleanAdds a viewer.@NotNull HoverEvent<HoverEvent.ShowEntity> asHoverEvent(@NotNull UnaryOperator<HoverEvent.ShowEntity> op) booleanGets if surrounding entities are automatically visible by this.voidRemoves all the effects currently applied to the entity.protected voiddespawn()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 intGenerate and return a new unique entity id.<T extends Entity>
@NotNull Acquirable<T> @NotNull List<@NotNull TimedPotion> Gets all the potion effect of this entity.@NotNull AerodynamicsGets the aerodynamics; how the entity behaves in the air.longGets the number of ticks this entity has been active for.@NotNull Set<Permission> Returns all permissions associated to this handler.protected @NotNull AttachEntityPacket@NotNull BoundingBoxReturns the current bounding box (based on pose).@Nullable ChunkgetChunk()Convenient method to get the entity current chunk.@Nullable ComponentGets the entity custom name.doublegetDistance(@NotNull Point point) doublegetDistance(@NotNull Entity entity) Gets the distance between two entities.doublegetDistanceSquared(@NotNull Point point) doublegetDistanceSquared(@NotNull Entity entity) Gets the distance squared between two entities.@Nullable TimedPotiongetEffect(@NotNull PotionEffect effect) Gets the TimedPotion of the specified effect.intgetEffectLevel(@NotNull PotionEffect effect) Gets the level of the specified effect.static @Nullable EntitygetEntity(int id) Gets an entity based on its id (fromgetEntityId()).static @Nullable EntityGets an entity based on its UUID (fromgetUuid()).intEach entity has an unique id (server-wide) which will change after a restart.@NotNull EntityMetaGets metadata of this entity.@NotNull EntityTypeReturns the entity type.doubleGets the entity eye height.intGets the number of tick this entity has been applied gravity.@UnknownNullability InstanceGets the entity current instance.Gets the entities that this entity is leashing.@Nullable EntityGets the current leash holder.getLineOfSight(int maxDistance) Gets the line of sight of the entity.@Nullable EntitygetLineOfSightEntity(double range, Predicate<Entity> predicate) Gets first entity on the line of sight of the current one that matches the given predicate.@NotNull EntityMetaDataPacketGets anEntityMetaDataPacketsent when adding viewers.Gets the entity passengers.protected @NotNull SetPassengersPacket@NotNull Entity.PosegetPose()Gets the current entity pose.@NotNull PosGets the entity position.@NotNull PosGets the previous entity position.longReturns the current synchronization interval.@NotNull UUIDgetUuid()Gets the entityUUID.@Nullable EntityGets the entity vehicle or null.@NotNull VecGets the entity current velocity.protected @NotNull Vecprotected @NotNull EntityVelocityPacketGets all the viewers of this viewable element.booleanbooleanhasEffect(@NotNull PotionEffect effect) If the entity has the specified effect.booleanhasLineOfSight(Entity entity) booleanhasLineOfSight(Entity entity, boolean exactView) Raycasts current entity's eye position to target eye position.booleanGets the noGravity metadata field.booleanGets if the entity has any passenger.booleanGets if this entity's viewers (surrounding players) can be predicted from surrounding chunks.booleanGets if the entity currently has a velocity applied.booleanintersectBox(@NotNull Point positionRelative, @NotNull BoundingBox boundingBox) Checks if two bounding boxes intersect.booleanintersectBoxSwept(@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.booleanisActive()Returns false just after instantiation, set to true after callingsetInstance(Instance).booleanGets if this entity is automatically sent to surrounding players.booleanGets the custom name visible metadata field.booleanGets if the entity is glowing or not.booleanGets if the entity is invisible or not.booleanisOccluded(@NotNull Shape shape, @NotNull BlockFace face) booleanisOnFire()Gets if the entity is on fire.booleanbooleanGets if this entity has been removed.booleanisSilent()booleanGets if the entity is sneaking.booleanGets if the player is sprinting.voidChanges 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.voidChanges the view of the entity so that it looks in a direction to the given entity.protected voidprotected voidrefreshCoordinate(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 voidrefreshCurrentChunk(Chunk currentChunk) voidrefreshPosition(@NotNull Pos newPosition) voidrefreshPosition(@NotNull Pos newPosition, boolean ignoreView) voidrefreshPosition(@NotNull Pos newPosition, boolean ignoreView, boolean sendPackets) Updates internal fields and sends updates.@NotNull PointRelative End@NotNull PointRelative Startvoidremove()Removes the entity from the server immediately.protected voidremove(boolean permanent) voidremoveEffect(@NotNull PotionEffect effect) Removes effect from entity, if it has it.voidremovePassenger(@NotNull Entity entity) Removes a passenger to this entity.final booleanremoveViewer(@NotNull Player player) Removes a viewer.voidscheduleNextTick(@NotNull Consumer<Entity> callback) Schedules a task to be run during the next entity tick.@NotNull SchedulervoidscheduleRemove(long delay, @NotNull TemporalUnit temporalUnit) Triggersremove()after the specified time.voidscheduleRemove(Duration delay) Triggersremove()after the specified time.voidsetAerodynamics(@NotNull Aerodynamics aerodynamics) Sets the aerodynamics; how the entity behaves in the air.voidsetAutoViewable(boolean autoViewable) Decides if this entity should be auto-viewable by nearby players.voidsetAutoViewEntities(boolean autoViewer) Decides if surrounding entities must be visible.voidsetBoundingBox(double width, double height, double depth) Changes the internal entity standing bounding box.voidsetBoundingBox(BoundingBox boundingBox) Changes the internal entity standing bounding box.voidsetCustomName(@Nullable Component customName) Changes the entity custom name.voidsetCustomNameVisible(boolean customNameVisible) Changes the internal custom name visible field and send aEntityMetaDataPacketto update the entity state to its viewers.voidsetGlowing(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.voidsetInvisible(boolean invisible) Changes the internal invisible value and send aEntityMetaDataPacketto make visible or invisible the entity to its viewers.voidsetLeashHolder(@Nullable Entity entity) Sets the leash holder to this entity.voidsetNoGravity(boolean noGravity) Changes the noGravity metadata field and change the gravity behaviour accordingly.voidsetOnFire(boolean fire) Sets the entity in fire visually.voidsetPose(@NotNull Entity.Pose pose) Changes the entity pose.voidsetSilent(boolean silent) voidsetSneaking(boolean sneaking) Makes the entity sneak.voidsetSprinting(boolean sprinting) Makes the entity sprint.voidsetSynchronizationTicks(long ticks) Set the tick period until this entity's position is synchronized.voidChanges the internal entity UUID, mostly unsafe.voidsetVelocity(@NotNull Vec velocity) Changes the entity velocity and callsEntityVelocityEvent.voidsetView(float yaw, float pitch) Changes the view of the entity.voidspawn()Called when a new instance is set.voidswitchEntityType(@NotNull EntityType entityType) Changes the entity type of this entity.voidAsks for a position synchronization to happen during next entity tick.protected voidUsed to synchronize entity position with viewers by sending anEntityTeleportPacketandEntityHeadLookPacketto viewers.@NotNull TagHandlervoidtakeKnockback(float strength, double x, double z) Applies knockback to the entity@NotNull CompletableFuture<Void> @NotNull CompletableFuture<Void> Teleports the entity only if the chunk atpositionis loaded or ifInstance.hasEnabledAutoChunkLoad()returns true.voidtick(long time) Updates the entity, called every tick.voidtriggerStatus(byte status) Entity statuses can be found here.voidupdate(long time) Called each tick.voidupdateNewViewer(@NotNull Player player) Called when a new viewer must be shown.voidupdateOldViewer(@NotNull Player player) Called when a viewer must be destroyed.protected void@NotNull EntitySnapshotupdateSnapshot(@NotNull SnapshotUpdater updater) Updates the currently cached snapshot if required.voidvoidupdateViewableRule(@Nullable Predicate<Player> predicate) voidvoidupdateViewerRule(@Nullable Predicate<Entity> predicate) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
-
instance
-
currentChunk
-
position
-
previousPosition
-
lastSyncedPosition
-
onGround
protected boolean onGround -
boundingBox
-
vehicle
-
velocity
-
lastVelocityWasZero
protected boolean lastVelocityWasZero -
hasPhysics
protected boolean hasPhysics -
hasCollision
protected boolean hasCollision -
gravityTickCount
protected int gravityTickCount -
trackingUpdate
-
viewEngine
protected final net.minestom.server.entity.EntityView viewEngine -
viewers
-
uuid
-
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
-
getEntity
Gets an entity based on its id (fromgetEntityId()).Entity id are unique server-wide.
- Parameters:
id- the entity unique id- Returns:
- the entity having the specified id, null if not found
-
getEntity
Gets an entity based on its UUID (fromgetUuid()).- Parameters:
uuid- the entity UUID- Returns:
- the entity having the specified uuid, null if not found
-
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) Teleports the entity only if the chunk atpositionis 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 atpositionflags- flags used to teleport the entity relatively rather than absolutely useRelativeFlagsto see available flags- Throws:
IllegalStateException- if you try to teleport an entity before settings its instance
-
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
@Experimental public void updateViewableRule() -
autoViewEntities
@Experimental 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
@Experimental 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
@Experimental public void updateViewerRule() -
addViewer
Description copied from interface:ViewableAdds a viewer. -
removeViewer
Description copied from interface:ViewableRemoves a viewer.- Specified by:
removeViewerin 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:ViewableGets all the viewers of this viewable element.- Specified by:
getViewersin 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
BoundingBoxwill not be modified.- Parameters:
entityType- the new entity type
-
getAllPermissions
Description copied from interface:PermissionHandlerReturns all permissions associated to this handler. The returned collection should be modified only by subclasses.- Specified by:
getAllPermissionsin 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
-
setUuid
Changes the internal entity UUID, mostly unsafe.- Parameters:
uuid- the new entity uuid
-
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
CompletableFuturecalled once the entity's instance has been set, this is due to chunks needing to load - Throws:
IllegalStateException- ifinstancehas 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
CompletableFuturecalled once the entity's instance has been set, this is due to chunks needing to load - Throws:
NullPointerException- ifinstanceis nullIllegalStateException- ifinstancehas 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- ifentityis 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- ifentityis 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
-
setOnFire
public void setOnFire(boolean fire) Sets the entity in fire visually.WARNING: if you want to apply damage or specify a duration, see
LivingEntity.setFireForDuration(int, TemporalUnit).- Parameters:
fire- should the entity be set in fire
-
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 aEntityMetaDataPacketto 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
crouchedandswimmingfield 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 aEntityMetaDataPacketto 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.Default to
BoundingBox.height()x0.85- 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, 0 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 anEntityMetaDataPacketsent when adding viewers. Used for synchronization.- Returns:
- The
EntityMetaDataPacketrelated to this entity
-
synchronizePosition
@Internal protected void synchronizePosition()Used to synchronize entity position with viewers by sending anEntityTeleportPacketandEntityHeadLookPacketto 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_TICKSbut 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:
asHoverEventin interfaceHoverEventSource<HoverEvent.ShowEntity>
-
getAcquirable
-
tagHandler
- Specified by:
tagHandlerin interfaceTaggable
-
scheduler
- Specified by:
schedulerin interfaceSchedulable
-
updateSnapshot
Description copied from interface:SnapshotableUpdates 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 storeupdateranywhere 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:
updateSnapshotin interfaceSnapshotable- Parameters:
updater- the snapshot updater/context- Returns:
- the updated snapshot
-
eventNode
- Specified by:
eventNodein 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
pointsin 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:
isOccludedin interfaceShape
-
intersectBox
public boolean intersectBox(@NotNull @NotNull Point positionRelative, @NotNull @NotNull BoundingBox boundingBox) Description copied from interface:ShapeChecks if two bounding boxes intersect.- Specified by:
intersectBoxin 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:ShapeChecks if a moving bounding box will hit this shape.- Specified by:
intersectBoxSweptin 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:ShapeRelative Start- Specified by:
relativeStartin interfaceShape- Returns:
- Start of shape
-
relativeEnd
Description copied from interface:ShapeRelative End- Specified by:
relativeEndin interfaceShape- Returns:
- End of shape
-
hasCollision
public boolean hasCollision()
-