UNPKG

yoni-mcscripts-lib

Version:

为 Minecraft Script API 中的部分接口创建了 wrapper,并提供简单的事件管理器和任务管理器,另附有一些便于代码编写的一些小工具。

179 lines (178 loc) 6.38 kB
import { Minecraft } from "./basis.js"; import type { EntityValue, PlayerEntityValue } from "./types"; import type { YoniPlayer, YoniEntity } from "./remix/entity/index.js"; /** * 一系列处理实体的方法。 */ export declare class EntityUtils { #private; /** * 检查一个对象是否为实体对象。 * @param {any} object - 任意。 * @throws 当不是实体的时候抛出错误。 */ static checkIsEntity(object: any): void; /** * (内部方法)由实体对象创建对应的 YoniEntity 实体对象。 * * 一般情况下你不应该使用此方法,而是使用 {@link EntityUtils.getYoniEntity}。 * @param {any} entity - 可以被认为是实体的东西。 * @return {YoniEntity} 如果 `entity` 不为实体类型,则返回 `null`。 */ static from(entity: any): YoniEntity | null; /** * 检测指定实体对象是否为玩家实体对象。 * @param {EntityValue} entity 要检测的实体。 * @returns {boolean} */ static entityIsPlayer(entity: EntityValue): entity is (Minecraft.Player | YoniPlayer); /** * 获取实体的已经存在于世界上的 YoniEntity 对象实例。 */ static getAliveEntity(entity: EntityValue): YoniEntity; /** * 获取实体的已经存在于世界上的香草实体对象实例。 */ static getAliveVanillaEntity(entity: EntityValue): Minecraft.Entity; /** * 获取所有已经载入的实体的对象实例。 * @param {Minecraft.EntityQueryOptions} option * @return {YoniEntity[]} */ static getAliveEntities(option: Minecraft.EntityQueryOptions): YoniEntity[]; /** * 获取活体实体的 `minecraft:health` 组件。 * @param {EntityValue} entity * @returns {Minecraft.EntityHealthComponent} */ static getHealthComponent(entity: EntityValue): Minecraft.EntityHealthComponent; /** * 尝试获取实体的 `minecraft:health` 组件。 * @param {EntityValue} entity * @returns {Minecraft.EntityHealthComponent} */ static tryGetHealthComponent(entity: EntityValue): Minecraft.EntityHealthComponent | false; /** * 获取实体的物品栏容器对象。 * @param {EntityValue} entity * @returns {Minecraft.InventoryComponentContainer} */ static getInventory(entity: EntityValue): Minecraft.Container; /** * 获取玩家主手上的物品。 */ static getItemInMainHand(entity: PlayerEntityValue): Minecraft.ItemStack | undefined; /** * 设置玩家主手上的物品。 */ static setItemInMainHand(entity: PlayerEntityValue, item?: Minecraft.ItemStack): void; /** * 获取活体实体的血量。 * @param {EntityValue} entity * @returns {number} */ static getCurrentHealth(entity: EntityValue): number; /** * 遍历所有维度以获取所有存活着的实体。 */ static getDimensionVanillaEntities(options?: Minecraft.EntityQueryOptions): Minecraft.Entity[]; /** * 获取世界内存在的玩家。 */ static getWorldVanillaPlayers(options?: Minecraft.EntityQueryOptions): Array<Minecraft.Player>; /** * 获取世界内存在的所有实体(这包括死亡的玩家)。 * * 尽管此方法已经尽了它最大的努力,但是对于一些特殊实体(如minecraft:agent),它们仍然不包含在返回结果中。 * @returns {EntityValue[]} */ static getLoadedVanillaEntities(): Minecraft.Entity[]; /** * 获取实体可达到的最大血量。 * @param {EntityValue} entity * @returns {number} */ static getMaxHealth(entity: EntityValue): number; /** * 获取实体对象对应的 Minecraft.Entity。 * @param {EntityValue} entity * @returns {MinecraftEntityType} */ static getMinecraftEntity(entity: EntityValue): Minecraft.Entity; /** * 获取实体对象对应的 YoniEntity。 * @param {EntityValue} entity * @returns {YoniEntityType} * @throws 如果参数不是实体将会抛出错误 */ static getYoniEntity(entity: EntityValue): YoniEntity; /** * 检测实体是否有所有指定的家族。 * @param {EntityValue} entity * @param {...string} families * @returns {boolean} */ static hasFamilies(entity: EntityValue, ...families: string[]): boolean; /** * 检测实体是否有任一指定的家族。 * @param {EntityValue} entity * @param {...string} families * @returns {boolean} */ static hasAnyFamily(entity: EntityValue, ...families: string[]): boolean; /** * 检测实体是否含有指定家族。 * @param {EntityValue} entity * @param {string} family * @returns {boolean} */ static hasFamily(entity: EntityValue, family: string): boolean; /** * 检测一个实体是否存在于世界上。 * @param {EntityValue} entity * @returns {boolean} */ static isAliveEntity(entity: EntityValue): boolean; /** * 检测一个实体是否活着。 * * 例如;物品、箭、烟花不是生物实体。 * @param {EntityValue} entity * @returns {boolean} */ static isLivingEntity(entity: EntityValue): boolean; /** * 检测参数是否为实体。 * @param {any} obj * @returns {boolean} */ static isEntity(object: any): object is (YoniEntity | Minecraft.Entity); /** * 检测参数是否为玩家实体。 * @param {any} obj * @returns {boolean} */ static isPlayer(object: any): object is (YoniPlayer | Minecraft.Player); /** * 检测参数是否为原版实体。 * @param {any} object * @returns {boolean} */ static isMinecraftEntity(object: any): object is Minecraft.Entity; /** * 检测两个参数是否为实体且代表同一实体 */ static isSameEntity(entity1: any, entity2: any): boolean; /** * 检测参数是否为 YoniEntity。 * @param {any} object * @returns {boolean} */ static isYoniEntity(object: any): object is YoniEntity; /** * 设置实体的血量。 * @param {EntityValue} entity * @param {number} val */ static setCurrentHealth(entity: EntityValue, value: number): void; }