fix bugs found regarding inventories
This commit is contained in:
@@ -62,7 +62,7 @@ typedef void(__stdcall *fn_set_player_connection_callbacks)(void *sendRaw);
|
||||
typedef long long(__stdcall *fn_fire_player_drop_item)(int entityId,
|
||||
int itemId, int itemCount, int itemAux,
|
||||
int *outItemId, int *outItemCount, int *outItemAux);
|
||||
typedef void(__stdcall *fn_set_inventory_callbacks)(void *getPlayerInventory, void *setPlayerInventorySlot, void *getContainerContents, void *setContainerSlot, void *getContainerViewerEntityIds, void *closeContainer, void *openVirtualContainer, void *getItemMeta, void *setItemMeta, void *setHeldItemSlot);
|
||||
typedef void(__stdcall *fn_set_inventory_callbacks)(void *getPlayerInventory, void *setPlayerInventorySlot, void *getContainerContents, void *setContainerSlot, void *getContainerViewerEntityIds, void *closeContainer, void *openVirtualContainer, void *getItemMeta, void *setItemMeta, void *setHeldItemSlot, void *getCarriedItem, void *setCarriedItem, void *getEnderChestContents, void *setEnderChestSlot);
|
||||
typedef int(__stdcall *fn_fire_player_interact)(int entityId, int action,
|
||||
int itemId, int itemCount, int itemAux,
|
||||
int clickedX, int clickedY, int clickedZ,
|
||||
@@ -322,7 +322,11 @@ void Initialize()
|
||||
(void *)&NativeOpenVirtualContainer,
|
||||
(void *)&NativeGetItemMeta,
|
||||
(void *)&NativeSetItemMeta,
|
||||
(void *)&NativeSetHeldItemSlot);
|
||||
(void *)&NativeSetHeldItemSlot,
|
||||
(void *)&NativeGetCarriedItem,
|
||||
(void *)&NativeSetCarriedItem,
|
||||
(void *)&NativeGetEnderChestContents,
|
||||
(void *)&NativeSetEnderChestSlot);
|
||||
|
||||
s_managedSetEntityCallbacks(
|
||||
(void *)&NativeSetSneaking,
|
||||
|
||||
@@ -1072,6 +1072,68 @@ void __cdecl NativeSetHeldItemSlot(int entityId, int slot)
|
||||
player->connection->queueSend(std::make_shared<SetCarriedItemPacket>(slot));
|
||||
}
|
||||
|
||||
void __cdecl NativeGetCarriedItem(int entityId, int *outData)
|
||||
{
|
||||
outData[0] = 0;
|
||||
outData[1] = 0;
|
||||
outData[2] = 0;
|
||||
auto player = FindPlayer(entityId);
|
||||
if (!player || !player->inventory)
|
||||
return;
|
||||
auto item = player->inventory->getCarried();
|
||||
if (item)
|
||||
{
|
||||
outData[0] = item->id;
|
||||
outData[1] = item->getAuxValue();
|
||||
outData[2] = (int)item->count;
|
||||
}
|
||||
}
|
||||
|
||||
void __cdecl NativeSetCarriedItem(int entityId, int itemId, int count, int aux)
|
||||
{
|
||||
auto player = FindPlayer(entityId);
|
||||
if (!player || !player->inventory)
|
||||
return;
|
||||
if (itemId <= 0 || count <= 0)
|
||||
player->inventory->setCarried(nullptr);
|
||||
else
|
||||
player->inventory->setCarried(std::make_shared<ItemInstance>(itemId, count, aux));
|
||||
}
|
||||
|
||||
void __cdecl NativeGetEnderChestContents(int entityId, int *outData)
|
||||
{
|
||||
memset(outData, 0, 27 * 3 * sizeof(int));
|
||||
auto player = FindPlayer(entityId);
|
||||
if (!player)
|
||||
return;
|
||||
auto ec = player->getEnderChestInventory();
|
||||
if (!ec)
|
||||
return;
|
||||
unsigned int size = ec->getContainerSize();
|
||||
if (size > 27)
|
||||
size = 27;
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
{
|
||||
WriteInventoryItemData(ec->getItem(i), i, outData);
|
||||
}
|
||||
}
|
||||
|
||||
void __cdecl NativeSetEnderChestSlot(int entityId, int slot, int itemId, int count, int aux)
|
||||
{
|
||||
auto player = FindPlayer(entityId);
|
||||
if (!player)
|
||||
return;
|
||||
auto ec = player->getEnderChestInventory();
|
||||
if (!ec)
|
||||
return;
|
||||
if (slot < 0 || slot >= (int)ec->getContainerSize())
|
||||
return;
|
||||
if (itemId <= 0 || count <= 0)
|
||||
ec->setItem(slot, nullptr);
|
||||
else
|
||||
ec->setItem(slot, std::make_shared<ItemInstance>(itemId, count, aux));
|
||||
}
|
||||
|
||||
void __cdecl NativeSetSneaking(int entityId, int sneak)
|
||||
{
|
||||
auto player = FindPlayer(entityId);
|
||||
|
||||
@@ -52,6 +52,12 @@ namespace FourKitBridge
|
||||
void __cdecl NativeSetItemMeta(int entityId, int slot, const char *inBuf, int bufSize);
|
||||
void __cdecl NativeSetHeldItemSlot(int entityId, int slot);
|
||||
|
||||
// carried item (cursor) & ender chest
|
||||
void __cdecl NativeGetCarriedItem(int entityId, int *outData);
|
||||
void __cdecl NativeSetCarriedItem(int entityId, int itemId, int count, int aux);
|
||||
void __cdecl NativeGetEnderChestContents(int entityId, int *outData);
|
||||
void __cdecl NativeSetEnderChestSlot(int entityId, int slot, int itemId, int count, int aux);
|
||||
|
||||
// ent
|
||||
void __cdecl NativeSetSneaking(int entityId, int sneak);
|
||||
void __cdecl NativeSetVelocity(int entityId, double x, double y, double z);
|
||||
|
||||
Reference in New Issue
Block a user