From f427f2f5e1491948d6ef011b74023842a06262cf 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: Tue, 23 Jul 2024 05:59:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E/=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 - getContainerType 修改 - HandleRequestActionEvent --- lib/EventAPI-JS.d.ts | 4 ++-- lib/GMLIB_API-JS.d.ts | 13 +++++++++---- lib/GMLIB_API-JS.js | 12 +++++++++++- src/CompatibilityApi.cpp | 8 ++++++++ src/EventAPI.cpp | 4 ++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/EventAPI-JS.d.ts b/lib/EventAPI-JS.d.ts index 3fe4da5..249578f 100644 --- a/lib/EventAPI-JS.d.ts +++ b/lib/EventAPI-JS.d.ts @@ -215,8 +215,8 @@ declare class Event { player: Player, /** 请求类型 */ actionType: string, - /** 容器ID */ - containerId: number, + /** 容器枚举名 */ + containerNetId: string, /** 请求的槽位 */ slot: number ) => boolean | void diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index 41d072b..f7b3bf9 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1266,15 +1266,20 @@ interface Item { blocks: string[] ): void; - /** 获取物品分类名称 */ + /** (GMLIB)获取物品分类名称 */ getCategoryName(): string; - /** 获取物品的命名 */ + /** (GMLIB)获取物品的命名 */ getCustomName(): string; - /** 获取物品的BUFF效果名称 */ + /** (GMLIB)获取物品的BUFF效果名称 */ getEffecName(): string; - /** 物品是否为食物 */ + /** (GMLIB)物品是否为食物 */ isFood(): boolean; +} + +interface Container { + /** (GMLIB)获取容器类型 */ + getContainerType(): string } \ No newline at end of file diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 07a0383..25d3f94 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -333,7 +333,9 @@ const GMLIB_API = { /** 获取玩家UI栏物品 @type {function(Player,number):Item} */ getPlayerUIItem: ll.import("GMLIB_API", "getPlayerUIItem"), /** 更新玩家容器物品 @type {function(Player,number,number,Item):void} */ - sendInventorySlotPacket: ll.import("GMLIB_API","sendInventorySlotPacket") + sendInventorySlotPacket: ll.import("GMLIB_API", "sendInventorySlotPacket"), + /** 获取容器类型 @type {function(Container):string} */ + getContainerType: ll.import("GMLIB_API", "getContainerType") } /** 静态悬浮字类列表 @type {Map} */ @@ -2471,6 +2473,14 @@ LLSE_Player.prototype.sendInventorySlotPacket = GMLIB_API.sendInventorySlotPacket(this, containerId, slot, item); } +LLSE_Container.prototype.getContainerType = + /** + * 获取容器类型 + */ + function () { + return GMLIB_API.getContainerType(this); + } + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 991eba1..a854dfb 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,6 +1,7 @@ #include "Global.h" #include "magic_enum.hpp" #include "mc/network/packet/InventorySlotPacket.h" +#include "mc/world/Container.h" #include #include #include @@ -878,4 +879,11 @@ void Export_Compatibility_API() { InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player); } ); + RemoteCall::exportAs( + "GMLIB_API", + "getContainerType", + [](Container* container) -> std::string { + return magic_enum::enum_name(container->getContainerType()).data(); + } + ); } \ No newline at end of file diff --git a/src/EventAPI.cpp b/src/EventAPI.cpp index a0bbbaf..c33c9ad 100644 --- a/src/EventAPI.cpp +++ b/src/EventAPI.cpp @@ -266,7 +266,7 @@ void Export_Event_API() { } case doHash("HandleRequestAction"): { auto Call = RemoteCall::importAs< - bool(Player * player, std::string const& actionType, int ContainerNetId, int slot)>( + bool(Player * player, std::string const& actionType, std::string const& containerNetId, int slot)>( eventName, eventId ); @@ -278,7 +278,7 @@ void Export_Event_API() { result = Call( &ev.self(), magic_enum::enum_name(requestAction->mActionType).data(), - (int)requestAction->getSrc().mOpenContainerNetId, + magic_enum::enum_name(requestAction->getSrc().mOpenContainerNetId).data(), requestAction->getSrc().mSlot ); } catch (...) {}