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