From cf128f460d6917f3b5f280fabdd9a21f87bba745 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: Sun, 21 Jul 2024 03:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EsendInventorySlotPacket?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/GMLIB_API-JS.d.ts | 10 ++++++++++ lib/GMLIB_API-JS.js | 17 +++++++++++++++-- src/CompatibilityApi.cpp | 11 +++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index ecedf22..41d072b 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1057,6 +1057,16 @@ interface Player { /** 槽位 */ slot: number ): Item; + + /** (GMLIB)发送更新更新物品数据包 */ + sendInventorySlotPacket( + /** 容器ID */ + containerId: number, + /** 槽位 */ + slot: number, + /** 物品 */ + item: Item + ): void; } interface Entity { diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index b83c7e8..07a0383 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -331,7 +331,9 @@ const GMLIB_API = { /** 设置玩家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") + getPlayerUIItem: ll.import("GMLIB_API", "getPlayerUIItem"), + /** 更新玩家容器物品 @type {function(Player,number,number,Item):void} */ + sendInventorySlotPacket: ll.import("GMLIB_API","sendInventorySlotPacket") } /** 静态悬浮字类列表 @type {Map} */ @@ -2445,7 +2447,7 @@ LLSE_Player.prototype.setPlayerUIItem = * @param {Item} item 要设置的物品 */ function (slot, item) { - return GMLIB_API.setPlayerUIItem(this, slot, item); + GMLIB_API.setPlayerUIItem(this, slot, item); } LLSE_Player.prototype.getPlayerUIItem = @@ -2458,6 +2460,17 @@ LLSE_Player.prototype.getPlayerUIItem = return GMLIB_API.getPlayerUIItem(this, slot); } +LLSE_Player.prototype.sendInventorySlotPacket = + /** + * 发送更新更新物品数据包 + * @param {number} containerId 容器ID + * @param {number} slot 格子槽位 + * @param {Item} item 物品对象 + */ + function (containerId, slot, item) { + GMLIB_API.sendInventorySlotPacket(this, containerId, slot, item); + } + module.exports = { StaticFloatingText, DynamicFloatingText, diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 9268450..991eba1 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -1,5 +1,9 @@ #include "Global.h" +#include "magic_enum.hpp" +#include "mc/network/packet/InventorySlotPacket.h" +#include #include +#include bool isInteger(const std::string& str) { std::regex pattern("^[+-]?\\d+$"); @@ -867,4 +871,11 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getPlayerUIItem", [](Player* player, int slot) -> ItemStack* { return const_cast(&player->getPlayerUIItem((PlayerUISlot)slot)); }); + RemoteCall::exportAs( + "GMLIB_API", + "sendInventorySlotPacket", + [](Player* player, int containerId, int slot, ItemStack* item) -> void { + InventorySlotPacket((ContainerID)containerId, slot, *item).sendTo(*player); + } + ); } \ No newline at end of file