diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/ContainerClickPacket.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/ContainerClickPacket.cpp')
| -rw-r--r-- | Minecraft.World/ContainerClickPacket.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Minecraft.World/ContainerClickPacket.cpp b/Minecraft.World/ContainerClickPacket.cpp new file mode 100644 index 00000000..5b3ca24f --- /dev/null +++ b/Minecraft.World/ContainerClickPacket.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include <iostream> +#include "InputOutputStream.h" +#include "net.minecraft.world.item.h" +#include "PacketListener.h" +#include "ContainerClickPacket.h" + + + +ContainerClickPacket::~ContainerClickPacket() +{ +} + +ContainerClickPacket::ContainerClickPacket() +{ + containerId = 0; + slotNum = 0; + buttonNum = 0; + uid = 0; + item = nullptr; + quickKey = false; +} + +ContainerClickPacket::ContainerClickPacket(int containerId, int slotNum, int buttonNum, bool quickKey, shared_ptr<ItemInstance> item, short uid) +{ + this->containerId = containerId; + this->slotNum = slotNum; + this->buttonNum = buttonNum; + this->uid = uid; + this->quickKey = quickKey; + // 4J - make a copy of the relevant bits of this item, as we want our packets to have full ownership of any data they reference + this->item = item ? item->copy() : nullptr; +} + +void ContainerClickPacket::handle(PacketListener *listener) +{ + listener->handleContainerClick(shared_from_this()); +} + +void ContainerClickPacket::read(DataInputStream *dis) //throws IOException +{ + containerId = dis->readByte(); + slotNum = dis->readShort(); + buttonNum = dis->readByte(); + uid = dis->readShort(); + quickKey = dis->readBoolean(); + + item = readItem(dis); +} + +void ContainerClickPacket::write(DataOutputStream *dos) // throws IOException +{ + dos->writeByte(containerId); + dos->writeShort(slotNum); + dos->writeByte(buttonNum); + dos->writeShort(uid); + dos->writeBoolean(quickKey); + + writeItem(item, dos); +} + +int ContainerClickPacket::getEstimatedSize() +{ + return 4 + 4 + 2 + 1; +} |
