UNPKG

@jsprismarine/prismarine

Version:

Dedicated Minecraft Bedrock Edition server written in TypeScript

306 lines • 10.1 kB
import { Vector3 } from '../../../math/src/index.ts'; import { default as Player } from '../Player'; import { default as Server } from '../Server'; import { default as TextType } from '../network/type/TextType'; import { Position } from '../world/Position'; import { World } from '../world/World'; import { Attributes } from './Attribute'; import { Metadata } from './Metadata'; /** * Entity-like class. * @class * @internal */ export declare class EntityLike extends Position { protected readonly uuid: string; protected readonly runtimeId: bigint; protected readonly server: Server; pitch: number; yaw: number; headYaw: number; /** * EntityLike constructor. * @param {object} options - The entity-like options. * @param {string} options.uuid - The entity's runtime id. * @param {bigint} options.runtimeId - The entity's runtime id. * @param {Server} options.server - The server instance. * @param {World} [options.world] - The world the entity belongs to. * @param {number} [options.pitch=0] - The pitch. * @param {number} [options.yaw=0] - The yaw. * @param {number} [options.headYaw=0] - The head yaw. * @returns {EntityLike} The entity-like instance. */ constructor({ uuid, runtimeId, pitch, yaw, headYaw, ...options }: { uuid?: string; runtimeId: bigint; pitch?: number; yaw?: number; headYaw?: number; server: Server; world: World; }); /** * Get the entity's runtime id. * @returns {bigint} The entity's runtime id. */ getRuntimeId(): bigint; /** * Get the server instance. * @returns {Server} The server instance. */ getServer(): Server; /** * Get the entity's position. * @returns {Vector3} The entity's position. * @example * ```typescript * const position = entity.getPosition(); * ``` */ getPosition(): Vector3; /** * Returns the nearest entity from the current entity. * @todo Customizable radius * @param {Entity[]} [entities=this.getWorld().getEntities()] - The entities to compare the distance between. * @returns {Entity[]} The nearest entity. * @example * ```typescript * const nearestEntity = entity.getNearestEntity(); * console.log('Nearest entity:', nearestEntity); * ``` */ getNearestEntity(entities?: Entity[]): Entity[]; } /** * The base class for all entities including `Player`. * @class * @public */ export declare class Entity extends EntityLike { /** * The global runtime id counter. * @internal */ static runtimeIdCount: bigint; /** * The entity's namespace ID. */ protected static MOB_ID: string; /** * Get the entity type. * @returns {string} The entity's namespace ID. * @example * ```typescript * const entityType = entity.getType(); * console.log(`Entity type: ${entityType}`); * ``` */ getType(): string; /** * Entity metadata. */ readonly metadata: Metadata; /** * Entity attributes. */ readonly attributes: Attributes; /** * Entity constructor. * @param {object} options - The entity options. * @param {World} options.world - The world the entity belongs to. * @param {Server} options.server - The server instance. * @param {string} [options.uuid] - The entity's UUID. * @returns {Entity} The entity instance. * @example * ```typescript * const entity = new Entity({ * world: server.getWorldManager().getDefaultWorld(), * server * }); * ``` */ constructor({ world, ...options }: Omit<ConstructorParameters<typeof EntityLike>[0], 'runtimeId'>); get [Symbol.toStringTag](): string; /** * Convert to a string representation. * @returns {string} The string. * ```typescript * console.log(entity.toString()); * ``` */ toString(): string; /** * Get the entity's runtime id. * @returns {bigint} The entity's runtime id. * @example * ```typescript * const entityId = entity.getRuntimeId(); * console.log(entityId); // Ex. Output: 1n * ``` */ getRuntimeId(): bigint; /** * Get the entity's UUID. * @returns {string} The entity's UUID. * ```typescript * console.log(entity.getUUID()); * ``` */ getUUID(): string; /** * Fired every tick from the event subscription in the constructor. * @param {number} _tick - The current world-tick. * @returns {Promise<void>} A promise that resolves when the update is complete. * @example * ```typescript * entity.update(10); * ``` */ update(_tick: number): Promise<void>; /** * Get the server instance. * @returns {Server} The server instance. * @example * ```typescript * const server = entity.getServer(); * // Do things with the server. * ``` */ getServer(): Server; /** * Spawn the entity. * @todo `motion`, `pitch` & `yaw` is unimplemented. * @param {Player} [player] - The player to send the packet to. * @returns {Promise<void>} A promise that resolves when the entity is spawned. */ sendSpawn(player?: Player): Promise<void>; /** * Despawn the entity. * @param {Player} [player] - The player to send the packet to, if not specified, all players in the world will receive the packet. * @returns {Promise<void>} A promise that resolves when the entity is despawned. */ sendDespawn(player?: Player): Promise<void>; /** * Send the position to all the players in the same world. * @returns {Promise<void>} A promise that resolves when the position is sent. */ sendPosition(): Promise<void>; /** * Send a message to an entity. * @remarks This will silently fail on non-client-controlled entities. * @param {string} message - The message. * @param {TextType} [type=TextType.Raw] - The text type. * @example Send "Hello World!" to a client: * ```typescript * entity.sendMessage('Hello World!'); * ``` */ sendMessage(message: string, type?: TextType): void; /** * Set the `x` position. * @param {number} x - The `x` coordinate. * @param {boolean} [suppress=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. * @example * ```typescript * await entity.setX(10); * ``` * @remarks This method will also send the position update to the client if `suppress` is `false`. */ setX(x: number, suppress?: boolean): Promise<void>; /** * Set the `y` position. * @param {number} y - The `y` coordinate. * @param {boolean} [suppress=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. * @example * ```typescript * await entity.setY(10); * ``` * @remarks This method will also send the position update to the client if `suppress` is `false`. */ setY(y: number, suppress?: boolean): Promise<void>; /** * Set the `z` position. * @param {number} z - The `z` coordinate. * @param {boolean} [suppress=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. * @example * ```typescript * await entity.setZ(10); * ``` * @remarks This method will also send the position update to the client if `suppress` is `false`. */ setZ(z: number, suppress?: boolean): Promise<void>; /** * Set the entity's position and notify the clients. * @param {object} options - The position options. * @param {Vector3} options.position - The position. * @param {number} [options.pitch] - The pitch. * @param {number} [options.yaw] - The yaw. * @param {number} [options.headYaw] - The head yaw. * @returns {Promise<void>} A promise that resolves when the position is set. */ setPosition({ position, pitch, yaw, headYaw }: { position: Vector3; pitch?: number; yaw?: number; headYaw?: number; }): Promise<void>; /** * Check if the entity is a player. * @returns {boolean} `true` if the entity is player-controlled, otherwise `false`. * @example * ```typescript * if (entity.isPlayer()) { * console.log('Entity is a player'); * } else { * console.log('Entity is not a player'); * } * ``` */ isPlayer(): boolean; /** * Check if the entity is a console instance. * @returns {boolean} `true` if the entity is console-controlled, otherwise `false`. * @example * ```typescript * if (entity.isConsole()) { * console.log('Entity is a console'); * } else { * console.log('Entity is not a console'); * } * ``` */ isConsole(): boolean; /** * Get the entity's (potentially custom) name. * @returns {string} The entity's name without formatting (usually prefix & suffix). * @example * ```typescript * const name = entity.getName(); * console.log(`Entity name: ${name}`); * ``` */ getName(): string; /** * Set the entity's name. * @param {string} name - The name. * @example * ```typescript * entity.setName('Mr. Sheep'); * ``` */ setName(name: string): void; /** * Get the entity's formatted name. * @returns {string} The entity's formatted name (including prefix & suffix). * @example * ```typescript * const formattedName = entity.getFormattedUsername(); * console.log(`Entity formatted name: ${formattedName}`); // Entity formatted name: Sheep * ``` */ getFormattedUsername(): string; } //# sourceMappingURL=Entity.d.ts.map