diff --git a/lib/BEPlaceholderAPI-JS.d.ts b/lib/BEPlaceholderAPI-JS.d.ts new file mode 100644 index 0000000..0328a22 --- /dev/null +++ b/lib/BEPlaceholderAPI-JS.d.ts @@ -0,0 +1,67 @@ +declare class PAPI { + /** 注册一个玩家PAPI变量 */ + static registerPlayerPlaceholder( + /** PAPI调用函数 */ + func: ( + /** 玩家对象 */ + player: Player + ) => string, + /** 插件名字 */ + pluginsName: string, + /** PAPI变量 */ + PAPIName: string + ): boolean; + + /** 注册一个服务器PAPI变量 */ + static registerServerPlaceholder( + /** PAPI调用函数 */ + func: () => string, + /** 插件名字 */ + pluginsName: string, + /** PAPI变量 */ + PAPIName: string + ): boolean; + + /** 注册一个静态PAPI变量 */ + static registerStaticPlaceholder( + /** PAPI调用函数 */ + func: () => string, + /** 插件名字 */ + pluginsName: string, + /** PAPI变量 */ + PAPIName: string, + /** 更新时间 */ + UpdateInterval: number + ): boolean; + + /** 获取一个服务器变量的值 */ + static getValue( + /** PAPI名 */ + key: string + ): string; + + /** 获取一个玩家变量的值 */ + static getValueByPlayer( + /** PAPI名 */ + key: string, + /** 玩家对象 */ + pl: Player + ): string; + + /** 翻译带PAPI变量的字符串 */ + static translateString( + /** 要翻译的字符串 */ + str: string, + /** 玩家对象 */ + pl: Player | undefined + ): string; + + /** 注销一个PAPI变量 */ + static unRegisterPlaceholder( + /** PAPI名 */ + str: string + ): boolean; + + /** 获取所有已注册的PAPI变量 */ + static getAllPAPI(): string[]; +} diff --git a/lib/BEPlaceholderAPI-JS.js b/lib/BEPlaceholderAPI-JS.js index 50ba212..6d5af74 100644 --- a/lib/BEPlaceholderAPI-JS.js +++ b/lib/BEPlaceholderAPI-JS.js @@ -1,47 +1,101 @@ const PlaceholderAPI = { + /** 获取一个服务器变量的值 @type {function(string):string} */ getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"), + /** 获取一个玩家变量的值 @type {function(string,Player):string} */ getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"), + /** 注册一个玩家变量 @type {function(string,string,string):boolean} */ registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"), + /** 注册一个服务器变量 @type {function(string,string,string):boolean} */ registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"), + /** 注册一个静态变量 @type {function(string,string,string,number):boolean} */ registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"), + /** 翻译包含PAPI服务器变量的字符串 @type {function(string):string} */ translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"), + /** 翻译包含PAPI玩家变量的字符串 @type {function(string,Player):string} */ translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"), + /** 注销PAPI变量 @type {function(string):boolean} */ unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"), + /** 获取所有已注册的PAPI变量 @type {function():Array.} */ getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI") } -Function.prototype.getName = function () { - return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] +Function.prototype.getName = +/** + * 获取函数名字 + * @returns {string} + */ +function () { + return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] || Math.ceil(Math.random() * 1000000).toString(16); } +/** PAPI变量类 */ class PAPI { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 注册一个玩家PAPI变量 + * @param {function} func 变量调用的函数 + * @param {string} PluginName 插件名字 + * @param {string} PAPIName PAPI变量名 + * @returns {boolean} 是否注册成功 + */ static registerPlayerPlaceholder(func, PluginName, PAPIName) { ll.export(func, PluginName, func.getName()); return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName); } + /** + * 注册一个服务器PAPI变量 + * @param {function} func 变量调用的函数 + * @param {string} PluginName 插件名字 + * @param {string} PAPIName PAPI变量名 + * @returns {boolean} 是否注册成功 + */ static registerServerPlaceholder(func, PluginName, PAPIName) { ll.export(func, PluginName, func.getName()); return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName); } + /** + * 注册一个静态PAPI变量 + * @param {function} func 变量调用的函数 + * @param {string} PluginName 插件名字 + * @param {string} PAPIName PAPI变量名 + * @param {number} [UpdateInterval=50] 更新间隔 + * @returns {boolean} 是否注册成功 + */ static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) { ll.export(func, PluginName, func.getName()); return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval); } + /** + * 获取一个服务器变量的值 + * @param {string} key PAPI变量名 + * @returns {string} 值 + */ static getValue(key) { return PlaceholderAPI.getValueAPI(key); } - + + /** + * 获取一个玩家变量的值 + * @param {string} key PAPI变量名 + * @param {Player} pl 玩家对象 + * @returns {string} 值 + */ static getValueByPlayer(key, pl) { return PlaceholderAPI.getValueByPlayerAPI(key, pl); } + /** + * 翻译带PAPI变量的字符串 + * @param {string} str 字符串 + * @param {Player} pl 玩家对象 + * @returns {string} 翻译结果 + */ static translateString(str, pl = null) { if (pl) { return PlaceholderAPI.translateStringWithPlayerAPI(str, pl); @@ -49,10 +103,19 @@ class PAPI { return PlaceholderAPI.translateStringAPI(str); } + /** + * 注销一个PAPI变量 + * @param {string} str PAPI变量名 + * @returns {boolean} 是否注销成功 + */ static unRegisterPlaceholder(str) { return PlaceholderAPI.unRegisterPlaceholderAPI(str); } + /** + * 获取所有已注册的PAPI变量 + * @returns {Array.} 已注册的PAPI变量数组 + */ static getAllPAPI() { return PlaceholderAPI.getAllPAPI(); } diff --git a/lib/EventAPI-JS.d.ts b/lib/EventAPI-JS.d.ts new file mode 100644 index 0000000..54af930 --- /dev/null +++ b/lib/EventAPI-JS.d.ts @@ -0,0 +1,194 @@ +/// + +/** 事件监听接口 */ +declare class Event2 { + /** 生物捡起物品 */ + static listen( + /** 事件名 */ + event: "onMobDie", + /** 监听函数 */ + listener: ( + /** 尝试捡起物品的实体对象 */ + entity: Entity, + /** 掉落物实体对象 */ + itemEntity: Entity + ) => boolean | void + ): boolean; + + /** 客户端登录后事件(不可以拦截) */ + static listen( + /** 事件名 */ + event: "onClientLogin", + /** 监听函数 */ + listener: ( + /** 玩家的游戏名字 */ + realName: string, + /** 玩家的uuid */ + uuid: string, + /** 玩家在服务端的xuid */ + serverXuid: string, + /** 玩家在客户端的xuid */ + clientXuid: string + ) => void + ): boolean; + + /** 天气改变事件事件 */ + static listen( + /** 事件名 */ + event: "onWeatherChange", + /** 监听函数 */ + listener: ( + /** 雷暴天气等级 */ + lightningLevel: number, + /** 雨天天气等级 */ + rainLevel: number, + /** 雷暴持续时间(刻) */ + lightningLastTick: number, + /** 雨天持续时间(刻) */ + rainingLastTick: number + ) => boolean | void + ): boolean; + + /** 掉落物尝试生成 */ + static listen( + event: "onItemTrySpawn", + listener: ( + /** 物品对象 */ + item: Item, + /** 尝试生成的坐标对象 */ + pos: FloatPos, + /** 创建掉落物的实体对象 */ + spawnerEntity: Entity + ) => boolean | void + ): boolean; + + /** 掉落物生成完毕(不可以拦截) */ + static listen( + /** 事件名 */ + event: "onItemTrySpawn", + /** 回调函数 */ + listener: ( + /** 物品对象 */ + item: Item, + /** 掉落物实体对象 */ + entity: Entity, + /** 实体生成的坐标 */ + pos: FloatPos, + /** 创建掉落物的实体对象 */ + spawnerEntity: Entity + ) => void + ): boolean; + + /** 实体切换维度 */ + static listen( + /** 事件名 */ + event: "onEntityChangeDim", + /** 回调函数 */ + listener: ( + /** 切换维度的实体对象 */ + entity: Entity, + /** 前往到的维度ID */ + dimid: number + ) => boolean | void + ): boolean; + + /** 实体切换维度后(不可拦截) */ + static listen( + /** 事件名 */ + event: "onEntityChangeDimAfter", + /** 回调函数 */ + listener: ( + /** 切换维度的实体对象 */ + entity: Entity, + /** 前往到的维度ID */ + fromDimid: number + ) => void + ): boolean; + + /** 玩家下床 */ + static listen( + /** 事件名 */ + event: "onLeaveBed", + /** 回调函数 */ + listener: ( + /** 下床的玩家对象 */ + player: Player + ) => boolean | void + ): boolean; + + /** 触发死亡信息(不可以拦截) */ + static listen( + /** 事件名 */ + event: "onDeathMessage", + /** 回调函数 */ + listener: ( + /** 死亡信息键名 */ + deathMsgKey: string, + /** 死亡信息翻译参数 */ + deathMsgParams: Array., + /** 死亡实体的实体对象 */ + entity: Entity + ) => void + ): boolean; + + /** 实体受伤后事件 */ + static listen( + /** 事件名 */ + event: "onMobHurted", + /** 回调函数 */ + listener: ( + /** 受伤的实体对象 */ + entity: Entity, + /** 造成伤害的实体对象 */ + source: Entity, + /** 伤害值 */ + damage: number, + /** 伤害类型 */ + cause: number + ) => void + ): boolean; + + /** 末影人搬起方块 */ + static listen( + /** 事件名 */ + event: "onEndermanTake", + /** 回调函数 */ + listener: ( + /** 末影人实体对象 */ + entity: Entity + ) => boolean | void + ): boolean; + + /** 末影龙重生事件 */ + static listen( + /** 事件名 */ + event: "DragonRespawn", + /** 回调函数 */ + listener: ( + /** 末影龙重生后的UniqueID */ + uniqueID: number + ) => boolean | void + ): boolean; + + /** 弹射物实体尝试创建 */ + static listen( + /** 事件名 */ + event: "ProjectileTryCreate", + /** 回调函数 */ + listener: ( + /** 弹射物实体对象 */ + entity: Entity + ) => boolean | void + ): boolean; + + /** 弹射物实体成功后(不可拦截) */ + static listen( + /** 事件名 */ + event: "ProjectileCreate", + /** 回调函数 */ + listener: ( + /** 弹射物实体对象 */ + entity: Entity + ) => void + ): boolean; +} diff --git a/lib/EventAPI-JS.js b/lib/EventAPI-JS.js index 0fc9189..7e2c7ee 100644 --- a/lib/EventAPI-JS.js +++ b/lib/EventAPI-JS.js @@ -1,17 +1,30 @@ +/** 事件创建函数 @type {function(string,string):boolean} */ const CallEvent = ll.import("GMLIB_API", "callCustomEvent"); +/** 事件ID @type {number} */ let NextEventId = 0; +/** + * 获取事件ID标识名 + * @returns {string} 事件ID标识名 + */ function getNextEventId() { NextEventId++; return "GMLIB_Event_" + NextEventId; } +/** 事件类 */ class Event { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 监听事件 + * @param {string} event 事件名称 + * @param {function} callback 回调 + * @returns {boolean} 是否创建成功 + */ static listen(event, callback) { let eventId = getNextEventId(); ll.export(callback, event, eventId); diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts new file mode 100644 index 0000000..20963e8 --- /dev/null +++ b/lib/GMLIB_API-JS.d.ts @@ -0,0 +1,1140 @@ +/** 静态悬浮字类 */ +declare class StaticFloatingText { + constructor( + /** 生成的坐标 */ + pos: FloatPos, + /** 显示的文本 */ + text: string, + /** 是否启用papi变量 */ + papi: boolean | undefined + ); + + /** 发送悬浮字给玩家 */ + sendToClient( + /** 要发送的玩家对象 */ + player: Player + ): boolean; + + /** 发送悬浮字给所有玩家 */ + sendToClients(): boolean; + + /** 删除玩家的悬浮字 */ + removeFromClient( + /** 要删除的玩家的玩家对象 */ + player: Player + ): boolean; + + /** 删除所有玩家悬浮字 */ + removeFromClients(): boolean; + + /** 更新玩家的悬浮字 */ + updateClient( + player: Player + ): boolean; + + /** 更新所有玩家的悬浮字 */ + updateClients(): boolean; + + /** 获取悬浮字的RuntimeId */ + getRuntimeId(): number; + + /** 获取悬浮字显示的文本 */ + getText(): string; + + /** 设置悬浮字显示的文本 */ + setText( + /** 要显示的文本 */ + text: string + ): void; + + /** 更新所有玩家的悬浮字 */ + update(): boolean; + + /** 更新悬浮字文本 */ + updateText( + /** 要显示的文本 */ + text: string + ): boolean; + + /** 获取悬浮字的坐标 */ + getPos(): FloatPos; + + /** 删除悬浮字 */ + destroy(): boolean + + /** 根据RuntimeId获取静态悬浮字 */ + static getFloatingText( + /** 悬浮字的RuntimeId */ + runtimeId: number + ): StaticFloatingText | null; + + /** 获取所有静态悬浮字 */ + static getAllFloatingTexts(): Array; +} + +/** 动态悬浮字类 */ +declare class DynamicFloatingText extends StaticFloatingText { + constructor( + /** 生成的坐标 */ + pos: FloatPos, + /** 显示的文本 */ + text: string, + /** 更新频率(秒) */ + updateRate: number | undefined, + /** 是否使用PAPI变量 */ + papi: boolean | undefined + ); + + /** 获取悬浮字更新频率 */ + getUpdateRate(): number + + /** 设置悬浮字更新频率 */ + setUpdateRate( + updateRate: number | undefined + ): void; + + /** 开始更新悬浮字 */ + startUpdate(): boolean; + + /** 停止更新悬浮字 */ + stopUpdate(): boolean; + + /** 删除悬浮字 */ + destroy(): boolean; + + /** 根据RuntimeId获取动态悬浮字 */ + static getFloatingText( + /** 悬浮字的RuntimeId */ + runtimeId: number + ): StaticFloatingText | null; + + /** 获取所有动态悬浮字 */ + static getAllFloatingTexts(): Array; +} + +/** 基础游戏API类 */ +declare class Minecraft { + private constructor(); + + /** 获取服务器平均tps */ + static getServerAverageTps(): number; + + /** 获取服务器当前tps */ + static getServerCurrentTps(): number; + + /** 获取服务器mspt */ + static getServerMspt(): number; + + /** 获取所有玩家uuid */ + static getAllPlayerUuids(): Array; + + /** 获取玩家NBT */ + static getPlayerNbt( + /** 玩家uuid */ + uuid: string + ): NbtCompound; + + /** 写入玩家NBT */ + static setPlayerNbt( + /** 玩家uuid */ + uuid: string, + /** 要设置的NBT数据 */ + nbt: NbtCompound, + /** 不存在是否创建 */ + forceCreate: boolean | undefined + ): boolean; + + /** 覆盖玩家NBT的特定Tags */ + static setPlayerNbtTags( + /** 玩家uuid */ + uuid: string, + /** 要设置的NBT数据 */ + nbt: NbtCompound, + /** 要覆盖的NBT标签 */ + tags: string + ): boolean; + + /** 删除玩家NBT */ + static deletePlayerNbt( + /** 玩家uuid */ + uuid: string, + ): boolean; + + /** 获取玩家坐标 */ + static getPlayerPosition( + /** 玩家uuid */ + uuid: string + ): IntPos | null; + + /** 设置玩家坐标 */ + static setPlayerPosition( + /** 玩家uuid */ + uuid: string, + /** 玩家坐标 */ + pos: IntPos + ): boolean; + + /** 获取世界出生点 */ + static getWorldSpawn(): IntPos; + + /** 设置世界出生点 */ + static setWorldSpawn( + /** 要设置的出生点坐标对象 */ + pos: IntPos + ): void; + + /** 启用教育版内容 */ + static setEducationFeatureEnabled(): void; + + /** 注册Ability命令 */ + static registerAbilityCommand(): void; + + /** 启用Xbox成就 */ + static setEnableAchievement(): void; + + /** 信任所有玩家皮肤 */ + static setForceTrustSkins(): void; + + /** 启用资源包双端共存 */ + static enableCoResourcePack(): void; + + /** 获取存档名称 */ + static getWorldName(): string; + + /** 设置存档名称 */ + static setWorldName( + name: string + ): boolean; + + /** 设置假种子 */ + static setFakeSeed( + /** 要设置的假种子 */ + seed: number | undefined + ): void; + + /** 启用错误方块清理 */ + static setUnknownBlockCleaner(): void; + + /** 强制生成实体 */ + static spawnEntity( + /** 生成坐标 */ + pos: FloatPos, + /** 实体命名空间 */ + name: string + ): Entity; + + /** 射弹投射物 */ + static shootProjectile( + /** 实体对象 */ + entity: Entity, + /** 投射物命名空间 */ + proj: string, + /** 速度 */ + speed: number, + /** 偏移量 */ + offset: number + ): boolean; + + /** 投掷实体 */ + static throwEntity( + /** 实体对象 */ + entity: Entity, + /** 被投掷的实体 */ + proj: Entity, + /** 速度 */ + speed: number, + /** 偏移量 */ + offset: number + ): boolean; + + /** 获取服务器使用的语言 */ + static getServerLanguage(): string; + + /** 设置服务器使用的语言 */ + static setServerLanguage( + language: string + ): boolean; + + /** 设置资源包路径 */ + static setCustomPackPath( + /** 要设置的路径 */ + path: string + ): void; + + /** 翻译资源包文本 */ + static resourcePackTranslate( + /** 键名 */ + key: string, + /** 参数 */ + params: string[] | undefined + ): string; + + /** 根据uuid获取玩家对象 */ + static getPlayerFromUuid( + uuid: string + ): Player; + + /** 根据UniqueId获取玩家对象 */ + static getPlayerFromUniqueId( + uniqueId: string + ): Player; + + /** 根据UniqueId获取实体对象 */ + static getEntityFromUniqueId( + uniqueId: string + ): Entity; + + /** 获取方块runtimeId */ + static getBlockRuntimeId( + /** 方块命名空间 */ + block: string, + /** 方块的特殊值 */ + legacyData: Number | undefined + ): number; + + /** 添加虚假列表玩家 */ + static addFakeList( + /** 虚假玩家的名字 */ + name: string, + /** 虚假玩家的xuid */ + xuid: string + ): boolean; + + /** 移除虚假列表玩家 */ + static removeFakeList( + /** 虚假的玩家名字或xuid */ + nameOrXuid: string + ): boolean; + + /** 移除所有虚假列表玩家 */ + static removeAllFakeLists(): boolean; + + /** 启用I18n修复 */ + static setFixI18nEnabled(): void; + + /** 保存NBT至文件 */ + static saveNbtToFile( + /** 文件路径 */ + path: string, + /** NBT对象 */ + nbt: NbtCompound, + /** 是否写入为二进制 */ + isBinary: boolean | undefined + ): boolean; + + /** 从文件读取NBT */ + static readNbtFromFile( + /** 文件路径 */ + path: string, + /** 是否以二进制方式读取 */ + isBinary: boolean | undefined + ): NbtCompound; + + /** 根据命名空间获取翻译键名 */ + static getBlockTranslateKeyFromName( + /** 方块命名空间 */ + name: string + ): string; + + /** 获取存档种子号 */ + static getLevelSeed(): string; + + /** 获取方块亮度 */ + static getBlockLightEmission( + /** 方块的命名空间 */ + block: string, + /** 方块的特殊值 */ + legacyData: number + ): number; + + /** 获取游戏规则列表 */ + static getGameRules(): { Name: string; Value: boolean | number; }[] +} + +/** 合成表类 */ +declare class Recipes { + private constructor(); + + /** 注销合成表 */ + static unregisterRecipe( + /** 合成表唯一标识符 */ + recipeId: string + ): boolean; + + /** 注册切石机合成表 */ + static registerStoneCutterRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 输入物品 */ + inputName: string, + /** 输入物品额外数据 */ + inputAux: number, + /** 合成结果 */ + outputName: string, + /** 合成结果额外数据 */ + outputAux: number, + /** 合成数量 */ + outputCount: number + ): boolean; + + /** 注册锻造纹饰合成表 */ + static registerSmithingTrimRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 锻造模板 */ + template: string, + /** 基础材料 */ + base: string, + /** 纹饰材料 */ + addition: string + ): boolean; + + /** 注册锻造配方合成表 */ + static registerSmithingTransformRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 锻造模板 */ + template: string, + /** 基础材料 */ + base: string, + /** 升级材料 */ + addition: string, + /** 合成结果 */ + result: string + ): boolean; + + /** 注册酿造容器表 */ + static registerBrewingContainerRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 输入物品 */ + input: string, + /** 合成结果 */ + output: string, + /** 酿造物品 */ + reagent: string + ): boolean; + + /** 注册酿造混合表 */ + static registerBrewingMixRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 输入物品 */ + input: string, + /** 合成结果 */ + output: string, + /** 酿造物品 */ + reagent: string + ): boolean; + + /** 注册熔炼合成表 */ + static registerFurnaceRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 输入物品 */ + input: string, + /** 合成结果 */ + output: string, + /** 材料的标签数组 */ + tags: ("furnace" | "blast_furnace" | "smoker" | "campfire" | "soul_campfire")[] | undefined + ): boolean; + + /** 注册有序合成表 */ + static registerShapedRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 合成表摆放方式,数组元素为字符串 */ + shape: [string, string, string], + /** 材料数组 */ + ingredients: string[], + /** 合成结果 */ + result: string, + /** 合成结果的数量 */ + count: number | undefined, + /** 解锁条件(也可以填物品命名空间) */ + unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined + ): boolean; + + /** 注册无序合成表 */ + static registerShapelessRecipe( + /** 合成表唯一标识符 */ + recipeId: string, + /** 合成材料 */ + ingredients: string[], + /** 合成结果 */ + result: string, + /** 合成结果的数量 */ + count: number | undefined, + /** 解锁条件(也可以填物品命名空间) */ + unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined + ): boolean; +} + +/** 实验性功能类 */ +declare class Experiments { + private constructor(); + + /** 获取所有实验的id */ + static getAllExperimentIds(): number[]; + + /** 获取实验性功能文本的键名 */ + static getExperimentTranslateKey( + /** 实验性功能的id */ + id: number + ): string; + + /** 获取实验性功能启用状态 */ + static getExperimentEnabled( + /** 实验性功能的id */ + id: number + ): boolean; + + /** 设置实验性功能启用状态 */ + static setExperimentEnabled( + /** 实验性功能的id */ + id: number, + /** 实验性功能是否开启 */ + value: boolean | undefined + ): void; + + /** 设置实验性依赖 */ + static registerExperimentsRequire( + /** 实验性功能的id */ + id: number, + ): void +} + +/** 计分板类 */ +declare class Scoreboard { + private constructor(); + + /** 获取所有跟踪实体 */ + static getAllTrackedEntities(): string[]; + + /** 获取所有跟踪的玩家 */ + static getAllTrackedPlayers(): string[]; + + /** 获取所有跟踪的字符串 */ + static getAllTrackedFakePlayers(): string[]; + + /** 获取所有跟踪目标 */ + static getAllTrackedTargets(): ({ Type: "Player"; Uuid: string; } | { Type: "FakePlayer"; Name: string; } | { Type: "Entity"; UniqueId: string; })[] + + /** 创建计分板 */ + static addObjective( + /** 计分板名字 */ + name: string, + /** 显示名称 */ + displayName: string, + ): boolean; + + /** 移除计分板 */ + static removeObjective( + /** 计分板名字 */ + name: string + ): boolean; + + /** 获取所有计分板名字 */ + static getAllObjectives(): string[]; + + /** 获取计分板显示名称 */ + static getDisplayName( + /** 计分板名字 */ + objective: string + ): string; + + /** 设置计分板显示名称 */ + static setDisplayName( + /** 计分板名字 */ + objective: string, + /** 显示名称 */ + displayName: string + ): boolean; + + /** 设置计分板显示 */ + static setDisplay( + /** 计分板名字 */ + objective: string, + /** 显示位置 */ + slot: "sidebar" | "list" | "belowName", + /** 排序方式 */ + order: 0 | 1 + ): void; + + /** 清除计分板显示 */ + static clearDisplay( + /** 计分板名字 */ + objective: string + ): void; + + /** 获取玩家在计分板中的值 */ + static getPlayerScore( + /** 玩家的uuid */ + uuid: string, + /** 计分板名字 */ + objective: string + ): number | null; + + /** 增加玩家在计分板中的值 */ + static addPlayerScore( + /** 玩家的uuid */ + uuid: string, + /** 计分板名字 */ + objective: string, + /** 增加的值 */ + value: number + ): boolean; + + /** 减少玩家在计分板中的值 */ + static reducePlayerScore( + /** 玩家的uuid */ + uuid: string, + /** 计分板名字 */ + objective: string, + /** 减少的值 */ + value: number + ): boolean; + + /** 设置玩家在计分板中的值 */ + static setPlayerScore( + /** 玩家的uuid */ + uuid: string, + /** 计分板名字 */ + objective: string, + /** 设置的值 */ + value: number + ): boolean; + + /** 重载玩家在计分板中的数据 */ + static resetPlayerScore( + /** 玩家的uuid */ + uuid: string, + /** 计分板名字 */ + objective: string + ): boolean; + + /** 重置玩家所有计分板的数据 */ + static resetPlayerScores( + /** 玩家的uuid */ + uuid: string + ): boolean; + + /** 获取字符串在计分板中的值 */ + static getFakePlayerScore( + /** 字符串名字 */ + name: string, + /** 计分板名字 */ + objective: string + ): number | null; + + /** 增加字符串在计分板中的值 */ + static addFakePlayerScore( + /** 字符串名字 */ + name: string, + /** 计分板名字 */ + objective: string, + /** 增加的值 */ + value: number + ): boolean; + + /** 减少字符串在计分板中的值 */ + static reduceFakePlayerScore( + /** 字符串名字 */ + name: string, + /** 计分板名字 */ + objective: string, + /** 减少的值 */ + value: number + ): boolean; + + /** 设置字符串在计分板中的值 */ + static setFakePlayerScore( + /** 字符串名字 */ + name: string, + /** 计分板名字 */ + objective: string, + /** 设置的值 */ + value: number + ): boolean; + + /** 重载字符串在计分板中的数据 */ + static resetFakePlayerScore( + /** 字符串名字 */ + name: string, + /** 计分板名字 */ + objective: string + ): boolean; + + /** 重载字符串所有计分板数据 */ + static resetAllFakePlayerScores( + /** 字符串名字 */ + name: string + ): boolean; + + /** 获取实体在计分板中的值 */ + static getEntityScore( + /** 实体的uniqueId */ + uniqueId: string, + /** 计分板名字 */ + objective: string + ): number | null; + + /** 增加实体在计分板中的值 */ + static addEntityScore( + /** 实体的uniqueId */ + uniqueId: string, + /** 计分板名字 */ + objective: string, + /** 增加的值 */ + value: number + ): boolean; + + /** 减少实体在计分板中的值 */ + static reduceEntityScore( + /** 实体的uniqueId */ + uniqueId: string, + /** 计分板名字 */ + objective: string, + /** 减少的值 */ + value: number + ): boolean; + + /** 设置实体在计分板中的值 */ + static setEntityScore( + /** 实体的uniqueId */ + uniqueId: string, + /** 计分板名字 */ + objective: string, + /** 设置的值 */ + value: number + ): boolean; + + /** 重载实体在计分板中的数据 */ + static resetEntityScore( + /** 实体的uniqueId */ + uniqueId: string, + /** 计分板名字 */ + objective: string + ): boolean; + + /** 重载实体所有计分板数据 */ + static resetAllEntityScores( + /** 实体的uniqueId */ + uniqueId: string + ): boolean; +} + +/** 仿LSE的JsonConfigFile类 */ +declare class JsonConfig { + constructor( + /** 文件路径 */ + path: string, + /** 默认数据 */ + defaultData: object | undefined + ); + + /** 初始化文件 */ + init(): void; + + /** 保存文件 */ + save( + /** 缩进 */ + format: number | undefined + ): void; + + /** 获取所有数据 */ + getData(): object; + + /** 读取数据 */ + get( + /** 键名 */ + key: string, + /** 不存在返回值 */ + defaultValue: any + ): any; + + /** 设置数据 */ + set( + /** 键名 */ + key: string, + /** 值 */ + value: any + ): void; + + /** 删除数据 */ + delete( + /** 键名 */ + key: string + ): void; +} + +declare class JsonLanguage extends JsonConfig { + /** 创建或打开一个 Json 语言文件 */ + constructor( + /** 文件路径 */ + path: string, + /** 默认数据 */ + defaultData: object | undefined + ); + + /** 翻译键名 */ + translate( + /** 键名 */ + key: string, + /** 替换参数 */ + data: string[] + ): string; +} + +declare class JsonI18n { + /** 加载翻译数据目录 */ + constructor( + /** 目录 */ + path: string, + /** 默认语言 */ + localLangCode: string | undefined + ); + + /** 加载所有语言 */ + loadAllLanguage(): void; + + /** 加载语言 */ + loadLanguage( + /** 语言标识符 */ + langCode: string, + /** 默认数据 */ + defaultData: object | undefined + ): void; + + /** 设置语言 */ + chooseLanguage( + /** 语言标识符 */ + langCode: string + ): void; + + /** 设置默认语言 */ + setDefaultLanguage( + /** 语言标识符 */ + langCode: string + ): void; + + /** 翻译键名 */ + translate( + /** 键名 */ + key: string, + /** 替换参数 */ + data: string[], + /** 语言标识符 */ + langCode: string | undefined + ): string; +} + +/** 版本类 */ +declare class Version { + /** 创建版本对象 */ + constructor( + /** 主版本号 */ + major: number, + /** 次版本号 */ + minor: number, + /** 修订版本号 */ + revision: number, + ); + + /** 转换成字符串 */ + toString( + /** 是否添加前缀"v" */ + prefix: boolean | undefined + ): string; + + /** 转换成数组 */ + toArray(): [number, number, number]; + + /** 转换成数字 */ + valueOf(): number; + + /** 从字符串中创建版本对象 */ + static fromString( + /** 字符串 */ + version: string + ): Version; + + /** 从数组中创建版本对象 */ + static fromArray( + /** 数组 */ + version: [number, number, number] + ): Version; + + /** 检测LRCA版本是否大于或等于此版本 */ + static isPluginVersionMatched( + /** 比较版本号 */ + version: Version + ); + + /** 获取LRCA版本对象 */ + static getLrcaVersion(): Version; + + /** 获取GMLIB版本对象 */ + static getGmlibVersion(): Version; +} + +declare class I18nAPI { + private constructor(); + + /** 获取键翻译 */ + static get( + /** 键名 */ + key: string, + /** 翻译参数 */ + params: string[] | undefined, + /** 语言标识符 */ + langCode: string | undefined + ): string; + + /** 获取键翻译 */ + static translate( + /** 键名 */ + key: string, + /** 翻译参数 */ + params: string[] | undefined, + /** 语言标识符 */ + langCode: string | undefined + ): string; + + /** 获取支持的语言标识符 */ + static getSupportedLanguages(): string[]; + + /** 获取资源包默认语言 */ + static getCurrentLanguage(): string; + + /** 设置资源包默认语言 */ + static chooseLanguage( + /** 要设置的语言标识符 */ + language: string + ): void; + + /** 加载语言数据 */ + static loadLanguage( + /** 语言数据 */ + code: string, + /** 语言标识符 */ + language: string + ): void; + + /** 更新或创建语言文件 */ + static updateOrCreateLanguageFile( + /** 语言数据 */ + code: string, + /** 语言标识符 */ + language: string, + /** 文件路径 */ + path: string + ): void; + + /** 加载语言目录 */ + static loadLanguageDirectory( + /** 语言数据目录 */ + path: string + ): void; +} + +declare class UserCache { + private constructor(); + + /** 根据uuid查xuid */ + static getXuidByUuid( + /** uuid */ + uuid: string + ): string; + + /** 根据xuid查uuid */ + static getUuidByXuid( + /** xuid */ + xuid: string + ): string; + + /** 根据xuid查玩家名 */ + static getNameByUuid( + /** xuid */ + xuid: string + ): string; + + /** 根据xuid查玩家名 */ + static getNameByXuid( + /** xuid */ + xuid: string + ): string; + + /** 根据玩家名查xuid */ + static getXuidByName( + /** 玩家名 */ + name: string + ): string; + + /** 根据玩家名查uuid */ + static getUuidByName( + /** 玩家名 */ + name: string + ): string; + + /** 获取玩家信息 */ + static getPlayerInfo( + /** 玩家名 或 xuid 或 uuid */ + playerIdentifier: string + ): { Xuid: String, Uuid: string, Name: string } | null; + + /** 获取所有玩家信息 */ + static getAllPlayerInfo(): { Xuid: String; Uuid: string; Name: string; }[] +} + +interface Player { + /** (GMLIB)转换成实体对象 */ + toEntity(): Entity; + + /** (GMLIB)获取玩家重生坐标 */ + getSpawnPoint(): IntPos; + + /** (GMLIB)设置玩家重生坐标 */ + setSpawnPoint( + /** 要设置的坐标对象 */ + pos: IntPos + ): void; + + /** (GMLIB)清除玩家重生点 */ + clearSpawnPoint(): void; +} + +interface Entity { + /** (GMLIB)射弹投射物 */ + shootProjectile( + /** 投射物命名空间 */ + proj: string, + /** 速度 */ + speed: number | undefined, + /** 偏移量 */ + offset: number | undefined + ): boolean; + + /** (GMLIB)投掷实体 */ + throwEntity( + /** 投掷的实体对象 */ + proj: Entity, + /** 速度 */ + speed: number | undefined, + /** 偏移量 */ + offset: number | undefined + ): boolean; + + /** (GMLIB)获取实体翻译键名 */ + getTranslateKey(): string; + + /** (GMLIB)获取实体名字翻译 */ + getTranslateName( + /** 要翻译的语言 */ + langCode: string + ): string; + + /** (GMLIB)使玩家攻击实体 */ + attack( + /** 攻击的实体对象 */ + entity: Entity + ): boolean; + + /** (GMLIB) */ + pullInEntity( + /** 实体对象 */ + entity: Entity + ): boolean; +} + +interface Block { + /** (GMLIB)获取方块翻译键名 */ + getTranslateKey(): string; + + /** (GMLIB)获取方块名字翻译 */ + getTranslateName( + /** 要翻译的语言 */ + langCode: string + ): string; + + /** (GMLIB)获取方块硬度 */ + getBlockDestroySpeed(): number; + + /** (GMLIB)使方块被玩家挖掘 */ + playerDestroy( + /** 挖掘的玩家对象 */ + player: Player + ): void; + + /** (GMLIB) */ + canDropWithAnyTool(): boolean; + + /** (GMLIB)方块是否不需要工具采集 */ + isAlwaysDestroyable(): boolean; + + /** (GMLIB) */ + playerWillDestroy( + /** 挖掘的玩家对象 */ + player: Player + ): boolean; +} + +interface Item { + /** (GMLIB)获取方块翻译键名 */ + getTranslateKey(): string; + + /** (GMLIB)获取方块名字翻译 */ + getTranslateName( + /** 要翻译的语言 */ + langCode: string + ): string; + + /** (GMLIB)获取物品挖掘方块速度 */ + getDestroyBlockSpeed( + /** 挖掘的方块对象 */ + block: Block + ): number; + + /** (GMLIB)物品冒险模式下是否可以挖掘方块 */ + canDestroy( + /** 挖掘的方块对象 */ + block: Block + ): boolean; + + /** (GMLIB)物品是否能破坏方块 */ + canDestroyInCreative(): boolean; + + /** (GMLIB)物品是否可以采集方块 */ + canDestroySpecial( + /** 挖掘的方块对象 */ + block: Block + ): boolean; + + /** 获取物品可以拥有的附魔 */ + getLegalEnchants(): number[] + + /** 添加附魔 */ + applyEnchant( + /** 附魔ID */ + id: number, + /** 附魔等级 */ + level: number, + /** 允许非原版附魔 */ + allowNonVanilla: boolean | null + ): boolean; + + /** 删除所有附魔 */ + removeEnchants(): void; + + /** 判断是否拥有附魔 */ + hasEnchant( + /** 附魔ID */ + id: number + ): boolean; + + /** 获取附魔等级 */ + getEnchantLevel( + /** 附魔ID */ + id: number + ): number; +} \ No newline at end of file diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 4abe833..2d8b90a 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -1,139 +1,296 @@ +/** LRCA导出接口 */ const GMLIB_API = { + /** 创建悬浮字 @type {function(FloatPos,string,boolean):number} */ createFloatingText: ll.import("GMLIB_API", "createFloatingText"), + /** 删除悬浮字 @type {function(number):boolean} */ deleteFloatingText: ll.import("GMLIB_API", "deleteFloatingText"), + /** 设置悬浮字文本 @type {function(number,string):boolean} */ setFloatingTextData: ll.import("GMLIB_API", "setFloatingTextData"), + /** 发送悬浮字给玩家 @type {function(number,Player):boolean} */ sendFloatingTextToPlayer: ll.import("GMLIB_API", "sendFloatingTextToPlayer"), + /** 发送悬浮字给所有玩家 @type {function(number):boolean} */ sendFloatingText: ll.import("GMLIB_API", "sendFloatingText"), + /** 删除玩家的悬浮字 @type {function(number,Player):boolean} */ removeFloatingTextFromPlayer: ll.import("GMLIB_API", "removeFloatingTextFromPlayer"), + /** 删除所有玩家悬浮字 @type {function(number):boolean} */ removeFloatingText: ll.import("GMLIB_API", "removeFloatingText"), + /** 更新玩家的悬浮字 @type {function(number,Player):boolean} */ updateClientFloatingTextData: ll.import("GMLIB_API", "updateClientFloatingTextData"), + /** 更新所有玩家的悬浮字 @type {function(number):boolean} */ updateAllClientsFloatingTextData: ll.import("GMLIB_API", "updateAllClientsFloatingTextData"), + /** 获取服务器Mspt @type {function():number} */ getServerMspt: ll.import("GMLIB_API", "getServerMspt"), + /** 获取服务器当前tps @type {function():number} */ getServerCurrentTps: ll.import("GMLIB_API", "getServerCurrentTps"), + /** 获取服务器平均tps @type {function():number} */ getServerAverageTps: ll.import("GMLIB_API", "getServerAverageTps"), + /** 获取存档内所有玩家的uuid @type {function():Array} */ getAllPlayerUuids: ll.import("GMLIB_API", "getAllPlayerUuids"), + /** 获取玩家NBT @type {function(string):NbtCompound} */ getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"), + /** 设置玩家NBT @type {function(string,NbtCompound,boolean):boolean} */ setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"), + /** 覆盖玩家的特定nbtTags @type {function(string,NbtCompound,string):boolean} */ setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"), + /** 删除玩家所有的NBT @type {function(string):boolean} */ deletePlayerNbt: ll.import("GMLIB_API", "deletePlayerNbt"), + /** 使用特定语言翻译资源包文本 @type {function(string,Array.,string):string} */ resourcePackTranslate: ll.import("GMLIB_API", "resourcePackTranslate"), + /** 使用默认语言翻译资源包文本 @type {function(string,Array.):string} */ resourcePackDefaultTranslate: ll.import("GMLIB_API", "resourcePackDefaultTranslate"), + /** 获取资源包默认语言 @type {function():string} */ getResourcePackI18nLanguage: ll.import("GMLIB_API", "getResourcePackI18nLanguage"), + /** 设置资源包默认语言 @type {function(string):void} */ chooseResourcePackI18nLanguage: ll.import("GMLIB_API", "chooseResourcePackI18nLanguage"), + /** 启用教育版内容 @type {function():void} */ setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"), + /** 注册Ability命令 @type {function():void} */ registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"), + /** 启用Xbox成就 @type {function():void} */ setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"), + /** 信任所有玩家皮肤 @type {function():void} */ setForceTrustSkins: ll.import("GMLib_ServerAPI", "setForceTrustSkins"), + /** 资源包双端共存 @type {function():void} */ enableCoResourcePack: ll.import("GMLib_ServerAPI", "enableCoResourcePack"), + /** 获取存档名字 @type {function():string} */ getLevelName: ll.import("GMLib_ServerAPI", "getLevelName"), + /** 设置存档名字 @type {function(string):boolean} */ setLevelName: ll.import("GMLib_ServerAPI", "setLevelName"), + /** 设置假种子 @type {function(number):void} */ setFakeSeed: ll.import("GMLib_ServerAPI", "setFakeSeed"), + /** 强制生成实体 @type {function(FloatPos,string):Entity} */ spawnEntity: ll.import("GMLib_ServerAPI", "spawnEntity"), + /** 射弹投射物 @type {function(Entity,string,number,number):boolean} */ shootProjectile: ll.import("GMLib_ServerAPI", "shootProjectile"), + /** 投掷实体 @type {function(Entity,Entity,number,number):boolean} */ throwEntity: ll.import("GMLib_ServerAPI", "throwEntity"), + /** 根据玩家对象获取实体对象 @type {function(Player):Entity} */ PlayerToEntity: ll.import("GMLib_ServerAPI", "PlayerToEntity"), + /** 启用错误方块清理 @type {function():void} */ setUnknownBlockCleaner: ll.import("GMLib_ModAPI", "setUnknownBlockCleaner"), + /** 获取实验性功能ID列表 @type {function():Array} */ getAllExperiments: ll.import("GMLIB_API", "getAllExperiments"), + /** 获取实验性功能文本的键名 @type {function(number):string} */ getExperimentTranslateKey: ll.import("GMLIB_API", "getExperimentTranslateKey"), + /** 获取实验性功能启用状态 @type {function(number):boolean} */ getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"), + /** 设置实验性功能启用状态 @type {function(number,boolean):void} */ setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"), + /** 注销合成表 @type {function(string):boolean} */ unregisterRecipe: ll.import("GMLIB_API", "unregisterRecipe"), + /** 设置实验性依赖 @type {function(number):void} */ registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerExperimentsRequire"), + /** 注册切石机合成表 @type {function(string,string,number,string,number,number):boolean} */ registerStoneCutterRecipe: ll.import("GMLib_ModAPI", "registerStoneCutterRecipe"), + /** 注册锻造纹饰合成表 @type {function(string,string,string,string):boolean} */ registerSmithingTrimRecipe: ll.import("GMLib_ModAPI", "registerSmithingTrimRecipe"), + /** 注册锻造配方合成表 @type {function(string,string,string,string):boolean} */ registerSmithingTransformRecipe: ll.import("GMLib_ModAPI", "registerSmithingTransformRecipe"), + /** 注册酿造容器表 @type {function(string,string,string,string):boolean} */ registerBrewingContainerRecipe: ll.import("GMLib_ModAPI", "registerBrewingContainerRecipe"), + /** 注册酿造混合表 @type {function(string,string,string,string):boolean} */ registerBrewingMixRecipe: ll.import("GMLib_ModAPI", "registerBrewingMixRecipe"), + /** 注册熔炼合成表 @type {function(string,string,string,Array.):boolean} */ registerFurnaceRecipe: ll.import("GMLib_ModAPI", "registerFurnaceRecipe"), + /** 注册有序合成表 @type {function(string,Array.,Array.,string,number,string)} */ registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"), + /** 注册无序合成表 @type {function(string,Array.,Array.,string,number,string)} */ registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"), + /** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */ isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"), + /** 获取LRCA版本 @type {function():string} */ getVersion_LRCA: ll.import("GMLIB_API", "getVersion_LRCA"), + /** 获取GMLIB版本 @type {function():string} */ getVersion_GMLIB: ll.import("GMLIB_API", "getVersion_GMLIB"), + /** 获取玩家坐标 @type {function(string):IntPos} */ getPlayerPosition: ll.import("GMLIB_API", "getPlayerPosition"), + /** 设置玩家坐标 @type {function(string,IntPos):boolean} */ setPlayerPosition: ll.import("GMLIB_API", "setPlayerPosition"), + /** 玩家是否存在于计分板 @type {function(string,string):boolean} */ playerHasScore: ll.import("GMLIB_API", "playerHasScore"), + /** 获取玩家在计分板中的值 @type {function(string,string):number} */ getPlayerScore: ll.import("GMLIB_API", "getPlayerScore"), + /** 增加玩家在计分板中的值 @type {function(string,string,number):boolean} */ addPlayerScore: ll.import("GMLIB_API", "addPlayerScore"), + /** 减少玩家在计分板中的值 @type {function(string,string,number):boolean} */ reducePlayerScore: ll.import("GMLIB_API", "reducePlayerScore"), + /** 设置玩家在计分板中的值 @type {function(string,string,number):boolean} */ setPlayerScore: ll.import("GMLIB_API", "setPlayerScore"), + /** 重置玩家在计分板中的数据 @type {function(string,string):boolean} */ resetPlayerScore: ll.import("GMLIB_API", "resetPlayerScore"), + /** 重置玩家所有的计分板数据 @type {function(string):boolean} */ resetPlayerScores: ll.import("GMLIB_API", "resetPlayerScores"), + /** 实体是否存在于计分板中 @type {function(string,string):boolean} */ entityHasScore: ll.import("GMLIB_API", "entityHasScore"), + /** 获取实体在计分板中的值 @type {function(string,string):number} */ getEntityScore: ll.import("GMLIB_API", "getEntityScore"), + /** 增加实体在计分板中的值 @type {function(string,string,number):boolean} */ addEntityScore: ll.import("GMLIB_API", "addEntityScore"), + /** 减少实体在计分板中的值 @type {function(string,string,number):boolean} */ reduceEntityScore: ll.import("GMLIB_API", "reduceEntityScore"), + /** 设置实体在计分板中的值 @type {function(string,string,number):boolean} */ setEntityScore: ll.import("GMLIB_API", "setEntityScore"), + /** 重置实体在计分板中的数据 @type {function(string,string):boolean} */ resetEntityScore: ll.import("GMLIB_API", "resetEntityScore"), + /** 重置实体所有的计分板数据 @type {function(string):boolean} */ resetEntityScores: ll.import("GMLIB_API", "resetEntityScores"), + /** 字符串是否存在于计分板 @type {function(string,string):boolean} */ fakePlayerHasScore: ll.import("GMLIB_API", "fakePlayerHasScore"), + /** 获取字符串在计分板中的值 @type {function(string,string):number} */ getFakePlayerScore: ll.import("GMLIB_API", "getFakePlayerScore"), + /** 增加字符串在计分板中的值 @type {function(string,string,number):boolean} */ addFakePlayerScore: ll.import("GMLIB_API", "addFakePlayerScore"), + /** 减少字符串在计分板中的值 @type {function(string,string,number):boolean} */ reduceFakePlayerScore: ll.import("GMLIB_API", "reduceFakePlayerScore"), + /** 设置字符串在计分板中的值 @type {function(string,string,number):boolean} */ setFakePlayerScore: ll.import("GMLIB_API", "setFakePlayerScore"), + /** 重置字符串在计分板中的数据 @type {function(string,string):boolean} */ resetFakePlayerScore: ll.import("GMLIB_API", "resetFakePlayerScore"), + /** 重置字符串所有的计分板数据 @type {function(string):boolean} */ resetFakePlayerScores: ll.import("GMLIB_API", "resetFakePlayerScores"), + /** 创建计分板 @type {function(string):boolean} */ addObjective: ll.import("GMLIB_API", "addObjective"), + /** 创建带有显示名称的计分板 @type {function(string,string):boolean} */ addObjectiveWithDisplayName: ll.import("GMLIB_API", "addObjectiveWithDisplayName"), + /** 获取计分板显示名字 @type {function(string):string} */ getDisplayName: ll.import("GMLIB_API", "getDisplayName"), + /** 设置计分板显示名字 @type {function(string,string):boolean} */ setDisplayName: ll.import("GMLIB_API", "setDisplayName"), + /** 删除计分板 @type {function(string):boolean} */ removeObjective: ll.import("GMLIB_API", "removeObjective"), + /** 设置计分板显示 @type {function(string,"list"|"sidebar"|"belowname",0|1):void} */ setDisplayObjective: ll.import("GMLIB_API", "setDisplayObjective"), + /** 清除计分板显示 @type {function("list"|"sidebar"|"belowname"):void} */ clearDisplayObjective: ll.import("GMLIB_API", "clearDisplayObjective"), + /** 获取所有计分板 @type {function():Array.} */ getAllObjectives: ll.import("GMLIB_API", "getAllObjectives"), + /** 获取所有跟踪目标 @type {function():Array.<{"Type":"Player","Uuid":string}|{"Type":"FakePlayer","Name":string}|{"Type":"Entity","UniqueId":string}>} */ getAllTrackedTargets: ll.import("GMLIB_API", "getAllTrackedTargets"), + /** 获取所有跟踪玩家 @type {function():Array.} */ getAllScoreboardPlayers: ll.import("GMLIB_API", "getAllScoreboardPlayers"), + /** 获取所有跟踪字符串 @type {function():Array.} */ getAllScoreboardFakePlayers: ll.import("GMLIB_API", "getAllScoreboardFakePlayers"), + /** 获取所有跟踪实体 @type {function():Array.} */ getAllScoreboardEntities: ll.import("GMLIB_API", "getAllScoreboardEntities"), + /** 根据uuid获取玩家对象 @type {function(string):Player} */ getPlayerFromUuid: ll.import("GMLIB_API", "getPlayerFromUuid"), + /** 根据UniqueId获取玩家对象 @type {function(string):Player} */ getPlayerFromUniqueId: ll.import("GMLIB_API", "getPlayerFromUniqueId"), + /** 根据UniqueId获取实体对象 @type {function(string):Entity} */ getEntityFromUniqueId: ll.import("GMLIB_API", "getEntityFromUniqueId"), + /** 获取世界出生点 @type {function():IntPos} */ getWorldSpawn: ll.import("GMLIB_API", "getWorldSpawn"), + /** 设置世界出生点 @type {function(IntPos):void} */ setWorldSpawn: ll.import("GMLIB_API", "setWorldSpawn"), + /** 获取玩家重生点 @type {function(Player):IntPos} */ getPlayerSpawnPoint: ll.import("GMLIB_API", "getPlayerSpawnPoint"), + /** 设置玩家重生点 @type {function(Player,IntPos):void} */ setPlayerSpawnPoint: ll.import("GMLIB_API", "setPlayerSpawnPoint"), + /** 清除玩家重生点 @type {function(Player):void} */ clearPlayerSpawnPoint: ll.import("GMLIB_API", "clearPlayerSpawnPoint"), + /** 设置资源包路径 @type {function(string):void} */ setCustomPackPath: ll.import("GMLIB_API", "setCustomPackPath"), + /** 获取支持的语言标识符 @type {function():Array.} */ getSupportedLanguages: ll.import("GMLIB_API", "getSupportedLanguages"), + /** 加载语言翻译 @type {function(string,string):void} */ loadLanguage: ll.import("GMLIB_API", "loadLanguage"), + /** 更新或创建语言文件 @type {function(string,string,string):void} */ updateOrCreateLanguageFile: ll.import("GMLIB_API", "updateOrCreateLanguageFile"), + /** 加载语言文件目录 @type {function(string):void} */ loadLanguagePath: ll.import("GMLIB_API", "loadLanguagePath"), + /** 合并json @type {function(string,string):string} */ mergePatchJson: ll.import("GMLIB_API", "mergePatchJson"), + /** 根据uuid获取xuid @type {function(string):string} */ getXuidByUuid: ll.import("GMLIB_API", "getXuidByUuid"), + /** 根据uuid获取名字 @type {function(string):string} */ getNameByUuid: ll.import("GMLIB_API", "getNameByUuid"), + /** 根据xuid获取uuid @type {function(string):string} */ getUuidByXuid: ll.import("GMLIB_API", "getUuidByXuid"), + /** 根据xuid获取名字 @type {function(string):string} */ getNameByXuid: ll.import("GMLIB_API", "getNameByXuid"), + /** 根据名字获取xuid @type {function(string):string} */ getXuidByName: ll.import("GMLIB_API", "getXuidByName"), + /** 根据名字获取uuid @type {function(string):string} */ getUuidByName: ll.import("GMLIB_API", "getUuidByName"), + /** 获取所有已记录的玩家信息 @type {function():Array.<{"Uuid":string,"Xuid":string,"Name":string}>} */ getAllPlayerInfo: ll.import("GMLIB_API", "getAllPlayerInfo"), + /** 获取方块RuntimeId @type {function(string,number):number} */ getBlockRuntimeId: ll.import("GMLIB_API", "getBlockRuntimeId"), + /** 添加虚假列表玩家 @type {function(string,string):boolean} */ addFakeList: ll.import("GMLIB_API", "addFakeList"), + /** 删除虚假列表玩家 @type {function(string):boolean} */ removeFakeList: ll.import("GMLIB_API", "removeFakeList"), + /** 删除所有虚假列表玩家 @type {function():void} */ removeAllFakeLists: ll.import("GMLIB_API", "removeAllFakeList"), + /** 启用I18n修复 @type {function():void} */ setFixI18nEnabled: ll.import("GMLib_ModAPI", "setFixI18nEnabled"), + /** 获取方块翻译键名 @type {function(Block):string} */ getBlockTranslateKey: ll.import("GMLIB_API", "getBlockTranslateKey"), + /** 获取物品翻译键名 @type {function(Item):string} */ getItemTranslateKey: ll.import("GMLIB_API", "getItemTranslateKey"), + /** 获取实体翻译键名 @type {function(Entity):string} */ getEntityTranslateKey: ll.import("GMLIB_API", "getEntityTranslateKey"), + /** 从文件中读取NBT @type {function(string,boolean):NbtCompound} */ readNbtFromFile: ll.import("GMLIB_API", "readNbtFromFile"), + /** 保存NBT至文件 @type {function(string,NbtCompound,boolean):void} */ saveNbtToFile: ll.import("GMLIB_API", "saveNbtToFile"), + /** 获取方块硬度 @type {function(Block):number} */ getBlockDestroySpeed: ll.import("GMLIB_API", "getBlockDestroySpeed"), + /** 获取物品挖掘方块速度 @type {function(Item,Block):number} */ getDestroyBlockSpeed: ll.import("GMLIB_API", "getDestroyBlockSpeed"), + /** 使玩家挖掘方块 @type {function(Block,IntPos,Player):void} */ playerDestroyBlock: ll.import("GMLIB_API", "playerDestroyBlock"), + /** 物品冒险模式下是否可以挖掘方块 @type {function(Item,Block):boolean} */ itemCanDestroyBlock: ll.import("GMLIB_API", "itemCanDestroyBlock"), + /** 物品是否能破坏方块 @type {function(Item):boolean} */ itemCanDestroyInCreative: ll.import("GMLIB_API", "itemCanDestroyInCreative"), + /** 物品是否可以采集方块 @type {function(Item,Block):boolean} */ itemCanDestroySpecial: ll.import("GMLIB_API", "itemCanDestroySpecial"), + /** @type {function(Block):boolean} */ blockCanDropWithAnyTool: ll.import("GMLIB_API", "blockCanDropWithAnyTool"), + /** 方块是否不需要工具采集 @type {function(Block):boolean} */ blockIsAlwaysDestroyable: ll.import("GMLIB_API", "blockIsAlwaysDestroyable"), + /** @type {function(Block,Player,IntPos):boolean} */ blockPlayerWillDestroy: ll.import("GMLIB_API", "blockPlayerWillDestroy"), + /** 使玩家攻击实体 @type {function(Entity,Player):boolean} */ playerAttack: ll.import("GMLIB_API", "playerAttack"), + /** @type {function(Player,Entity):boolean} */ playerPullInEntity: ll.import("GMLIB_API", "playerPullInEntity"), - getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName") + /** 根据命令空间获取翻译键名 @type {function(string):string} */ + getBlockTranslateKeyFromName: ll.import("GMLIB_API", "getBlockTranslateKeyFromName"), + /** 获取存档种子号 @type {function():string} */ + getLevelSeed: ll.import("GMLib_ServerAPI", "getLevelSeed"), + /** 获取方块亮度 @type {function(string,number):number} */ + getBlockLightEmission: ll.import("GMLIB_API", "getBlockLightEmission"), + /** 获取游戏规则列表 @type {function():Array.<{Name:string,Value:string,Type:"Bool"|"Float"|"Int"}>} */ + getGameRules: ll.import("GMLIB_API", "getGameRules"), + /** 获取物品可以拥有的附魔 @type {function(Item):Array.} */ + getLegalEnchants: ll.import("GMLIB_API", "getLegalEnchants"), + /** 给物品添加附魔 @type {function(Item,number,number,boolean):boolean} */ + applyEnchant: ll.import("GMLIB_API", "applyEnchant"), + /** 删除物品所有附魔 @type {function(Item):void} */ + removeEnchants: ll.import("GMLIB_API", "removeEnchants"), + /** 判断物品是否拥有附魔 @type {function(Item,number):boolean} */ + hasEnchant: ll.import("GMLIB_API", "hasEnchant"), + /** 获取附魔等级 @type {function(Item,number):number} */ + getEnchantLevel: ll.import("GMLIB_API", "getEnchantLevel"), + /** 获取附魔名字 @type {function(number,number):number} */ + getEnchantNameAndLevel: ll.import("GMLIB_API", "getEnchantNameAndLevel") } +/** 静态悬浮字类列表 @type {Map} */ const mStaticFloatingTextMap = new Map(); +/** 动态悬浮字类列表 @type {Map} */ const mDynamicFloatingTextMap = new Map(); +/** 静态悬浮字类 */ class StaticFloatingText { + /** + * 构造函数 + * @param {FloatPos} pos 要生成的坐标 + * @param {string} text 悬浮字文本 + * @param {boolean?} [papi=true] 是否使用PAPI变量 + */ constructor(pos, text, papi = true) { this.mPosition = pos; this.mText = text; @@ -142,61 +299,122 @@ class StaticFloatingText { mStaticFloatingTextMap.set(this.mRuntimeId, this); } + /** + * 发送悬浮字给玩家 + * @param {Player} player 玩家对象 + * @returns {boolean} 是否成功发送 + */ sendToClient(player) { return GMLIB_API.sendFloatingTextToPlayer(this.mRuntimeId, player); } + /** + * 发送悬浮字给所有玩家 + * @returns {boolean} 是否成功发送 + */ sendToClients() { return GMLIB_API.sendFloatingText(this.mRuntimeId); } + /** + * 删除玩家的悬浮字 + * @param {Player} player 玩家对象 + * @returns {boolean} 是否成功删除 + */ removeFromClient(player) { return GMLIB_API.removeFloatingTextFromPlayer(this.mRuntimeId, player); } + /** + * 删除所有玩家悬浮字 + * @returns {boolean} 是否成功删除 + */ removeFromClients() { return GMLIB_API.removeFloatingText(this.mRuntimeId); } + /** + * 更新玩家的悬浮字 + * @param {Player} player 玩家对象 + * @returns {boolean} 是否成功更新 + */ updateClient(player) { return GMLIB_API.updateClientFloatingTextData(this.mRuntimeId, player); } + /** + * 更新所有玩家的悬浮字 + * @returns {boolean} 是否成功更新 + */ updateClients() { return GMLIB_API.updateAllClientsFloatingTextData(this.mRuntimeId); } + /** + * 获取悬浮字的RuntimeId + * @returns {number} 悬浮字的RuntimeId + */ getRuntimeId() { return this.mRuntimeId; } + /** + * 获取悬浮字显示的文本 + * @returns {IntPos} 悬浮字显示的文本 + */ getText() { return this.mText; } + /** + * 设置悬浮字显示的文本 + * @param {string} newText 要显示的文本 + */ setText(newText) { this.mText = newText; } + /** + * 更新所有玩家的悬浮字 + * @returns {boolean} 是否成功更新 + */ update() { GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText); return this.updateClients(); } + /** + * 更新悬浮字文本 + * @param {string} newText 要显示的文本 + * @returns {boolean} 是否成功更新 + */ updateText(newText) { this.setText(newText); return this.update(); } + /** + * 获取悬浮字的坐标 + * @returns {FlatPos} 悬浮字的坐标 + */ getPos() { return this.mPosition; } + /** + * 删除悬浮字 + * @returns {boolean} 是否成功删除 + */ destroy() { mStaticFloatingTextMap.delete(this.mRuntimeId); return GMLIB_API.deleteFloatingText(this.mRuntimeId); } + /** + * 根据RuntimeId获取静态悬浮字 + * @param {number} runtimeId 悬浮字的RuntimeId + * @returns {StaticFloatingText|null} 悬浮字对象 + */ static getFloatingText(runtimeId) { if (mStaticFloatingTextMap.has(runtimeId)) { return mStaticFloatingTextMap.get(runtimeId); @@ -204,6 +422,10 @@ class StaticFloatingText { return null; } + /** + * 获取所有静态悬浮字 + * @returns {Array} 所有悬浮字对象 + */ static getAllFloatingTexts() { let result = []; mStaticFloatingTextMap.forEach((ft) => { @@ -213,7 +435,15 @@ class StaticFloatingText { } } +/** 动态悬浮字类 */ class DynamicFloatingText extends StaticFloatingText { + /** + * 创建一个动态悬浮字 + * @param {FlatPos} pos 悬浮字的坐标 + * @param {string} text 悬浮字显示的文本 + * @param {number} [updateRate=1] 更新频率(秒) + * @param {boolean} [papi=true] 是否使用PAPI变量 + */ constructor(pos, text, updateRate = 1, papi = true) { this.mPosition = pos; this.mText = text; @@ -225,16 +455,28 @@ class DynamicFloatingText extends StaticFloatingText { this.startUpdate(); } + /** + * 获取悬浮字更新频率 + * @returns {number} 更新频率,单位为秒 + */ getUpdateRate() { return this.mUpdateRate; } + /** + * 设置悬浮字更新频率 + * @param {number} updateRate 更新频率,单位为秒 + */ setUpdateRate(updateRate = 1) { this.stopUpdate(); this.mUpdateRate = updateRate; this.startUpdate(); } + /** + * 开始更新悬浮字 + * @returns {boolean} 是否成功开始更新 + */ startUpdate() { if (this.mTaskId == null) { this.mTaskId = setInterval(() => { @@ -245,6 +487,10 @@ class DynamicFloatingText extends StaticFloatingText { return false; } + /** + * 停止更新悬浮字 + * @returns {boolean} 是否成功停止更新 + */ stopUpdate() { if (this.mTaskId) { clearInterval(this.mTaskId); @@ -254,11 +500,20 @@ class DynamicFloatingText extends StaticFloatingText { return false; } + /** + * 删除悬浮字 + * @returns {boolean} 是否成功删除 + */ destroy() { mDynamicFloatingTextMap.delete(this.mRuntimeId); return GMLIB_API.deleteFloatingText(this.mRuntimeId); } + /** + * 根据runtimeId获取动态悬浮字对象 + * @param {number} runtimeId 悬浮字的RuntimeId + * @returns {DynamicFloatingText} 悬浮字对象 + */ static getFloatingText(runtimeId) { if (mDynamicFloatingTextMap.has(runtimeId)) { return mDynamicFloatingTextMap.get(runtimeId); @@ -266,6 +521,10 @@ class DynamicFloatingText extends StaticFloatingText { return null; } + /** + * 获取所有动态悬浮字 + * @returns {Array} 所有悬浮字对象 + */ static getAllFloatingTexts() { let result = []; mDynamicFloatingTextMap.forEach((ft) => { @@ -275,43 +534,89 @@ class DynamicFloatingText extends StaticFloatingText { } } +/** 基础游戏API类 */ class Minecraft { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 获取服务器平均tps + * @returns {number} 服务器平均tps + */ static getServerAverageTps() { return GMLIB_API.getServerAverageTps(); } + /** + * 获取服务器当前tps + * @returns {number} 服务器当前tps + */ static getServerCurrentTps() { return GMLIB_API.getServerCurrentTps(); } + /** + * 获取服务器mspt + * @returns {number} 服务器mspt + */ static getServerMspt() { return GMLIB_API.getServerMspt(); } + /** + * 获取所有玩家uuid + * @returns {Array} 所有玩家uuid + */ static getAllPlayerUuids() { return GMLIB_API.getAllPlayerUuids(); } + /** + * 获取玩家NBT + * @param {string} uuid 玩家的uuid + * @returns {NbtCompound} 玩家的NBT + */ static getPlayerNbt(uuid) { return GMLIB_API.getPlayerNbt(uuid); } + /** + * 写入玩家NBT + * @param {string} uuid 玩家的uuid + * @param {NbtCompound} nbt 要写入的NBT + * @param {boolean?} [forceCreate=true] 不存在是否创建 + * @returns {boolean} 是否成功写入NBT + */ static setPlayerNbt(uuid, nbt, forceCreate = true) { return GMLIB_API.setPlayerNbt(uuid, nbt, forceCreate); } + /** + * 覆盖玩家NBT的特定Tags + * @param {string} uuid 玩家的uuid + * @param {NbtCompound} nbt 要写入的NBT + * @param {string} tags 要覆盖的NBT标签 + * @returns {boolean} 是否成功写入NBT + */ static setPlayerNbtTags(uuid, nbt, tags) { return GMLIB_API.setPlayerNbtTags(uuid, nbt, tags); } + /** + * 删除玩家NBT + * @param {string} uuid 玩家的uuid + * @returns {boolean} 是否成功删除NBT + */ static deletePlayerNbt(uuid) { return GMLIB_API.deletePlayerNbt(uuid); } + /** + * 获取玩家坐标 + * @param {string} uuid 玩家的uuid + * @returns {IntPos|null} 玩家坐标 + */ static getPlayerPosition(uuid) { let pos = GMLIB_API.getPlayerPosition(uuid); if (pos.dimid == -1) { @@ -320,204 +625,508 @@ class Minecraft { return pos; } + /** + * 设置玩家坐标 + * @param {string} uuid 玩家的uuid + * @param {IntPos} pos 要设置的坐标 + * @returns {boolean} 是否成功设置玩家坐标 + */ static setPlayerPosition(uuid, pos) { return GMLIB_API.setPlayerPosition(uuid, pos); } + /** + * 获取世界出生点 + * @returns {IntPos} 世界坐标 + */ static getWorldSpawn() { return GMLIB_API.getWorldSpawn(); } + /** + * 设置世界出生点 + * @param {IntPos} pos 要设置的出生点坐标 + */ static setWorldSpawn(pos) { - return GMLIB_API.setWorldSpawn(pos); + GMLIB_API.setWorldSpawn(pos); } + /** + * 启用教育版内容 + */ static setEducationFeatureEnabled() { - return GMLIB_API.setEducationFeatureEnabled(); + GMLIB_API.setEducationFeatureEnabled(); } + /** + * 注册Ability命令 + */ static registerAbilityCommand() { - return GMLIB_API.registerAbilityCommand(); + GMLIB_API.registerAbilityCommand(); } + /** + * 启用Xbox成就 + */ static setEnableAchievement() { - return GMLIB_API.setEnableAchievement(); + GMLIB_API.setEnableAchievement(); } + /** + * 信任所有玩家皮肤 + */ static setForceTrustSkins() { - return GMLIB_API.setForceTrustSkins(); + GMLIB_API.setForceTrustSkins(); } + /** + * 启用资源包双端共存 + */ static enableCoResourcePack() { - return GMLIB_API.enableCoResourcePack(); + GMLIB_API.enableCoResourcePack(); } + /** + * 获取存档名称 + * @returns {string} 世界名称 + */ static getWorldName() { return GMLIB_API.getLevelName(); } + /** + * 设置存档名称 + * @param {string} name 世界名称 + * @returns {boolean} 是否成功设置世界名称 + */ static setWorldName(name) { return GMLIB_API.setLevelName(name); } + /** + * 设置假种子 + * @param {Number?} [seed=114514] seed 要设置的假种子 + */ static setFakeSeed(seed = 114514) { - return GMLIB_API.setFakeSeed(seed); + GMLIB_API.setFakeSeed(seed); } + /** + * 启用错误方块清理 + */ static setUnknownBlockCleaner() { - return GMLIB_API.setUnknownBlockCleaner(); + GMLIB_API.setUnknownBlockCleaner(); } + /** + * 强制生成实体 + * @param {FloatPos} pos 要生成的坐标 + * @param {string} name 实体命名空间 + * @returns {boolean} 是否成功生成实体 + */ static spawnEntity(pos, name) { return GMLIB_API.spawnEntity(pos, name); } + /** + * 射弹投射物 + * @param {Entity} entity 实体对象 + * @param {string} proj 投射物命名空间 + * @param {number} [speed=2] 速度 + * @param {number} [offset=3] 偏移量 + * @returns {boolean} 是否成功投射投射物 + */ static shootProjectile(entity, proj, speed = 2, offset = 3) { return GMLIB_API.shootProjectile(entity, proj, speed, offset); } + /** + * 投掷实体 + * @param {Entity} entity 实体对象 + * @param {Entity} proj 被投掷的实体 + * @param {number} [speed=2] 速度 + * @param {number} [offset=3] 偏移量 + * @returns {boolean} 是否成功投射投射物 + */ static throwEntity(entity, proj, speed = 2, offset = 3) { return GMLIB_API.throwEntity(entity, proj, speed = 2, offset = 3); } + /** + * 获取服务器使用的语言 + * @returns {string} 服务器使用的语言 + */ static getServerLanguage() { return I18nAPI.getCurrentLanguage(); } + /** + * 设置服务器使用的语言 + * @param {string} language 语言标识符 + * @returns {boolean} 是否成功设置服务器使用的语言 + */ static setServerLanguage(language) { return I18nAPI.chooseLanguage(language); } + /** + * 设置资源包路径 + * @param {string} path 资源包路径 + * @returns {boolean} 是否成功设置资源包路径 + */ static setCustomPackPath(path) { GMLIB_API.setCustomPackPath(path); } + /** + * 翻译资源包文本 + * @param {string} key 键名 + * @param {Array.} params 翻译参数 + * @returns {string} 翻译后的文本 + */ static resourcePackTranslate(key, params = []) { return I18nAPI.get(key, params); } + /** + * 根据uuid获取玩家对象 + * @param {string} uuid 玩家的uuid + * @returns {Player} 玩家对象 + */ static getPlayerFromUuid(uuid) { return GMLIB_API.getPlayerFromUuid(uuid); } + /** + * 根据UniqueId获取玩家对象 + * @param {string} uniqueId 玩家的UniqueId + * @returns {Player} 玩家对象 + */ static getPlayerFromUniqueId(uniqueId) { return GMLIB_API.getPlayerFromUniqueId(uniqueId); } + /** + * 根据UniqueId获取实体对象 + * @param {string} uniqueId 实体的UniqueId + * @returns {Entity} 实体对象 + */ static getEntityFromUniqueId(uniqueId) { - return GMLIB_API.getFromUniqueId(uniqueId); + return GMLIB_API.getEntityFromUniqueId(uniqueId); } - static getBlockRuntimeId(block) { - return GMLIB_API.getBlockRuntimeId(block); + /** + * 获取方块runtimeId + * @param {string} block 方块命名空间 + * @param {number} [legacyData=0] 方块的特殊值 + * @returns {number} 方块的runtimeId + */ + static getBlockRuntimeId(block, legacyData = 0) { + return GMLIB_API.getBlockRuntimeId(block, legacyData); } + /** + * 添加虚假列表玩家 + * @param {string} name 虚假玩家的名字 + * @param {string} xuid 虚假玩家的xuid + * @returns {boolean} 是否成功添加 + */ static addFakeList(name, xuid) { return GMLIB_API.addFakeList(name, xuid); } + /** + * 移除虚假列表玩家 + * @param {string} nameOrXuid 虚假的玩家名字或xuid + * @returns {boolean} 是否成功移除 + */ static removeFakeList(nameOrXuid) { return GMLIB_API.removeFakeList(nameOrXuid); } + /** + * 移除所有虚假列表玩家 + * @returns {boolean} 是否成功移除 + */ static removeAllFakeLists() { return GMLIB_API.removeAllFakeLists(); } + /** + * 启用I18n修复 + */ static setFixI18nEnabled() { GMLIB_API.setFixI18nEnabled(); } + /** + * 保存NBT至文件 + * @param {string} path 文件路径 + * @param {NbtCompound} nbt NBT对象 + * @param {boolean} [isBinary=true] 是否为写入为二进制文件 + * @returns + */ static saveNbtToFile(path, nbt, isBinary = true) { return GMLIB_API.saveNbtToFile(path, nbt, isBinary); } + /** + * 从文件读取NBT + * @param {string} path 文件路径 + * @param {boolean} [isBinary=true] 是否为读取为二进制文件 + * @returns {NbtCompound} NBT对象 + */ static readNbtFromFile(path, isBinary = true) { return GMLIB_API.readNbtFromFile(path, isBinary); } + /** + * 根据命名空间获取翻译键名 + * @param {string} name 方块的命名空间 + * @returns {string} 方块的翻译键名 + */ static getBlockTranslateKeyFromName(name) { return GMLIB_API.getBlockTranslateKeyFromName(name); } + + /** + * 获取存档种子号 + */ + static getLevelSeed() { + return GMLIB_API.getLevelSeed(); + } + + /** + * 获取方块亮度 + * @param {string} block 方块的命名空间 + * @param {number} [legacyData=0] 方块的特殊值 + * @returns {number} 方块的亮度(-1为不存在) + */ + static getBlockLightEmission(block, legacyData = 0) { + return GMLIB_API.getBlockLightEmission(block, legacyData) + } + + /** + * 获取游戏规则列表 + * @returns {Array.<{Name:string,Value:boolean|number}>} + */ + static getGameRules() { + const gameRules = GMLIB_API.getGameRules(); + let result = []; + for (const gameRule of gameRules) { + if (gameRule.Type === "Bool") { + result.push({ + "Name": gameRule.Name, + "Value": gameRule.Value == "1" ? true : false + }); + } else { + result.push({ + "Name": gameRule.Name, + "Value": JSON.parse(gameRule.Value) + }); + } + } + return result; + } + + /** + * 获取附魔名字和等级 + * @param {number} id 附魔ID + * @param {number} level 附魔等级 + * @returns {string} 文本 + */ + static getEnchantNameAndLevel(id, level) { + return GMLIB_API.getEnchantNameAndLevel(id, level); + } } +/** 合成表类 */ class Recipes { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 注销合成表 + * @param {string} recipeId 合成表唯一标识符 + * @returns {boolean} 是否注销成功 + */ static unregisterRecipe(recipeId) { return GMLIB_API.unregisterRecipe(recipeId); } + /** + * 注册切石机合成表 + * @param {string} recipeId 合成表唯一标识符 + * @param {string} inputName 输入物品 + * @param {number} inputAux 输入物品额外数据 + * @param {string} outputName 合成结果 + * @param {number} outputAux 合成结果额外数据 + * @param {number} outputCount 合成结果数量 + * @returns {boolean} 是否注册成功 + */ static registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount) { return GMLIB_API.registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount); } + /** + * 注册锻造纹饰合成表 + * @param {string} recipeId 合成表唯一标识符 + * @param {string} template 锻造模板 + * @param {string} base 基础材料 + * @param {string} addition 纹饰材料 + * @returns {boolean} 是否注册成功 + */ static registerSmithingTrimRecipe(recipeId, template, base, addition) { return GMLIB_API.registerSmithingTrimRecipe(recipeId, template, base, addition); } + /** + * 注册锻造配方合成表 + * @param {string} recipeId 合成表唯一标识符 + * @param {string} template 锻造模板 + * @param {string} base 基础物品 + * @param {string} addition 升级材料 + * @param {string} result 合成结果 + * @returns {boolean} 是否注册成功 + */ static registerSmithingTransformRecipe(recipeId, template, base, addition, result) { return GMLIB_API.registerSmithingTransformRecipe(recipeId, template, base, addition, result); } + /** + * 注册酿造容器表 + * @param {string} recipeId 合成表唯一标识符 + * @param {string} input 输入物品 + * @param {string} output 合成结果 + * @param {string} reagent 酿造物品 + * @returns {boolean} 是否注册成功 + */ static registerBrewingContainerRecipe(recipeId, input, output, reagent) { return GMLIB_API.registerBrewingContainerRecipe(recipeId, input, output, reagent); } + /** + * 注册酿造混合表 + * @param {string} recipeId 合成表唯一标识 + * @param {string} input 输入物品(必须是原版药水物品id) + * @param {string} output 合成结果(必须是原版药水物品id) + * @param {string} reagent 酿造物品 + * @returns {boolean} 是否注册成功 + */ static registerBrewingMixRecipe(recipeId, input, output, reagent) { return GMLIB_API.registerBrewingMixRecipe(recipeId, input, output, reagent); } - // tags ["furnace", "blast_furnace", "smoker", "campfire", "soul_campfire"] + /** + * 注册熔炼合成表 + * @param {string} recipeId 合成表唯一标识 + * @param {string} input 输入材料 + * @param {string} output 合成结果 + * @param {Array.<"furnace"|"blast_furnace"|"smoker"|"campfire"|"soul_campfire">} [tags=["furnace"]] 材料的标签数组 + * @returns {boolean} 是否注册成功 + */ static registerFurnaceRecipe(recipeId, input, output, tags = ["furnace"]) { return GMLIB_API.registerFurnaceRecipe(recipeId, input, output, tags); } - // unlock : "AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None", Item ID + /** + * 注册有序合成表 + * @param {string} recipeId 合成表唯一标识 + * @param {[string,string,string]} shape 合成表摆放方式,数组元素为字符串 + * @param {Array.} ingredients 材料数组 + * @param {string} result 合成结果 + * @param {string} [count=1] 合成结果的数量 + * @param {"AlwaysUnlocked"|"PlayerHasManyItems"|"PlayerInWater"|"None"} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间) + * @returns {boolean} 是否注册成功 + */ static registerShapedRecipe(recipeId, shape, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock); } + /** + * 注册无序合成表 + * @param {string} recipeId 合成表唯一标识 + * @param {Array.} ingredients 合成材料 + * @param {string} result 合成结果 + * @param {number} [count=1] 合成数量 + * @param {"AlwaysUnlocked"|"PlayerHasManyItems"|"PlayerInWater"|"None"} [unlock=AlwaysUnlocked] 解锁条件(也可以填物品命名空间) + * @returns {boolean} 是否注册成功 + */ static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock); } } +/** 实验性功能类 */ class Experiments { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 获取所有实验的id + * @returns {Array.} 所有实验的id + */ static getAllExperimentIds() { return GMLIB_API.getAllExperiments(); } - + /** + * 获取实验性功能文本的键名 + * @param {number} id 实验性功能的id + * @returns {string} 实验性功能文本的键名 + */ static getExperimentTranslateKey(id) { return GMLIB_API.getExperimentTranslateKey(id); } + /** + * 获取实验性功能启用状态 + * @param {number} id 实验性功能的id + * @returns {boolean} 实验性功能是否开启 + */ static getExperimentEnabled(id) { return GMLIB_API.getExperimentEnabled(id); } + /** + * 设置实验性功能启用状态 + * @param {number} id 实验性功能的id + * @param {boolean?} [value=true] 实验性功能是否开启 + */ static setExperimentEnabled(id, value = true) { - return GMLIB_API.setExperimentEnabled(id, value); + GMLIB_API.setExperimentEnabled(id, value); } + /** + * 设置实验性依赖 + * @param {number} id 实验性功能的id + */ static registerExperimentsRequire(id) { - return GMLIB_API.registerExperimentsRequire(id); + GMLIB_API.registerExperimentsRequire(id); } } +/** 版本类 */ class Version { + /** + * 创建版本对象 + * @param {number} major 主版本号 + * @param {number} minor 次版本号 + * @param {number} patch 修订版本号 + * @constructor + */ constructor(major, minor, patch) { this.mMajor = major; this.mMinor = minor; this.mPatch = patch; } + /** + * 转换成字符串 + * @param {boolean} [prefix=true] 是否添加前缀"v" + * @returns {string} 版本字符串 + */ toString(prefix = true) { let result = `${this.mMajor}.${this.mMinor}.${this.mPatch}`; if (prefix) { @@ -526,16 +1135,29 @@ class Version { return result; } + /** + * 转换成数组 + * @returns {[number,number,number]} 版本数组 + */ toArray() { return [this.mMajor, this.mMinor, this.mPatch]; } + /** + * 转换成数字 + * @returns {number} 版本数字 + */ valueOf() { return 100000000 * this.mMajor + 10000 * this.mMinor + this.mPatch; } + /** + * 从字符串中创建版本对象 + * @param {string} version 版本号字符串 + * @returns {Version|null} 版本对象 + */ static fromString(string) { - if (typeof string === 'string' || string instanceof String) { + if (typeof string === "string" || string instanceof String) { let pattern = /^v?\d+\.\d+\.\d+$/; if (pattern.test(string)) { let regex = /\d+/g; @@ -547,6 +1169,11 @@ class Version { return null; } + /** + * 从数组中创建版本对象 + * @param {[number,number,number]} array 版本号数组 + * @returns {Version|null} 版本对象 + */ static fromArray(array) { if (Array.isArray(array) && array.length == 3) { let isNumber = array.every(element => typeof element == "number"); @@ -557,42 +1184,76 @@ class Version { return null; } + /** + * 检测LRCA版本是否大于或等于此版本 + * @param {Version} version 版本对象 + * @returns {boolean} 检测结果 + */ static isPluginVersionMatched(version) { return GMLIB_API.isVersionMatched(version.mMajor, version.mMinor, version.mPatch); } + /** + * 获取LRCA版本号对象 + * @returns {Version} 版本对象 + */ static getLrcaVersion() { return Version.fromString(GMLIB_API.getVersion_LRCA()); } + /** + * 获取GMLIB版本号对象 + * @returns {Version} 版本对象 + */ static getGmlibVersion() { return Version.fromString(GMLIB_API.getVersion_GMLIB()); } } +/** 计分板类 */ class Scoreboard { constructor() { throw new Error("Static class cannot be instantiated"); } - // Targets + /** + * 获取所有跟踪实体 + * @returns {Array.} 所有跟踪实体 + */ static getAllTrackedEntities() { return GMLIB_API.getAllScoreboardEntities(); } + /** + * 获取所有跟踪玩家 + * @returns {Array.} 所有跟踪玩家 + */ static getAllTrackedPlayers() { return GMLIB_API.getAllScoreboardPlayers(); } + /** + * 获取所有跟踪字符串 + * @returns {Array.} 所有跟踪字符串 + */ static getAllTrackedFakePlayers() { return GMLIB_API.getAllScoreboardFakePlayers(); } + /** + * 获取所有跟踪目标 + * @returns {Array.<{"Type":"Player","Uuid":string}|{"Type":"FakePlayer","Name":string}|{"Type":"Entity","UniqueId":string}>} 所有跟踪目标 + */ static getAllTrackedTargets() { return GMLIB_API.getAllTrackedTargets(); } - // Objectives + /** + * 创建计分板 + * @param {string} name 计分板名字 + * @param {string?} [displayName=""] 显示名称 + * @returns {boolean} 是否创建成功 + */ static addObjective(name, displayName = "") { if (displayName == "") { return GMLIB_API.addObjective(name); @@ -600,31 +1261,66 @@ class Scoreboard { return GMLIB_API.addObjectiveWithDisplayName(name, displayName); } + /** + * 移除计分板 + * @param {string} name 计分板名字 + * @returns {boolean} 是否移除成功 + */ static removeObjective(name) { return GMLIB_API.removeObjective(name); } + /** + * 获取所有计分板名字 + * @returns {Array.} 所有计分板名字列表 + */ static getAllObjectives() { return GMLIB_API.getAllObjectives(); } + /** + * 获取计分板显示名称 + * @param {string} objective 计分板名字 + * @returns {string} 计分板显示名称 + */ static getDisplayName(objective) { return GMLIB_API.getDisplayName(objective); } + /** + * 设置计分板显示名称 + * @param {string} objective 计分板名字 + * @param {string} displayName 显示名称 + * @returns {boolean} 是否设置成功 + */ static setDisplayName(objective, displayName) { return GMLIB_API.setDisplayName(objective, displayName); } + /** + * 设置计分板显示 + * @param {string} objective 计分板名称 + * @param {"list" | "sidebar" | "belowname"} slot 显示位置 + * @param {0|1?} [order=0] 排序方式 + */ static setDisplay(objective, slot, order = 0) { GMLIB_API.setDisplayObjective(objective, slot, order); } + /** + * 清除计分板显示 + * @param {"list" | "sidebar" | "belowname"} slot 清除的显示位置 + */ static clearDisplay(slot) { GMLIB_API.clearDisplayObjective(slot); } - // Player Score + /** + * 获取玩家在计分板中的值 + * @param {string} uuid 玩家的uuid + * @param {string} objective 计分板名称 + * @returns {number?} 计分板值 + */ static getPlayerScore(uuid, objective) { if (GMLIB_API.playerHasScore(uuid, objective)) { return GMLIB_API.getPlayerScore(uuid, objective); @@ -632,27 +1328,64 @@ class Scoreboard { return null; } + /** + * 增加玩家在计分板中的值 + * @param {string} uuid 玩家的uuid + * @param {string} objective 计分板名称 + * @param {number} value 增加的值 + * @returns {boolean} 是否增加成功 + */ static addPlayerScore(uuid, objective, value) { return GMLIB_API.addPlayerScore(uuid, objective, value); } + /** + * 减少玩家在计分板中的值 + * @param {string} uuid 玩家的uuid + * @param {string} objective 计分板名称 + * @param {number} value 减少的值 + * @returns {boolean} 是否减少成功 + */ static reducePlayerScore(uuid, objective, value) { return GMLIB_API.reducePlayerScore(uuid, objective, value); } + /** + * 设置玩家在计分板中的值 + * @param {string} uuid 玩家的uuid + * @param {string} objective 计分板名称 + * @param {number} value 设置的值 + * @returns {boolean} 是否设置成功 + */ static setPlayerScore(uuid, objective, value) { return GMLIB_API.setPlayerScore(uuid, objective, value); } + /** + * 重置玩家在计分板中的数据 + * @param {string} uuid 玩家的uuid + * @param {string} objective 计分板名称 + * @returns {boolean} 是否重置成功 + */ static resetPlayerScore(uuid, objective) { return GMLIB_API.resetPlayerScore(uuid, objective); } + /** + * 重置玩家所有的计分板数据 + * @param {string} uuid 玩家的uuid + * @returns {boolean} 是否重置成功 + */ static resetPlayerScores(uuid) { return GMLIB_API.resetPlayerScores(uuid); } - // FakePlayer Score + /** + * 获取字符串在计分板中的值 + * @param {string} name 字符串名称 + * @param {string} objective 计分板名称 + * @returns {number?} 计分板值 + */ static getFakePlayerScore(name, objective) { if (GMLIB_API.fakePlayerHasScore(name, objective)) { return GMLIB_API.getFakePlayerScore(name, objective); @@ -660,27 +1393,64 @@ class Scoreboard { return null; } + /** + * 增加字符串在计分板中的值 + * @param {string} name 字符串名称 + * @param {string} objective 计分板名称 + * @param {number} value 增加的值 + * @returns {boolean} 是否增加成功 + */ static addFakePlayerScore(name, objective, value) { return GMLIB_API.addFakePlayerScore(name, objective, value); } + /** + * 减少字符串在计分板中的值 + * @param {string} name 字符串名称 + * @param {string} objective 计分板名称 + * @param {number} value 减少的值 + * @returns {boolean} 是否减少成功 + */ static reduceFakePlayerScore(name, objective, value) { return GMLIB_API.reduceFakePlayerScore(name, objective, value); } + /** + * 设置字符串在计分板中的值 + * @param {string} name 字符串名称 + * @param {string} objective 计分板名称 + * @param {number} value 设置的值 + * @returns {boolean} 是否设置成功 + */ static setFakePlayerScore(name, objective, value) { return GMLIB_API.setFakePlayerScore(name, objective, value); } + /** + * 重置字符串在计分板中的数据 + * @param {string} name 字符串名称 + * @param {string} objective 计分板名称 + * @returns {boolean} 是否重置成功 + */ static resetFakePlayerScore(name, objective) { return GMLIB_API.resetFakePlayerScore(name, objective); } + /** + * 重置字符串所有的计分板数据 + * @param {string} name 字符串 + * @returns {boolean} 是否重置成功 + */ static resetFakePlayerScores(name) { return GMLIB_API.resetFakePlayerScores(name); } - // Entity Score + /** + * 获取实体在计分板中的值 + * @param {string} uniqueId 实体的uniqueId + * @param {string} objective 计分板名称 + * @returns {number?} 计分板值 + */ static getEntityScore(uniqueId, objective) { if (GMLIB_API.entityHasScore(uniqueId, objective)) { return GMLIB_API.getEntityScore(uniqueId, objective); @@ -688,35 +1458,76 @@ class Scoreboard { return null; } + /** + * 增加实体在计分板中的值 + * @param {string} uniqueId 实体的uniqueId + * @param {string} objective 计分板名称 + * @param {number} value 增加的值 + * @returns {boolean} 是否增加成功 + */ static addEntityScore(uniqueId, objective, value) { return GMLIB_API.addEntityScore(uniqueId, objective, value); } + /** + * 减少实体在计分板中的值 + * @param {string} uniqueId 实体的uniqueId + * @param {string} objective 计分板名称 + * @param {number} value 减少的值 + * @returns {boolean} 是否减少成功 + */ static reduceEntityScore(uniqueId, objective, value) { return GMLIB_API.reduceEntityScore(uniqueId, objective, value); } + /** + * 设置实体在计分板中的值 + * @param {string} uniqueId 实体的uniqueId + * @param {string} objective 计分板名称 + * @param {number} value 设置的值 + * @returns {boolean} 是否设置成功 + */ static setEntityScore(uniqueId, objective, value) { return GMLIB_API.setEntityScore(uniqueId, objective, value); } + /** + * 重置实体的计分板数据 + * @param {string} uniqueId 实体的uniqueId + * @param {string} objective 计分板名称 + * @returns {boolean} 是否重置成功 + */ static resetEntityScore(uniqueId, objective) { return GMLIB_API.resetEntityScore(uniqueId, objective); } + /** + * 重置实体的所有计分板数据 + * @param {string} uniqueId 实体的uniqueId + * @returns {boolean} 是否重置成功 + */ static resetEntityScores(uniqueId) { return GMLIB_API.resetEntityScores(uniqueId); } - } +/** 仿LSE的JsonConfigFile类 */ class JsonConfig { + /** + * 创建或打开一个 Json 配置文件 + * @param {string} path Json文件的路径 + * @param {object} defultValue 默认数据 + * @constructor + */ constructor(path, defultValue = {}) { this.mData = defultValue; this.mPath = path; this.init(); } + /** + * 初始化Json文件 + */ init() { if (File.exists(this.mPath)) { let existDataStr = File.readFrom(this.mPath); @@ -732,15 +1543,29 @@ class JsonConfig { this.save(); } + /** + * 保存Json文件 + * @param {number} [format=4] 缩进长度 + */ save(format = 4) { let dataStr = JSON.stringify(this.mData, null, format); File.writeTo(this.mPath, dataStr); } + /** + * 获取所有数据 + * @returns {object} 数据 + */ getData() { return this.mData; } + /** + * 读取数据 + * @param {string} key 键名 + * @param {any?} [defultValue=undefined] 不存在时返回值 + * @returns {any} 数据 + */ get(key, defultValue = undefined) { let result = this.getData()[key]; if (!result && defultValue != undefined) { @@ -750,22 +1575,46 @@ class JsonConfig { return result; } + /** + * 设置数据 + * @param {string} key 键名 + * @param {any} value 值 + */ set(key, value) { this.getData()[key] = value; this.save(); } + /** + * 删除数据 + * @param {string} key 键名 + */ delete(key) { delete this.getData()[key]; this.save(); } } +/** + * JSON版语言类 + */ class JsonLanguage extends JsonConfig { + /** + * 创建或打开一个 Json 语言文件 + * @param {string} path Json文件的路径 + * @param {object} defultValue 默认值 + * @constructor + */ constructor(path, defultValue = {}) { super(path, defultValue); } + /** + * 翻译键名 + * @param {string} key 键名 + * @param {Array.} data 翻译参数 + * @returns {string} 翻译结果 + */ translate(key, data = []) { let result = this.get(key); if (result == null) { @@ -773,13 +1622,19 @@ class JsonLanguage extends JsonConfig { } data.forEach((val, index) => { let old = `{${index + 1}}`; - result = result.split(old).join(val); + result = result.split(old).join(val?.toString() ?? ""); }); return result; } } +/** JSON版I18n类 */ class JsonI18n { + /** + * 加载翻译数据目录 + * @param {string} path 目录 + * @param {string?} [localLangCode="en_US"] 默认语言 + */ constructor(path, localLangCode = "en_US") { if (!path.endsWith("/") && !path.endsWith("\\")) { path = path + "/"; @@ -791,6 +1646,9 @@ class JsonI18n { this.loadAllLanguages(); } + /** + * 加载所有语言 + */ loadAllLanguages() { let exist_list = File.getFilesList(this.mPath); exist_list.forEach((name) => { @@ -801,6 +1659,11 @@ class JsonI18n { }); } + /** + * 加载语言 + * @param {string} langCode 语言标识符 + * @param {any?} [defaultData={}] 默认数据 + */ loadLanguage(langCode, defaultData = {}) { let langPath = this.mPath; langPath = langPath + langCode + ".json"; @@ -808,14 +1671,29 @@ class JsonI18n { this.mAllLanguages[langCode] = language; } + /** + * 设置语言 + * @param {string} langCode 语言标识符 + */ chooseLanguage(langCode) { this.mLangCode = langCode; } + /** + * 设置默认语言 + * @param {string} langCode 语言标识符 + */ setDefaultLanguage(langCode) { this.mDefaultLangCode = langCode; } + /** + * 翻译键名 + * @param {string} key 键名 + * @param {Array.?} [data=[]] 翻译参数 + * @param {string?} [langCode=this.mLangCode] 翻译语言 + * @returns {string} 翻译结果 + */ translate(key, data = [], langCode = this.mLangCode) { let language = this.mAllLanguages[langCode]; let result = language.translate(key, data); @@ -829,186 +1707,443 @@ class JsonI18n { } }; +/** I18nAPI类 */ class I18nAPI { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 获取键翻译 + * @param {string} key 键名 + * @param {Array.?} params 翻译参数 + * @param {string?} langCode 要翻译的语言 + * @returns {string} 翻译结果 + */ static get(key, params = [], langCode = undefined) { - let data = []; - params.forEach((param) => { - data.push(param); - }); + const data = params.map(item => item?.toString() || ""); if (langCode) { return GMLIB_API.resourcePackTranslate(key, data, langCode); } return GMLIB_API.resourcePackDefaultTranslate(key, data); } + /** + * 获取键翻译 + * @param {string} key 键名 + * @param {Array.?} params 翻译参数 + * @param {string?} langCode 要翻译的语言 + * @returns {string} 翻译结果 + */ static translate(key, params = [], langCode = undefined) { return I18nAPI.get(key, params, langCode); } + /** + * 获取支持的语言标识符 + * @returns {Array.} 语言标识符数组 + */ static getSupportedLanguages() { return GMLIB_API.getSupportedLanguages(); } + /** + * 获取资源包默认语言 + * @returns {string} 语言标识符 + */ static getCurrentLanguage() { - return GMLIB_API.getResourcePackI18nLanguage(language); + return GMLIB_API.getResourcePackI18nLanguage(); } + /** + * 设置资源包默认语言 + * @param {string} language 语言标识符 + */ static chooseLanguage(language) { GMLIB_API.chooseResourcePackI18nLanguage(language); } + /** + * 加载语言数据 + * @param {string} code 语言数据 + * @param {string} language 语言标识符 + */ static loadLanguage(code, language) { GMLIB_API.loadLanguage(code, language); } + /** + * 更新或创建语言文件 + * @param {string} code 语言数据 + * @param {strring} lang 语言标识符 + * @param {string} path 文件路径 + */ static updateOrCreateLanguageFile(code, lang, path) { GMLIB_API.updateOrCreateLanguageFile(code, lang, path); } + /** + * 加载语言目录 + * @param {string} path 文件夹路径 + */ static loadLanguageDirectory(path) { GMLIB_API.loadLanguagePath(path); } }; +/** 玩家数据库API类 */ class UserCache { constructor() { throw new Error("Static class cannot be instantiated"); } + /** + * 根据uuid获取xuid + * @param {string} uuid 玩家uuid + * @returns {string?} xuid + */ static getXuidByUuid(uuid) { let result = GMLIB_API.getXuidByUuid(uuid); return result == "" ? null : result; } + /** + * 根据xuid获取uuid + * @param {string} xuid 玩家xuid + * @returns {string?} uuid + */ static getUuidByXuid(xuid) { let result = GMLIB_API.getUuidByXuid(xuid); return result == "" ? null : result; } + /** + * 根据xuid获取玩家名称 + * @param {string} xuid 玩家xuid + * @returns {string?} 玩家名称 + */ static getNameByUuid(uuid) { let result = GMLIB_API.getNameByUuid(uuid); return result == "" ? null : result; } + /** + * 根据xuid获取玩家名称 + * @param {string} xuid 玩家uuid + * @returns {string?} 玩家名称 + */ static getNameByXuid(xuid) { let result = GMLIB_API.getNameByXuid(xuid); return result == "" ? null : result; } + /** + * 根据名称获取xuid + * @param {string} name 玩家名称 + * @returns {string?} 玩家的xuid + */ static getXuidByName(name) { let result = GMLIB_API.getXuidByName(name); return result == "" ? null : result; } + /** + * 根据名称获取uuid + * @param {string} name 玩家名称 + * @returns {string?} 玩家的uuid + */ static getUuidByName(name) { let result = GMLIB_API.getUuidByName(name); return result == "" ? null : result; } + /** + * 获取玩家信息 + * @param {string} playerIdentifier 玩家的 xuid 或 uuid 或 名称 + * @returns {{Xuid: String, Uuid: string, Name: string}?} 玩家信息 + */ static getPlayerInfo(playerIdentifier) { return GMLIB_API.getAllPlayerInfo().find(Info => Object.keys(Info).some(InfoKey => Info[InfoKey] === playerIdentifier)); } + /** + * 获取所有玩家信息 + * @returns {Array.<{Xuid: String, Uuid: string, Name: string}>} 包含所有玩家信息的数组 + */ static getAllPlayerInfo() { return GMLIB_API.getAllPlayerInfo(); } }; -LLSE_Player.prototype.toEntity = function () { - return GMLIB_API.PlayerToEntity(this); -} +LLSE_Player.prototype.toEntity = + /** + * 获取实体对象 + * @returns {Entity} 实体对象 + */ + function () { + return GMLIB_API.PlayerToEntity(this); + } -LLSE_Player.prototype.getSpawnPoint = function () { - return GMLIB_API.getPlayerSpawnPoint(this); -} +LLSE_Player.prototype.getSpawnPoint = + /** + * 获取玩家重生坐标 + * @returns {IntPos} 重生坐标对象 + */ + function () { + return GMLIB_API.getPlayerSpawnPoint(this); + } -LLSE_Player.prototype.setSpawnPoint = function (pos) { - return GMLIB_API.setPlayerSpawnPoint(this, pos); -} +LLSE_Player.prototype.setSpawnPoint = + /** + * 设置玩家重生坐标 + * @param {IntPos} pos 坐标对象 + */ + function (pos) { + GMLIB_API.setPlayerSpawnPoint(this, pos); + } -LLSE_Player.prototype.clearSpawnPoint = function () { - return GMLIB_API.clearPlayerSpawnPoint(this); -} +LLSE_Player.prototype.clearSpawnPoint = + /** + * 清除玩家重生点 + */ + function () { + GMLIB_API.clearPlayerSpawnPoint(this); + } -LLSE_Entity.prototype.shootProjectile = function (proj, speed = 2, offset = 3) { - return GMLIB_API.shootProjectile(this, proj, speed, offset); -} +LLSE_Entity.prototype.shootProjectile = + /** + * 射弹投射物 + * @param {string} proj 投射物命名空间 + * @param {number} [speed=2] 速度 + * @param {number} [offset=3] 偏移量 + * @returns {boolean} 是射弹投射物 + */ + function (proj, speed = 2, offset = 3) { + return GMLIB_API.shootProjectile(this, proj, speed, offset); + } -LLSE_Entity.prototype.throwEntity = function (proj, speed = 2, offset = 3) { - return GMLIB_API.throwEntity(this, proj, speed, offset); -} +LLSE_Entity.prototype.throwEntity = + /** + * 投掷实体 + * @param {Entity} proj 投掷的实体对象 + * @param {number} [speed=2] 速度 + * @param {number} [offset=3] 偏移量 + * @returns {boolean} 是否投掷成功 + */ + function (proj, speed = 2, offset = 3) { + return GMLIB_API.throwEntity(this, proj, speed, offset); + } -LLSE_Entity.prototype.getTranslateKey = function () { - return GMLIB_API.getEntityTranslateKey(this); -} +LLSE_Entity.prototype.getTranslateKey = + /** + * 获取实体翻译键名 + * @returns {string} 翻译键名 + */ + function () { + return GMLIB_API.getEntityTranslateKey(this); + } -LLSE_Entity.prototype.getTranslateName = function (language) { - return I18nAPI.get(this.getTranslateKey(), [], language); -} +LLSE_Entity.prototype.getTranslateName = + /** + * 获取实体名字翻译 + * @param {string} language 语言标识符 + * @returns {string} 翻译名称 + */ + function (language) { + return I18nAPI.get(this.getTranslateKey(), [], language); + } -LLSE_Block.prototype.getTranslateKey = function () { - return GMLIB_API.getBlockTranslateKey(this); -} +LLSE_Block.prototype.getTranslateKey = + /** + * 获取方块翻译键名 + * @returns {string} 翻译键名 + */ + function () { + return GMLIB_API.getBlockTranslateKey(this); + } -LLSE_Block.prototype.getTranslateName = function (language) { - return I18nAPI.get(this.getTranslateKey(), [], language); -} +LLSE_Block.prototype.getTranslateName = + /** + * 获取方块翻译 + * @param {string} language 语言标识符 + * @returns {string} 翻译名称 + */ + function (language) { + return I18nAPI.get(this.getTranslateKey(), [], language); + } -LLSE_Item.prototype.getTranslateKey = function () { - return GMLIB_API.getItemTranslateKey(this); -} +LLSE_Item.prototype.getTranslateKey = + /** + * 获取物品翻译键名 + * @returns {string} 翻译键名 + */ + function () { + return GMLIB_API.getItemTranslateKey(this); + } -LLSE_Item.prototype.getTranslateName = function (language) { - return I18nAPI.get(this.getTranslateKey(), [], language); -} +LLSE_Item.prototype.getTranslateName = + /** + * 获取物品翻译 + * @param {string} language 语言标识符 + * @returns {string} 翻译名称 + */ + function (language) { + return I18nAPI.get(this.getTranslateKey(), [], language); + } -LLSE_Block.prototype.getBlockDestroySpeed = function () { - return GMLIB_API.getBlockDestroySpeed(this); -} +LLSE_Block.prototype.getBlockDestroySpeed = + /** + * 获取方块硬度 + * @returns {number} 硬度 + */ + function () { + return GMLIB_API.getBlockDestroySpeed(this); + } -LLSE_Item.prototype.getDestroyBlockSpeed = function (block) { - return GMLIB_API.getDestroyBlockSpeed(this, block); -} +LLSE_Item.prototype.getDestroyBlockSpeed = + /** + * 获取物品挖掘方块速度 + * @param {Block} block 方块对象 + * @returns {number} 挖掘速度 + */ + function (block) { + return GMLIB_API.getDestroyBlockSpeed(this, block); + } -LLSE_Block.prototype.playerDestroy = function (player) { - GMLIB_API.playerDestroyBlock(this, this.pos, player); -} +LLSE_Block.prototype.playerDestroy = + /** + * 使方块被玩家挖掘 + * @param {Player} player 玩家对象 + */ + function (player) { + GMLIB_API.playerDestroyBlock(this, this.pos, player); + } -LLSE_Item.prototype.canDestroy = function (block) { - return GMLIB_API.itemCanDestroyBlock(this, block); -} +LLSE_Item.prototype.canDestroy = + /** + * 物品冒险模式下是否可以挖掘方块 + * @param {Block} block 方块对象 + * @returns {boolean} 物品冒险模式下是否可以挖掘方块 + */ + function (block) { + return GMLIB_API.itemCanDestroyBlock(this, block); + } -LLSE_Item.prototype.canDestroyInCreative = function () { - return GMLIB_API.itemCanDestroyInCreative(this); -} +LLSE_Item.prototype.canDestroyInCreative = + /** + * 物品是否能破坏方块 + * @returns {boolean} 是否能破坏方块 + */ + function () { + return GMLIB_API.itemCanDestroyInCreative(this); + } -LLSE_Item.prototype.canDestroySpecial = function (block) { - return GMLIB_API.itemCanDestroySpecial(this, block); -} +LLSE_Item.prototype.canDestroySpecial = + /** + * 物品是否可以采集方块 + * @param {Block} block 方块对象 + * @returns {boolean} 是否可以采集方块 + */ + function (block) { + return GMLIB_API.itemCanDestroySpecial(this, block); + } -LLSE_Block.prototype.canDropWithAnyTool = function () { - return GMLIB_API.blockCanDropWithAnyTool(this); -} +LLSE_Block.prototype.canDropWithAnyTool = + /** + * + * @returns {boolean} + */ + function () { + return GMLIB_API.blockCanDropWithAnyTool(this); + } -LLSE_Block.prototype.isAlwaysDestroyable = function () { - return GMLIB_API.blockIsAlwaysDestroyable(this); -} +LLSE_Block.prototype.isAlwaysDestroyable = + /** + * 方块是否不需要工具采集 + * @returns {boolean} 方块是否不需要工具采集 + */ + function () { + return GMLIB_API.blockIsAlwaysDestroyable(this); + } -LLSE_Block.prototype.playerWillDestroy = function (player) { - return GMLIB_API.blockPlayerWillDestroy(this, player, this.pos); -} +LLSE_Block.prototype.playerWillDestroy = + /** + * + * @param {Player} player 玩家对象 + * @returns {boolean} + */ + function (player) { + return GMLIB_API.blockPlayerWillDestroy(this, player, this.pos); + } -LLSE_Player.prototype.attack = function (entity) { - return GMLIB_API.playerAttack(this, entity); -} +LLSE_Player.prototype.attack = + /** + * 使玩家攻击实体 + * @param {Entity} entity 实体对象 + * @returns {boolean} + */ + function (entity) { + return GMLIB_API.playerAttack(this, entity); + } -LLSE_Player.prototype.pullInEntity = function (entity) { - return GMLIB_API.playerPullInEntity(this, entity); -} +LLSE_Player.prototype.pullInEntity = + /** + * + * @param {Entity} entity 实体对象 + * @returns {boolean} + */ + function (entity) { + return GMLIB_API.playerPullInEntity(this, entity); + } + +LLSE_Item.prototype.getLegalEnchants = + /** + * 获取物品可以拥有的合法附魔 + * @returns {Array.} 附魔ID列表 + */ + function () { + return GMLIB_API.getLegalEnchants(this); + } + +LLSE_Item.prototype.applyEnchant = + /** + * 添加附魔 + * @param {number} id 附魔ID + * @param {number} level 等级 + * @param {boolean} allowNonVanilla 允许非原版附魔 + * @returns {boolean} 是否附魔成功 + */ + function (id, level, allowNonVanilla = true) { + return GMLIB_API.applyEnchant(this, id, level, allowNonVanilla); + } + +LLSE_Item.prototype.removeEnchants = + /** + * 删除所有附魔 + */ + function () { + GMLIB_API.removeEnchants(this); + } + +LLSE_Item.prototype.hasEnchant = + /** + * 判断是否拥有附魔 + * @param {number} id 附魔ID + * @returns {boolean} 是否拥有附魔 + */ + function (id) { + return GMLIB_API.hasEnchant(this, id); + } + +LLSE_Item.prototype.getEnchantLevel = + /** + * 获取附魔等级 + * @param {number} id 附魔ID + * @returns {number} 附魔等级 + */ + function (id) { + return GMLIB_API.getEnchantLevel(this, id); + } module.exports = { StaticFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index e1bed12..b02f3c0 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -599,8 +599,8 @@ void Export_Compatibility_API() { return result; } ); - RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName) -> uint { - if (auto block = Block::tryGetFromRegistry(blockName)) { + RemoteCall::exportAs("GMLIB_API", "getBlockRuntimeId", [](std::string const& blockName, short legacyData) -> uint { + if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) { return block->getRuntimeId(); } return 0; @@ -648,7 +648,10 @@ void Export_Compatibility_API() { return item->canDestroy(block); }); RemoteCall::exportAs("GMLIB_API", "itemCanDestroyInCreative", [](ItemStack const* item) -> bool { - return item->getItem()->canDestroyInCreative(); + if (auto itemDef = item->getItem()) { + return itemDef->canDestroyInCreative(); + } + return false; }); RemoteCall::exportAs("GMLIB_API", "itemCanDestroySpecial", [](ItemStack const* item, Block const* block) -> bool { return item->canDestroySpecial(*block); @@ -678,4 +681,66 @@ void Export_Compatibility_API() { } return "tile.unknown.name"; }); + RemoteCall::exportAs( + "GMLIB_API", + "getBlockLightEmission", + [](std::string const& blockName, short legacyData) -> char { + if (auto block = Block::tryGetFromRegistry(blockName, legacyData)) { + return (char)block->getLightEmission().value; + } + return -1; + } + ); + RemoteCall::exportAs( + "GMLIB_API", + "getGameRules", + []() -> std::vector> { + auto gameRules = ll::service::getLevel()->getGameRules().getRules(); + std::vector> result; + for (auto& gameRule : gameRules) { + std::unordered_map data; + data["Name"] = gameRule.getName(); + switch (gameRule.getType()) { + case GameRule::Type::Bool: + data["Type"] = "Bool"; + data["Value"] = std::to_string(gameRule.getBool()); + break; + case GameRule::Type::Float: + data["Type"] = "Float"; + data["Value"] = std::to_string(gameRule.getFloat()); + break; + case GameRule::Type::Int: + data["Type"] = "Int"; + data["Value"] = std::to_string(gameRule.getInt()); + break; + case GameRule::Type::Invalid: + break; + } + result.push_back(data); + } + return result; + } + ); + RemoteCall::exportAs("GMLIB_API", "getLegalEnchants", [](ItemStack const* item) -> std::vector { + return EnchantUtils::getLegalEnchants(item->getItem()); + }); + RemoteCall::exportAs( + "GMLIB_API", + "applyEnchant", + [](ItemStack const* item, int id, int level, bool allowNonVanilla) -> bool { + return EnchantUtils::applyEnchant((ItemStackBase&)*item, (Enchant::Type)id, level, allowNonVanilla); + } + ); + RemoteCall::exportAs("GMLIB_API", "removeEnchants", [](ItemStack const* item) -> void { + EnchantUtils::removeEnchants((ItemStack&)*item); + }); + RemoteCall::exportAs("GMLIB_API", "hasEnchant", [](ItemStack const* item, int id) -> bool { + return EnchantUtils::hasEnchant((Enchant::Type)id, (ItemStackBase&)*item); + }); + RemoteCall::exportAs("GMLIB_API", "getEnchantLevel", [](ItemStack const* item, int id) -> int { + return EnchantUtils::getEnchantLevel((Enchant::Type)id, (ItemStackBase&)*item); + }); + RemoteCall::exportAs("GMLIB_API", "getEnchantNameAndLevel", [](int id, int level) -> std::string { + return EnchantUtils::getEnchantNameAndLevel((Enchant::Type)id, level); + }); } \ No newline at end of file diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index d0ea282..bfa03d2 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -7,195 +7,249 @@ void Export_Event_API() { "GMLIB_API", "callCustomEvent", [eventBus](std::string const& eventName, std::string const& eventId) -> bool { - if (RemoteCall::hasFunc(eventName, eventId)) { - switch (doHash(eventName)) { - case doHash("onClientLogin"): { - auto Call = RemoteCall::importAs(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::PacketEvent::ClientLoginAfterEvent& ev) { - try { - Call( - ev.getRealName(), - ev.getUuid().asString(), - ev.getServerAuthXuid(), - ev.getClientAuthXuid() - ); - } catch (...) {} - } - ); - return true; - } - case doHash("onWeatherChange"): { - auto Call = - RemoteCall::importAs( - eventName, - eventId - ); - eventBus->emplaceListener( - [Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) { - bool result = true; - try { - result = Call( - ev.getLightningLevel(), - ev.getRainLevel(), - ev.getLightningLastTick(), - ev.getRainingLastTick() - ); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - case doHash("onMobPick"): { - auto Call = RemoteCall::importAs(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) { - bool result = true; - try { - result = Call(&ev.self(), (Actor*)&ev.getItemActor()); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - case doHash("onItemTrySpawn"): { - auto Call = RemoteCall::importAs< - bool(const ItemStack* item, std::pair position, Actor* spawner)>(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) { - auto pos = ev.getPosition(); - auto dimid = ev.getBlockSource().getDimensionId().id; - std::pair lsePos = {pos, dimid}; - bool result = true; - try { - result = Call(&ev.getItem(), lsePos, ev.getSpawner()); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - case doHash("onItemSpawned"): { - auto Call = RemoteCall::importAs< - bool(const ItemStack* item, Actor* itemActor, std::pair position, Actor* spawner)>( - eventName, - eventId - ); - eventBus->emplaceListener( - [Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) { - auto pos = ev.getPosition(); - auto dimid = ev.getBlockSource().getDimensionId().id; - std::pair lsePos = {pos, dimid}; - try { - Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner()); - } catch (...) {} - } - ); - return true; - } - case doHash("onEntityChangeDim"): { - auto Call = RemoteCall::importAs(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) { - bool result = true; - try { - result = Call(&ev.self(), ev.getToDimensionId()); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - case doHash("onLeaveBed"): { - auto Call = RemoteCall::importAs(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) { - bool result = true; - try { - result = Call(&ev.self()); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - case doHash("onDeathMessage"): { - auto Call = - RemoteCall::importAs, Actor* dead)>( - eventName, - eventId - ); - eventBus->emplaceListener( - [Call](Event::EntityEvent::DeathMessageAfterEvent& ev) { - auto msg = ev.getDeathMessage(); - auto source = ev.getDamageSource(); - try { - Call(msg.first, msg.second, &ev.self()); - } catch (...) {} - } - ); - return true; - } - case doHash("onMobHurted"): { - auto Call = RemoteCall::importAs( - eventName, - eventId - ); - eventBus->emplaceListener( - [Call](Event::EntityEvent::MobHurtAfterEvent& ev) { - auto& damageSource = ev.getSource(); - Actor* source = nullptr; - if (damageSource.isEntitySource()) { - auto uniqueId = damageSource.getDamagingEntityUniqueID(); - source = ll::service::getLevel()->fetchEntity(uniqueId); - if (source->getOwner()) { - source = source->getOwner(); - } - } - try { - Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()); - } catch (...) {} - } - ); - return true; - } - case doHash("onEndermanTake"): { - auto Call = RemoteCall::importAs(eventName, eventId); - eventBus->emplaceListener( - [Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) { - bool result = true; - try { - result = Call(&ev.self()); - } catch (...) {} - if (!result) { - ev.cancel(); - } - } - ); - return true; - } - default: - return false; - } + if (!RemoteCall::hasFunc(eventName, eventId)) return false; + switch (doHash(eventName)) { + case doHash("onClientLogin"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::PacketEvent::ClientLoginAfterEvent& ev) { + try { + Call( + ev.getRealName(), + ev.getUuid().asString(), + ev.getServerAuthXuid(), + ev.getClientAuthXuid() + ); + } catch (...) {} + } + ); + return true; + } + case doHash("onWeatherChange"): { + auto Call = + RemoteCall::importAs( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) { + bool result = true; + try { + result = Call( + ev.getLightningLevel(), + ev.getRainLevel(), + ev.getLightningLastTick(), + ev.getRainingLastTick() + ); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onMobPick"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) { + bool result = true; + try { + result = Call(&ev.self(), (Actor*)&ev.getItemActor()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onItemTrySpawn"): { + auto Call = + RemoteCall::importAs position, Actor* spawner)>( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) { + auto pos = ev.getPosition(); + auto dimid = ev.getBlockSource().getDimensionId().id; + std::pair lsePos = {pos, dimid}; + bool result = true; + try { + result = Call(&ev.getItem(), lsePos, ev.getSpawner()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onItemSpawned"): { + auto Call = RemoteCall::importAs< + bool(const ItemStack* item, Actor* itemActor, std::pair position, Actor* spawner)>( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) { + auto pos = ev.getPosition(); + auto dimid = ev.getBlockSource().getDimensionId().id; + std::pair lsePos = {pos, dimid}; + try { + Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner()); + } catch (...) {} + } + ); + return true; + } + case doHash("onEntityChangeDim"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) { + bool result = true; + try { + result = Call(&ev.self(), ev.getToDimensionId()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onLeaveBed"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) { + bool result = true; + try { + result = Call(&ev.self()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onDeathMessage"): { + auto Call = + RemoteCall::importAs, Actor* dead)>( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](Event::EntityEvent::DeathMessageAfterEvent& ev) { + auto msg = ev.getDeathMessage(); + auto source = ev.getDamageSource(); + try { + Call(msg.first, msg.second, &ev.self()); + } catch (...) {} + } + ); + return true; + } + case doHash("onMobHurted"): { + auto Call = RemoteCall::importAs( + eventName, + eventId + ); + eventBus->emplaceListener( + [Call](Event::EntityEvent::MobHurtAfterEvent& ev) { + auto& damageSource = ev.getSource(); + Actor* source = nullptr; + if (damageSource.isEntitySource()) { + auto uniqueId = damageSource.getDamagingEntityUniqueID(); + source = ll::service::getLevel()->fetchEntity(uniqueId); + if (source->getOwner()) { + source = source->getOwner(); + } + } + try { + Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()); + } catch (...) {} + } + ); + return true; + } + case doHash("onEndermanTake"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) { + bool result = true; + try { + result = Call(&ev.self()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("onEntityChangeDimAfter"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ActorChangeDimensionAfterEvent& ev) { + bool result = true; + try { + result = Call(&ev.self(), ev.getFromDimensionId()); + } catch (...) {} + } + ); + return true; + } + case doHash("DragonRespawn"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) { + bool result = true; + try { + result = Call(ev.getEnderDragon().id); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("ProjectileTryCreate"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) { + bool result = true; + try { + result = Call(&ev.self()); + } catch (...) {} + if (!result) { + ev.cancel(); + } + } + ); + return true; + } + case doHash("ProjectileCreate"): { + auto Call = RemoteCall::importAs(eventName, eventId); + eventBus->emplaceListener( + [Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) { + try { + Call(&ev.self()); + } catch (...) {} + } + ); + return true; + } + default: + return false; } - return false; } ); } \ No newline at end of file