Namespace Entity

Module used to manipulate entities (mobs, drop, arrows, etc.) in the world. Every entity has it's unique numeric ID which is often used across this module as the first function parameter.

Functions

  • Adds an effect to entity.

    Parameters

    • entityUid: number
    • effectId: number

      effect ID, should be one one of EPotionEffect values

    • effectData: number

      effect amplifier

    • effectTime: number

      effect time in ticks

    • Optionalambience: boolean

      if true, particles are ambient

    • Optionalparticles: boolean

      if true, particles are not displayed

    Returns void

  • Adds an effect to entity.

    Parameters

    • entityUid: number
    • effectId: number

      effect ID, should be one one of EPotionEffect values

    • effectData: number

      effect amplifier

    • effectTime: number

      effect time in ticks

    • ambience: boolean

      if true, particles are ambient

    • particles: boolean

      if true, particles are not displayed

    • effectAnimation: boolean

      if true, flashing are displayed

    Returns void

    2.3.1b116

  • Updates current entity position by specified coordinates.

    Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns void

  • Updates current entity's velocity by specified value.

    Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns void

  • Clears effect, applied to the mob.

    Parameters

    • entityUid: number
    • id: number

      effect ID, should be one of the EPotionEffect

    Returns void

  • Clears all effects of the mob.

    Parameters

    • entityUid: number

    Returns void

  • Damages entity.

    Parameters

    • entityUid: number
    • damage: number

      damage value in half-hearts

    • Optionalcause: number

      existing DamageSource or any inclusive value between 25 and 32

    • Optionalproperties: {
          attacker?: number;
          bool1?: boolean;
      }

      additional damage source properties

      • Optionalattacker?: number

        Entity that caused damage, determines actor of damage source.

      • Optionalbool1?: boolean

        If true, damage can be reduced by armor.

    Returns void

  • Retrieves nearest to the coordinates entity of the specified entity type.

    Parameters

    • coords: Vector

      search range center coordinates

    • Optionaltype: number

      entity type ID. Parameter is no longer supported and should be 0 in all cases

    • OptionalmaxRange: number

      if specified, determines search radius

    Returns Nullable<number>

    Overheating method, capture entities by BlockSource.fetchEntitiesInAABB
    and pass over them by checking radius between coords and entity.

  • Parameters

    • entityUid: number

    Returns number

    Use attributes instead.

  • Returns number[]

    An array of all server entities UIDs.

  • Returns array of all entities numeric IDs in given range in blocks.

    Parameters

    • coords: Vector

      search range center coordinates

    • maxRange: number

      determines search radius

    • Optionaltype: number

      entity type ID

    Returns number[]

    Overheating method, capture entities by BlockSource.fetchEntitiesInAABB
    and pass over them by checking radius between coords and entity.

  • Returns array of all entities numeric IDs in given range in blocks.

    Parameters

    • coords1: Vector

      start search range coordinates

    • coords2: Vector

      end search range coordinates

    • Optionaltype: number

      entity type ID

    • Optionalflag: boolean

    Returns number[]

    type: 255, flag: true
    

    2.0.4b35

    Local method, use BlockSource.listEntitiesInAABB instead.

  • Returns number[]

    An array of all server entities UIDs.

    Consider using Entity.getAll instead.

  • Returns number[]

    An array of all client entities UIDs.

    2.4.0b120

  • Creates an object used to change entity's attributes.

    Parameters

    • entityUid: number

      entity uid

    • attribute: string

      one of Attribute or your custom one

    Returns AttributeInstance

    Object used to manipulate entity's attributes.

    2.0.3b33

  • Parameters

    • entityUid: number

    Returns CustomEntity

    Custom entity object by it's numeric entity UID.

    Not supported anymore, use behavior packs.

  • Parameters

    • entityUid: number

    Returns number

    Current dimension numeric ID, one of the EDimension values or custom dimension ID.

    2.0.4b35

  • Parameters

    Returns number

    Distance in blocks between the two coordinate sets.

  • Parameters

    • entityUid: number
    • coords: Vector

    Returns number

    Distance between specified entity and a fixed coordinate set.

  • Parameters

    • ent1: number
    • ent2: number

    Returns number

    Distance in blocks between two entities.

  • Parameters

    • entity: number
    • effectId: number

    Returns EffectInstance

    Object with duration and level of the potion effect with given numeric ID on the given entity. These fields are set to 0, if the given effect doesn't affect the given entity at the moment.

    2.2.1b102

  • Parameters

    • entityUid: number
    • name: string

    Returns null

    Use attributes instead, or Saver.

  • Parameters

    • entityUid: number
    • name: string

    Returns object

    Use attributes instead, or Saver.

  • Parameters

    • entityUid: number

    Returns number

    Entity's current health value.

  • Parameters

    • entityUid: number
    • OptionalhandleNames: boolean
    • OptionalhandleEnchant: boolean

    Returns void

    Consider use Entity.getCarriedItem instead.

  • Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns LookAngle

    Look angle between entity and static coordinates.

  • Parameters

    • entityUid: number

    Returns number

    Entity's maximum health value.

  • Parameters

    • entityUid: number

    Returns boolean

    true, if entity was immobilized.

    2.3.1b116-3

  • Retrieves entity look angle in the form of pitch/yaw angle. No other information included to the resulting object.

    Parameters

    • entityUid: number

    Returns LookAngle

  • Parameters

    • pos1: any
    • pos2: any

    Returns undefined

    Nothing to perform here anymore.

  • Retrieves entity's current movement information.

    Parameters

    • entityUid: number

    Returns MovingVector

    Object that contains normalized moving vector, moving speed and moving xz speed (with no Y coordinate).

  • Parameters

    • entityUid: number

    Returns string

    Entity name tag or player name.

    2.2.1b97 (not working before)

  • Parameters

    • entityUid: number

    Returns number

    Entity render type, should be one of the EMobRenderType values.

    Use resource packs instead.

  • Parameters

    • entityUid: number

    Returns number

    Entity that is riding the specified entity.

  • Parameters

    • entityUid: number

    Returns number

    Entity that is ridden by specified entity.

  • Parameters

    • entityUid: number

    Returns string

    Use NBT instead.

  • Parameters

    • entityUid: number

    Returns boolean

    true if entity is sneaking, false otherwise.

  • Gets the attack target of current entity.

    Parameters

    • entityUid: number

    Returns number

    Target entity's unique ID.

  • Parameters

    • entityUid: number

    Returns number

    Numeric entity type, one of the EEntityType.

  • Parameters

    • entityUid: number

    Returns string

    String entity type, like minecraft:chicken<> (<namespace>:<identifier>[<attributes>]).

  • Parameters

    • entityUid: number

    Returns number | string

    String type for entities defined via add-ons or numeric type for all the other entities.

  • Get current entity's velocity using velocity vector.

    Parameters

    • entityUid: number

    Returns Vector

    Containing current entity's velocity.

  • Parameters

    • entityUid: number

    Returns number

    Distance between player and entity, counting only x and z values (y value is ignored).

  • Parameters

    • entity: number
    • effectId: number

      numeric ID of the potion effect, one of EPotionEffect values

    Returns boolean

    Whether the given entity is affected by the potion effect with given numeric ID.

    2.2.1b102

  • Adds specified health amount to the entity.

    Parameters

    • entityUid: number
    • heal: number

      health to be added to entity, in half-hearts

    Returns void

  • Parameters

    • entityUid: number

    Returns boolean

    true if specified entity is loaded within any player chunks (not despawned or unloaded) and identifier is valid.

  • Sets entity look angle to look at specified coordinates.

    Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns void

  • Makes entity move using pitch/yaw angle to determine direction.

    Parameters

    • entityUid: number
    • angle: LookAngle

      angle to define entity's direction

    • params: MoveParams

      additional move parameters

    Returns void

  • Makes entity move towards it's current look angle.

    Parameters

    • entityUid: number
    • params: MoveParams

      additional move parameters

    Returns void

  • Makes entity move to the target coordinates.

    Parameters

    Returns void

  • Parameters

    • entityUid: number
    • name: string
    • Optionalextra: object

    Returns void

    Use attributes instead, or Saver.

  • Parameters

    • entityUid: number
    • name: string
    • obj: object

    Returns void

    Use attributes instead, or Saver.

  • Removes entity from the world.

    Parameters

    • entityUid: number

    Returns void

  • Makes rider ride entity.

    Parameters

    • entityUid: number

      ridden entity

    • riderUid: number

      rider entity

    Returns void

  • Parameters

    • entityUid: number
    • age: number

    Returns void

    Use attributes instead.

  • Sets armor slot contents for the entity.

    Parameters

    • entityUid: number
    • slot: number

      armor slot index, should be one of the EArmorType values

    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • Optionalextra: ItemExtraData

      item extra

    Returns void

  • Sets current carried item for the entity.

    Parameters

    • entityUid: number
    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • Optionalextra: ItemExtraData

      item extra

    Returns void

  • Sets compound tag for the specified entity.

    Parameters

    Returns void

    2.0.5b44

  • Sets item to the specified drop entity

    Parameters

    • entityUid: number
    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • Optionalextra: ItemExtraData

      item extra

    Returns void

  • Puts entity on fire.

    Parameters

    • entityUid: number
    • fire: number

      duration (in ticks) of the fire

    • force: boolean

      should always be true

    Returns void

  • Sets entity's current health value.

    Parameters

    • entityUid: number
    • health: number

      health value to be set

    Returns void

  • Sets hitbox to the entity. Hitboxes defines entity collisions between terrain and themselves (e.g. physics).

    Parameters

    • entityUid: number
    • w: number

      hitbox width and length

    • h: number

      hitbox height

    Returns void

  • Sets specified pitch and yaw as look angle for the entity.

    Parameters

    • entityUid: number
    • yaw: number

      look angle yaw in radians

    • pitch: number

      look angle pitch in radians

    Returns void

  • Sets entity's maximum health value.

    Parameters

    • entityUid: number
    • health: number

    Returns void

  • Sets entity's immobile state.

    Parameters

    • entityUid: number
    • mobile: boolean

      if true, entity can move, otherwise it is immobilized

    Returns void

  • Sets custom entity name tag. Custom entity tags are displayed above the entities and can be set by player using label.

    Parameters

    • entityUid: number
    • tag: string

      name tag to be set to the entity

    Returns void

  • Sets current offhand item for the entity.

    Parameters

    • entityUid: number
    • id: number

      item ID

    • count: number

      item count

    • data: number

      item data

    • Optionalextra: ItemExtraData

      item extra

    Returns void

    2.2.1b93 (not working before)

  • Sets the specified coordinates as a new position for the entity. No checks are performed.

    Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns void

  • Sets entity render type.

    Parameters

    • entityUid: number
    • render: number

      entity render type, should be one of the EMobRenderType values

    Returns void

    Use resource packs instead.

  • Sets mob skin.

    Parameters

    • entityUid: number
    • skin: string

      skin name, full path in the resourcepack (mod assets)

    Returns void

    Use NBT or resource packs instead.

  • Sets entity's sneaking state, supported slightly entities, resource pack render controlling it.

    Parameters

    • entityUid: number
    • sneak: boolean

      if true, entity becomes sneaking, else not

    Returns void

  • Sets the attack target for current entity. Works only for mobs that actually can attack.

    Parameters

    • entityUid: number
    • targetUid: number

      target entity's unique ID

    Returns void

  • Sets mob skin, uses Texture object.

    Parameters

    Returns void

    Use NBT or resource packs instead.

  • Set current entity's velocity using velocity vector.

    Parameters

    • entityUid: number
    • x: number
    • y: number
    • z: number

    Returns void

  • Spawns vanilla entity on the specified coordinates.

    Parameters

    • x: number
    • y: number
    • z: number
    • type: number

      numeric entity type, one of the EEntityType

    • Optionalskin: string

      skin to set for the entity. Leave empty or null to use default skin of the mob

    Returns number

    Numeric ID of spawn entity or -1 if entity was not created.

    Client-side method, use BlockSource.spawnEntity instead.

  • Spawns custom entity defined in behavior packs or game itself.

    Parameters

    • x: number
    • y: number
    • z: number
    • name: string

    Returns AddonEntity

    Instance to performing commands on entity.

    Client-side method, use BlockSource.spawnEntity instead.

  • Spawns custom entity on the specified coords. Allows to pass some values to controllers via extra param.

    Parameters

    • name: string

      custom entity string ID

    • x: number
    • y: number
    • z: number
    • Optionalextra: object

      object that contains some data for the controllers

    Returns CustomEntity

    You are should implement addon entity and spawn it with BlockSource.spawnEntity instead.

Type Aliases

Attribute:
    | "minecraft:follow_range"
    | "minecraft:luck"
    | "minecraft:lava_movement"
    | "minecraft:underwater_movement"
    | "minecraft:movement"
    | "minecraft:knockback_resistance"
    | "minecraft:absorption"
    | "minecraft:health"
    | "minecraft:attack_damage"
    | "minecraft:jump_strength"
DamageSource: number

Damage sources, which are used to determine entity damage type:

Type Name Message Translation
0 Generic "death.attack.generic" (fallback damage source) * died
1 Cactus "death.attack.cactus" (only when standing on cactus) * was pricked to death
2 Mob "death.attack.mob" * was slain by *
3 Impact n/a
4 In Wall "death.attack.inWall" * suffocated in a wall
5 Fall "death.attack.fall" OR "death.fell.accident.generic" * hit the ground too hard OR * fell from a high place
6 In Fire "death.attack.inFire" * went up in flames
7 On Fire "death.attack.onFire" * burned to death
8 Lava "death.attack.lava" * tried to swim in lava
9 Drown "death.attack.drown" * drowned
10 Explosion "death.attack.explosion" * blew up
11 Explosion (Player) "death.attack.explosion" * was blown up by *
12 Out Of World "death.attack.outOfWorld" * fell out of the world
13 Command n/a
14 Magic "death.attack.magic" * was killed by magic
15 Wither "death.attack.wither" * withered away
16 Starve "death.attack.starve" * starved to death
17 Anvil "death.attack.anvil" * was squashed by a falling anvil
18 Thorns "death.attack.thorns" * was killed trying to hurt *
19 Projectile n/a
20 Falling Block "death.attack.fallingBlock" * was squashed by a falling block
21 Fly Into Wall "death.attack.flyIntoWall" * experienced kinetic energy
22 Magma "death.attack.magma" * discovered floor was lava
23 Fireworks "death.attack.fireworks" * went off with a bang
24 Lightning Bolt "death.attack.lightningBolt" * was struck by lightning
PathNavigationResultCode:
    | 0
    | 1
    | 2
    | 3
    | 4
    | 5
    | 6

Path navigation result, which is used in result callback:

Result code Meaning
0 Path successfully completed
1 Cannot reach target, no available path
2 Cannot reach target, out of range
3 Entity has been unloaded or removed
4 Cancelled by stop() or similar method
5 Player left level or server closed
6 Result function will be replaced

Copyright © 2024 Nernar. Copyright © 2020 #mineprogramming. Built with ❤ and TypeDoc.