JSPrismarine
    Preparing search index...

    The base class for all entities including Player.

    Hierarchy (View Summary)

    Index

    Constructors

    • Entity constructor.

      Parameters

      • options: Omit<
            {
                headYaw?: number;
                pitch?: number;
                runtimeId: bigint;
                server: Server;
                uuid?: string;
                world: World;
                yaw?: number;
            },
            "runtimeId",
        >

        The entity options.

        • world

          The world the entity belongs to.

        • server

          The server instance.

        • uuid

          The entity's UUID.

      Returns Hoglin

      The entity instance.

      const entity = new Entity({
      world: server.getWorldManager().getDefaultWorld(),
      server
      });

    Properties

    attributes: Attributes = ...

    Entity attributes.

    headYaw: number
    metadata: Metadata = ...

    Entity metadata.

    pitch: number
    runtimeId: bigint
    server: Server
    uuid: string
    x: number = 0

    The X coordinate.

    y: number

    The Y coordinate.

    yaw: number
    z: number = 0

    The Z coordinate.

    MOB_ID: string = 'minecraft:hoglin'

    The entity's namespace ID.

    runtimeIdCount: bigint = 0n

    The global runtime id counter.

    Accessors

    Methods

    • Get the entity's formatted name.

      Returns string

      The entity's formatted name (including prefix & suffix).

      const formattedName = entity.getFormattedUsername();
      console.log(`Entity formatted name: ${formattedName}`); // Entity formatted name: Sheep
    • Get the entity's (potentially custom) name.

      Returns string

      The entity's name without formatting (usually prefix & suffix).

      const name = entity.getName();
      console.log(`Entity name: ${name}`);
    • Check if the entity is a console instance.

      Returns boolean

      true if the entity is console-controlled, otherwise false.

      if (entity.isConsole()) {
      console.log('Entity is a console');
      } else {
      console.log('Entity is not a console');
      }
    • Check if the entity is a player.

      Returns boolean

      true if the entity is player-controlled, otherwise false.

      if (entity.isPlayer()) {
      console.log('Entity is a player');
      } else {
      console.log('Entity is not a player');
      }
    • Send a message to an entity.

      Parameters

      • message: string

        The message.

      • Optionaltype: TextType = TextType.Raw

        The text type.

      Returns void

      This will silently fail on non-client-controlled entities.

      entity.sendMessage('Hello World!');
      
    • Set the entity's position and notify the clients.

      Parameters

      • options: { headYaw?: number; pitch?: number; position: Vector3; yaw?: number }

        The position options.

        • OptionalheadYaw?: number

          The head yaw.

        • Optionalpitch?: number

          The pitch.

        • position: Vector3

          The position.

        • Optionalyaw?: number

          The yaw.

      Returns Promise<void>

      A promise that resolves when the position is set.

    • Set the x position.

      Parameters

      • x: number

        The x coordinate.

      • Optionalsuppress: boolean = false

        If true, the client won't be notified about the position change.

      Returns Promise<void>

      A promise that resolves when the x position is set.

      await entity.setX(10);
      

      This method will also send the position update to the client if suppress is false.

    • Set the y position.

      Parameters

      • y: number

        The y coordinate.

      • Optionalsuppress: boolean = false

        If true, the client won't be notified about the position change.

      Returns Promise<void>

      A promise that resolves when the y position is set.

      await entity.setY(10);
      

      This method will also send the position update to the client if suppress is false.

    • Set the z position.

      Parameters

      • z: number

        The z coordinate.

      • Optionalsuppress: boolean = false

        If true, the client won't be notified about the position change.

      Returns Promise<void>

      A promise that resolves when the z position is set.

      await entity.setZ(10);
      

      This method will also send the position update to the client if suppress is false.

    • Fired every tick from the event subscription in the constructor.

      Parameters

      • _tick: number

        The current world-tick.

      Returns Promise<void>

      A promise that resolves when the update is complete.

      entity.update(10);
      
    • Creates a new Vector3 instance from an object with x, y, and z properties.

      Parameters

      • obj: { x: number; y: number; z: number }

        The object containing x, y, and z properties.

      Returns Vector3

      A new Vector3 instance.