新增hasPlayerNbt接口

This commit is contained in:
子沐呀
2024-07-23 08:45:43 +08:00
Unverified
parent f427f2f5e1
commit a5eb2e855a
3 changed files with 28 additions and 11 deletions
+7 -1
View File
@@ -151,7 +151,7 @@ declare class Minecraft {
/** 要设置的NBT数据 */ /** 要设置的NBT数据 */
nbt: NbtCompound, nbt: NbtCompound,
/** 要覆盖的NBT标签 */ /** 要覆盖的NBT标签 */
tags: string tags: string[]
): boolean; ): boolean;
/** 删除玩家NBT */ /** 删除玩家NBT */
@@ -366,6 +366,12 @@ declare class Minecraft {
/** 获取最大玩家数 */ /** 获取最大玩家数 */
static getMaxPlayers(): number; static getMaxPlayers(): number;
/** 玩家是否拥有NBT */
static hasPlayerNbt(
/** 玩家的uuid */
uuid: string
): boolean;
} }
/** 合成表类 */ /** 合成表类 */
+14 -3
View File
@@ -30,7 +30,7 @@ const GMLIB_API = {
getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"), getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"),
/** 设置玩家NBT @type {function(string,NbtCompound,boolean):boolean} */ /** 设置玩家NBT @type {function(string,NbtCompound,boolean):boolean} */
setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"), setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"),
/** 覆盖玩家的特定nbtTags @type {function(string,NbtCompound,string):boolean} */ /** 覆盖玩家的特定nbtTags @type {function(string,NbtCompound,Array.<string>):boolean} */
setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"), setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"),
/** 删除玩家所有的NBT @type {function(string):boolean} */ /** 删除玩家所有的NBT @type {function(string):boolean} */
deletePlayerNbt: ll.import("GMLIB_API", "deletePlayerNbt"), deletePlayerNbt: ll.import("GMLIB_API", "deletePlayerNbt"),
@@ -335,7 +335,9 @@ const GMLIB_API = {
/** 更新玩家容器物品 @type {function(Player,number,number,Item):void} */ /** 更新玩家容器物品 @type {function(Player,number,number,Item):void} */
sendInventorySlotPacket: ll.import("GMLIB_API", "sendInventorySlotPacket"), sendInventorySlotPacket: ll.import("GMLIB_API", "sendInventorySlotPacket"),
/** 获取容器类型 @type {function(Container):string} */ /** 获取容器类型 @type {function(Container):string} */
getContainerType: ll.import("GMLIB_API", "getContainerType") getContainerType: ll.import("GMLIB_API", "getContainerType"),
/** 玩家是否拥有NBT @type {function(string):boolean} */
hasPlayerNbt: ll.import("GMLIB_API", "hasPlayerNbt")
} }
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */ /** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
@@ -656,7 +658,7 @@ class Minecraft {
* 覆盖玩家NBT的特定Tags * 覆盖玩家NBT的特定Tags
* @param {string} uuid 玩家的uuid * @param {string} uuid 玩家的uuid
* @param {NbtCompound} nbt 要写入的NBT * @param {NbtCompound} nbt 要写入的NBT
* @param {string} tags 要覆盖的NBT标签 * @param {Array.<string>} tags 要覆盖的NBT标签
* @returns {boolean} 是否成功写入NBT * @returns {boolean} 是否成功写入NBT
*/ */
static setPlayerNbtTags(uuid, nbt, tags) { static setPlayerNbtTags(uuid, nbt, tags) {
@@ -1016,6 +1018,15 @@ class Minecraft {
static getMaxPlayers() { static getMaxPlayers() {
return GMLIB_API.getMaxPlayers(); return GMLIB_API.getMaxPlayers();
} }
/**
* 玩家是否拥有NBT
* @param {string} uuid 玩家的uuid
* @returns 玩家是否拥有NBT
*/
static hasPlayerNbt(uuid) {
return GMLIB_API.hasPlayerNbt(uuid);
}
} }
/** 合成表类 */ /** 合成表类 */
+7 -7
View File
@@ -879,11 +879,11 @@ void Export_Compatibility_API() {
InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player); InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs("GMLIB_API", "getContainerType", [](Container* container) -> std::string {
"GMLIB_API", return magic_enum::enum_name(container->getContainerType()).data();
"getContainerType", });
[](Container* container) -> std::string { RemoteCall::exportAs("GMLIB_API", "hasPlayerNbt", [](std::string const& uuid) -> bool {
return magic_enum::enum_name(container->getContainerType()).data(); auto uid = mce::UUID::fromString(uuid);
} return GMLIB_Player::getPlayerNbt(uid) ? true : false;
); });
} }