Class in @minecraft/server
Extended by ItemEntity, Player
A mob, item, orb, arrow, cloud or minecart in the world, or a player.
import { Entity } from '@minecraft/server';Example
Section titled “Example”import { world, type Entity } from '@minecraft/server';
const overworld = world.getDimension('overworld');const [player] = world.getAllPlayers();
// Name every zombie within 16 blocks of the first player.if (player) { const zombies: Entity[] = overworld.getEntities({ type: 'minecraft:zombie', location: player.location, maxDistance: 16, }); for (const zombie of zombies) zombie.nameTag = 'Walker';}import { world } from '@minecraft/server';
const overworld = world.getDimension('overworld');const [player] = world.getAllPlayers();
// Name every zombie within 16 blocks of the first player.if (player) { const zombies = overworld.getEntities({ type: 'minecraft:zombie', location: player.location, maxDistance: 16, }); for (const zombie of zombies) zombie.nameTag = 'Walker';}Constructor
Section titled “Constructor”protected constructor();Properties
Section titled “Properties”read-only
readonly id: string;Its unique id for this session.
typeId
Section titled “typeId”read-only
readonly typeId: string;As minecraft:zombie.
isValid
Section titled “isValid”read-only
readonly isValid: boolean;False once it’s gone.
dimension
Section titled “dimension”read-only
readonly dimension: Dimension;The dimension it is in. Basalt has only the overworld.
location
Section titled “location”read-only
readonly location: Vector3;Where it is: a player’s feet, a mob’s feet, an item’s centre.
nameTag
Section titled “nameTag”nameTag: string;The name over its head, "" for none.
localizationKey
Section titled “localizationKey”read-only
readonly localizationKey: string;Its name key in the language files, as entity.zombie.name.
isOnGround
Section titled “isOnGround”read-only
readonly isOnGround: boolean;Whether it stands on something.
isInWater
Section titled “isInWater”read-only
readonly isInWater: boolean;Whether it’s in water. Always false for items, orbs, arrows and clouds.
isFalling
Section titled “isFalling”read-only
readonly isFalling: boolean;Whether it’s in the air and has fallen some way.
fallDistance
Section titled “fallDistance”read-only
readonly fallDistance: number;Blocks fallen since it was last on the ground.
isClimbing
Section titled “isClimbing”read-only
readonly isClimbing: boolean;Whether it’s on a ladder or vine. Only players climb in Basalt.
isSwimming
Section titled “isSwimming”read-only
readonly isSwimming: boolean;Whether it’s swimming. Only players swim in Basalt.
isSneaking
Section titled “isSneaking”read-only
readonly isSneaking: boolean;Whether it’s sneaking. Only players sneak in Basalt.
isSprinting
Section titled “isSprinting”read-only
readonly isSprinting: boolean;Whether it’s sprinting. Only players sprint in Basalt.
scoreboardIdentity
Section titled “scoreboardIdentity”read-only
readonly scoreboardIdentity: ScoreboardIdentity | undefined;Its identity on the scoreboard, once it has a score.
isSleeping
Section titled “isSleeping”read-only
readonly isSleeping: boolean;Whether it’s asleep.
nameplateDepthTested
Section titled “nameplateDepthTested”nameplateDepthTested: boolean;Whether its nameplate is hidden behind blocks.
nameplateRenderDistance
Section titled “nameplateRenderDistance”nameplateRenderDistance: number;How far its nameplate shows, in blocks.
Methods
Section titled “Methods”getHeadLocation
Section titled “getHeadLocation”getHeadLocation(): Vector3;Where its eyes are.
Vector3getComponent
Section titled “getComponent”getComponent<T extends keyof EntityComponentTypeMap>(componentId: T): EntityComponentTypeMap[T] | undefined;getComponent(componentId: string): unknown;One of its components: minecraft:health for mobs and players, minecraft:inventory for
players, minecraft:equippable for players and mobs, minecraft:item for items.
undefined if it has none such.
getComponents
Section titled “getComponents”getComponents(): unknown[];Every component it has.
unknown[]hasComponent
Section titled “hasComponent”hasComponent(componentId: string): boolean;Whether it has the component, as minecraft:health.
componentIdstring
booleanmatches
Section titled “matches”matches(options: EntityQueryOptions & EntityFilterOptions): boolean;Whether it passes these filters, as Dimension.getEntities would pick it.
optionsEntityQueryOptions & EntityFilterOptions
booleangetVelocity
Section titled “getVelocity”getVelocity(): Vector3;How fast it moves, in blocks a tick.
Vector3getRotation
Section titled “getRotation”getRotation(): Vector2;Where it looks: x is the pitch (down positive) and y the yaw, in degrees.
Vector2getViewDirection
Section titled “getViewDirection”getViewDirection(): Vector3;A unit vector along where it looks, as getViewDirection in BDS.
Vector3applyImpulse
Section titled “applyImpulse”applyImpulse(vector: Vector3): void;Adds to its motion.
vectorVector3
clearVelocity
Section titled “clearVelocity”clearVelocity(): void;Stops it moving.
setVelocity
Section titled “setVelocity”setVelocity(velocity: Vector3): void;Sets its motion outright.
velocityVector3
applyKnockback
Section titled “applyKnockback”applyKnockback(horizontalForce: VectorXZ, verticalStrength: number): void;Pushes it: horizontalForce across and verticalStrength up, as a hit’s knockback does.
Its motion is set to the push, not added to it.
horizontalForceVectorXZverticalStrengthnumber
teleport
Section titled “teleport”teleport(location: Vector3, teleportOptions?: TeleportOptions): void;Moves it at once, optionally turning it. A player’s client is held until it arrives, so nothing desyncs.
locationVector3teleportOptionsoptionalTeleportOptions
getTags
Section titled “getTags”getTags(): string[];Its tags, in the order they were added, saved with it. A cloud’s last only as long as it does, since clouds aren’t saved.
string[]hasTag
Section titled “hasTag”hasTag(tag: string): boolean;Whether it has the tag.
tagstring
booleanaddTag
Section titled “addTag”addTag(tag: string): boolean;tagstring
booleanFalse if it had the tag already.removeTag
Section titled “removeTag”removeTag(tag: string): boolean;tagstring
booleanFalse if it didn’t have the tag.getDynamicProperty
Section titled “getDynamicProperty”getDynamicProperty(identifier: string): DynamicPropertyValue | undefined;A dynamic property this plugin set, kept apart from other plugins’ by the manifest’s uuid
and saved with the entity. undefined if it isn’t set.
identifierstring
DynamicPropertyValue | undefinedsetDynamicProperty
Section titled “setDynamicProperty”setDynamicProperty(identifier: string, value?: DynamicPropertyValue): void;Sets a dynamic property, or takes it away with undefined.
identifierstringvalueoptionalDynamicPropertyValue
- If the value isn’t a boolean, finite number, string of at most 32767 bytes or Vector3.
setDynamicProperties
Section titled “setDynamicProperties”setDynamicProperties(values: Record<string, DynamicPropertyValue>): void;Sets several of this plugin’s properties at once; undefined values take them away.
valuesRecord<string, DynamicPropertyValue>
getDynamicPropertyIds
Section titled “getDynamicPropertyIds”getDynamicPropertyIds(): string[];The identifiers of every property this plugin set on it.
string[]getDynamicPropertyTotalByteCount
Section titled “getDynamicPropertyTotalByteCount”getDynamicPropertyTotalByteCount(): number;The bytes this plugin’s properties take, their identifiers and values.
numberclearDynamicProperties
Section titled “clearDynamicProperties”clearDynamicProperties(): void;Takes away every property this plugin set on it.
runCommand
Section titled “runCommand”runCommand(commandString: string): CommandResult;Runs a command with the server’s permission, ~ counting from where the entity is.
commandStringstring
CommandResult- If the command fails or the server hasn’t started.
kill(): boolean;Kills a mob with its death and drops, or takes anything else away.
booleanremove
Section titled “remove”remove(): void;Takes it out of the world with no death and no drops.
addEffect
Section titled “addEffect”addEffect(effectType: EffectType | string, duration: number, options?: EntityEffectOptions): Effect | undefined;Gives or refreshes an effect for duration ticks.
effectTypeEffectType | stringdurationnumberoptionsoptionalEntityEffectOptions
Effect | undefinedgetEffect
Section titled “getEffect”getEffect(effectType: EffectType | string): Effect | undefined;One of its effects, or undefined if it doesn’t have it.
effectTypeEffectType | string
Effect | undefinedgetEffects
Section titled “getEffects”getEffects(): Effect[];Every effect on it.
Effect[]removeEffect
Section titled “removeEffect”removeEffect(effectType: EffectType | string): boolean;effectTypeEffectType | string
booleanWhether it had the effect.addItem
Section titled “addItem”addItem(itemStack: ItemStack): ItemStack | undefined;Drops the item at its feet; returns what didn’t fit.
itemStackItemStack
ItemStack | undefinedapplyDamage
Section titled “applyDamage”applyDamage(amount: number, options?: EntityApplyDamageByProjectileOptions | EntityApplyDamageOptions): boolean;Hurts it, optionally crediting a source.
amountnumberoptionsoptionalEntityApplyDamageByProjectileOptions | EntityApplyDamageOptions
booleansetOnFire
Section titled “setOnFire”setOnFire(seconds: number, useEffects?: boolean): boolean;Sets it on fire for seconds.
secondsnumberuseEffectsoptionalboolean
booleanWhether it took.extinguishFire
Section titled “extinguishFire”extinguishFire(useEffects?: boolean): boolean;Puts its fire out.
useEffectsoptionalboolean
booleanWhether it was burning.lookAt
Section titled “lookAt”lookAt(targetLocation: Vector3): void;Turns it to face a point.
targetLocationVector3
setRotation
Section titled “setRotation”setRotation(rotation: Vector2): void;Sets where it looks: x the pitch, y the yaw, in degrees.
rotationVector2
playAnimation
Section titled “playAnimation”playAnimation(animationName: string, options?: PlayAnimationOptions): void;Plays one of its animations.
animationNamestringoptionsoptionalPlayAnimationOptions
triggerEvent
Section titled “triggerEvent”triggerEvent(eventName: string): void;Fires a data-driven entity event on it, as /event entity.
eventNamestring
tryTeleport
Section titled “tryTeleport”tryTeleport(location: Vector3, teleportOptions?: TeleportOptions): boolean;Like teleport, but returns false instead of throwing when it can’t.
locationVector3teleportOptionsoptionalTeleportOptions
booleangetProperty
Section titled “getProperty”getProperty(identifier: string): boolean | number | string | undefined;An entity property from its definition; undefined if it has none such.
identifierstring
boolean | number | string | undefinedsetProperty
Section titled “setProperty”setProperty(identifier: string, value: boolean | number | string): void;Sets an entity property defined on its type.
identifierstringvalueboolean | number | string
resetProperty
Section titled “resetProperty”resetProperty(identifier: string): boolean | number | string;Puts an entity property back to its default.
identifierstring
boolean | number | stringThe default.getBlockFromViewDirection
Section titled “getBlockFromViewDirection”getBlockFromViewDirection(options?: BlockRaycastOptions): BlockRaycastHit | undefined;The first block its view line hits, as a raycast from its eyes.
optionsoptionalBlockRaycastOptions
BlockRaycastHit | undefinedgetEntitiesFromViewDirection
Section titled “getEntitiesFromViewDirection”getEntitiesFromViewDirection(options?: EntityRaycastOptions): EntityRaycastHit[];The entities its view line crosses, nearest first.
optionsoptionalEntityRaycastOptions
EntityRaycastHit[]getBlockStandingOn
Section titled “getBlockStandingOn”getBlockStandingOn(options?: GetBlocksStandingOnOptions): Block | undefined;The block it stands on, or undefined if none.
optionsoptionalGetBlocksStandingOnOptions
Block | undefinedgetAllBlocksStandingOn
Section titled “getAllBlocksStandingOn”getAllBlocksStandingOn(options?: GetBlocksStandingOnOptions): Block[];Every block it stands on.
optionsoptionalGetBlocksStandingOnOptions
Block[]getAABB
Section titled “getAABB”getAABB(): AABB;Its bounding box in world space.
AABBUsed by
Section titled “Used by”EntityDamageSource.damagingEntity, EntityHealthComponent.entity, EntityEquippableComponent.entity, EntityRideableComponent.entity, EntityRideableComponent.addRider, EntityRideableComponent.ejectRider, EntityRideableComponent.getRiders, EntityRidingComponent.entity, EntityRidingComponent.entityRidingOn, Player.setPropertyOverrideForEntity, Player.removePropertyOverrideForEntity, Player.clearPropertyOverridesForEntity, ExplosionOptions.source, Dimension.getEntities, Dimension.spawnEntity, Dimension.getEntitiesAtBlockLocation, ScoreboardIdentity.getEntity, EntityHurtAfterEvent.hurtEntity, EntityHurtBeforeEvent.hurtEntity, EntityDieAfterEvent.deadEntity, EntitySpawnAfterEvent.entity, PlayerInteractWithEntityAfterEvent.target, BlockExplodeAfterEvent.source, EntityDieBeforeEvent.deadEntity and 69 more