新增sendInventorySlotPacket接口

This commit is contained in:
子沐呀
2024-07-21 03:57:10 +08:00
Unverified
parent 6b01186f23
commit cf128f460d
3 changed files with 36 additions and 2 deletions
+10
View File
@@ -1057,6 +1057,16 @@ interface Player {
/** 槽位 */
slot: number
): Item;
/** (GMLIB)发送更新更新物品数据包 */
sendInventorySlotPacket(
/** 容器ID */
containerId: number,
/** 槽位 */
slot: number,
/** 物品 */
item: Item
): void;
}
interface Entity {
+15 -2
View File
@@ -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<number,StaticFloatingText>} */
@@ -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,
+11
View File
@@ -1,5 +1,9 @@
#include "Global.h"
#include "magic_enum.hpp"
#include "mc/network/packet/InventorySlotPacket.h"
#include <map>
#include <regex>
#include <vector>
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<ItemStack*>(&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);
}
);
}