the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 112 lines 2.0 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "net.minecraft.world.item.h" 5#include "PacketListener.h" 6#include "UseItemPacket.h" 7 8const float UseItemPacket::CLICK_ACCURACY = 16.0f; 9 10UseItemPacket::~UseItemPacket() 11{ 12} 13 14UseItemPacket::UseItemPacket() 15{ 16 x = 0; 17 y = 0; 18 z = 0; 19 face = 0; 20 item = nullptr; 21 clickX = 0.0f; 22 clickY = 0.0f; 23 clickZ = 0.0f; 24} 25 26UseItemPacket::UseItemPacket(int x, int y, int z, int face, shared_ptr<ItemInstance> item, float clickX, float clickY, float clickZ) 27{ 28 this->x = x; 29 this->y = y; 30 this->z = z; 31 this->face = face; 32 // 4J - take copy of item as we want our packets to have full ownership of any referenced data 33 this->item = item ? item->copy() : shared_ptr<ItemInstance>(); 34 this->clickX = clickX; 35 this->clickY = clickY; 36 this->clickZ = clickZ; 37} 38 39void UseItemPacket::read(DataInputStream *dis) //throws IOException 40{ 41 x = dis->readInt(); 42 y = dis->readUnsignedByte(); 43 z = dis->readInt(); 44 face = dis->read(); 45 item = readItem(dis); 46 clickX = dis->readUnsignedByte() / CLICK_ACCURACY; 47 clickY = dis->readUnsignedByte() / CLICK_ACCURACY; 48 clickZ = dis->readUnsignedByte() / CLICK_ACCURACY; 49} 50 51void UseItemPacket::write(DataOutputStream *dos) //throws IOException 52{ 53 dos->writeInt(x); 54 dos->write(y); 55 dos->writeInt(z); 56 dos->write(face); 57 58 writeItem(item, dos); 59 dos->write((int) (clickX * CLICK_ACCURACY)); 60 dos->write((int) (clickY * CLICK_ACCURACY)); 61 dos->write((int) (clickZ * CLICK_ACCURACY)); 62} 63 64void UseItemPacket::handle(PacketListener *listener) 65{ 66 listener->handleUseItem(shared_from_this()); 67} 68 69int UseItemPacket::getEstimatedSize() 70{ 71 return 15; 72} 73 74int UseItemPacket::getX() 75{ 76 return x; 77} 78 79int UseItemPacket::getY() 80{ 81 return y; 82} 83 84int UseItemPacket::getZ() 85{ 86 return z; 87} 88 89int UseItemPacket::getFace() 90{ 91 return face; 92} 93 94shared_ptr<ItemInstance> UseItemPacket::getItem() 95{ 96 return item; 97} 98 99float UseItemPacket::getClickX() 100{ 101 return clickX; 102} 103 104float UseItemPacket::getClickY() 105{ 106 return clickY; 107} 108 109float UseItemPacket::getClickZ() 110{ 111 return clickZ; 112}