From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/GiveItemCommand.cpp | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Minecraft.World/GiveItemCommand.cpp (limited to 'Minecraft.World/GiveItemCommand.cpp') diff --git a/Minecraft.World/GiveItemCommand.cpp b/Minecraft.World/GiveItemCommand.cpp new file mode 100644 index 00000000..1d13592f --- /dev/null +++ b/Minecraft.World/GiveItemCommand.cpp @@ -0,0 +1,50 @@ +#include "stdafx.h" +#include "net.minecraft.commands.h" +#include "net.minecraft.world.item.h" +#include "net.minecraft.network.packet.h" +#include "..\Minecraft.Client\ServerPlayer.h" +#include "GiveItemCommand.h" + +EGameCommand GiveItemCommand::getId() +{ + return eGameCommand_Give; +} + +void GiveItemCommand::execute(shared_ptr source, byteArray commandData) +{ + ByteArrayInputStream bais(commandData); + DataInputStream dis(&bais); + + PlayerUID uid = dis.readPlayerUID(); + int item = dis.readInt(); + int amount = dis.readInt(); + int aux = dis.readInt(); + wstring tag = dis.readUTF(); + + bais.reset(); + + shared_ptr player = getPlayer(uid); + if(player != NULL && item > 0 && Item::items[item] != NULL) + { + shared_ptr itemInstance = shared_ptr(new ItemInstance(item, amount, aux)); + player->drop(itemInstance); + //logAdminAction(source, L"commands.give.success", ChatPacket::e_ChatCustom, Item::items[item]->getName(itemInstance), item, amount, player->getAName()); + logAdminAction(source, ChatPacket::e_ChatCustom, L"commands.give.success", item, player->getAName()); + } +} + +shared_ptr GiveItemCommand::preparePacket(shared_ptr player, int item, int amount, int aux, const wstring &tag) +{ + if(player == NULL) return nullptr; + + ByteArrayOutputStream baos; + DataOutputStream dos(&baos); + + dos.writePlayerUID(player->getXuid()); + dos.writeInt(item); + dos.writeInt(amount); + dos.writeInt(aux); + dos.writeUTF(tag); + + return shared_ptr( new GameCommandPacket(eGameCommand_Give, baos.toByteArray() )); +} \ No newline at end of file -- cgit v1.2.3