From cd088431f34922a8e6ae5b159f309f85a690fc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=B2=90=E5=91=80?= <163636894+zimuya4153@users.noreply.github.com> Date: Sat, 20 Jul 2024 17:00:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A02=E4=B8=AA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - setPlayerUIItem - getPlayerUIItem --- lib/GMLIB_API-JS.d.ts | 14 ++++++++++++++ lib/GMLIB_API-JS.js | 26 +++++++++++++++++++++++++- src/CompatibilityApi.cpp | 6 ++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index 2dbaa2d..7aa1c4a 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1043,6 +1043,20 @@ interface Player { /** (GMLIB)获取玩家盔甲值 */ getArmorValue(): number; + + /** (GMLIB)设置玩家UI栏物品 */ + setPlayerUIItem( + /** 槽位 */ + slot: number, + /** 物品 */ + item: Item + ): void; + + /** (GMLIB)获取玩家UI栏物品 */ + setPlayerUIItem( + /** 槽位 */ + slot: number + ): Item; } interface Entity { diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 86a58f7..af2dea8 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -327,7 +327,11 @@ const GMLIB_API = { /** 获取物品BUFF效果名称 @type {function(Item):string} */ getItemEffecName: ll.import("GMLIB_API", "getItemEffecName"), /** 物品是否为食物 @type {function(Item):boolean} */ - itemIsFood: ll.import("GMLIB_API", "itemIsFood") + itemIsFood: ll.import("GMLIB_API", "itemIsFood"), + /** 设置玩家UI栏物品 @type {function(Player,number,Item):void} */ + setPlayerUIItem: ll.import("GMLIB_API", "setPlayerUIItem"), + /** 获取玩家UI栏物品 @type {function(Player,number):Item} */ + getPlayerUIItem: ll.import("GMLIB_API", "getPlayerUIItem") } /** 静态悬浮字类列表 @type {Map} */ @@ -2434,6 +2438,26 @@ LLSE_Item.prototype.isFood = return GMLIB_API.itemIsFood(this); } +LLSE_Player.prototype.setPlayerUIItem = + /** + * 设置玩家UI栏物品 + * @param {number} slot 格子槽位 + * @param {Item} item 要设置的物品 + */ + function (slot, item) { + return GMLIB_API.setPlayerUIItem(this, slot, item); + } + +LLSE_Player.prototype.setPlayerUIItem = + /** + * 获取玩家UI栏物品 + * @param {number} slot 格子槽位 + * @returns {Item} 物品对象 + */ + function (slot) { + return GMLIB_API.getPlayerUIItem(this, slot); + } + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 557c5d7..02a607a 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -862,4 +862,10 @@ void Export_Compatibility_API() { } return false; }); + RemoteCall::exportAs("GMLIB_API", "setPlayerUIItem", [](Player* player, int slot, ItemStack const* item) -> void { + player->setPlayerUIItem((PlayerUISlot)slot, *item); + }); + RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](Player* player, int slot) -> void { + player->getPlayerUIItem((PlayerUISlot)slot); + }); } \ No newline at end of file