the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 142 lines 3.8 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "net.minecraft.world.entity.player.h" 5#include "net.minecraft.world.item.h" 6#include "PacketListener.h" 7#include "AddPlayerPacket.h" 8 9 10 11AddPlayerPacket::AddPlayerPacket() 12{ 13 id = -1; 14 name = L""; 15 x = 0; 16 y = 0; 17 z = 0; 18 yRot = 0; 19 xRot = 0; 20 carriedItem = 0; 21 xuid = INVALID_XUID; 22 m_playerIndex = 0; 23 m_skinId = 0; 24 m_capeId = 0; 25 m_uiGamePrivileges = 0; 26 entityData = nullptr; 27 unpack = NULL; 28} 29 30AddPlayerPacket::~AddPlayerPacket() 31{ 32 if(unpack != NULL) delete unpack; 33} 34 35AddPlayerPacket::AddPlayerPacket(shared_ptr<Player> player, PlayerUID xuid, PlayerUID OnlineXuid,int xp, int yp, int zp, int yRotp, int xRotp, int yHeadRotp) 36{ 37 id = player->entityId; 38 name = player->getName(); 39 40 // 4J Stu - Send "previously sent" value of position as well so that we stay in sync 41 x = xp;//Mth::floor(player->x * 32); 42 y = yp;//Mth::floor(player->y * 32); 43 z = zp;//Mth::floor(player->z * 32); 44 // 4J - changed - send current "previously sent" value of rotations to put this in sync with other clients 45 yRot = yRotp; 46 xRot = xRotp; 47 yHeadRot = yHeadRotp; // 4J Added 48 // yRot = (byte) (player->yRot * 256 / 360); 49 // xRot = (byte) (player->xRot * 256 / 360); 50 51 //printf("%d: New add player (%f,%f,%f) : (%d,%d,%d) : xRot %d, yRot %d\n",id,player->x,player->y,player->z,x,y,z,xRot,yRot); 52 53 shared_ptr<ItemInstance> itemInstance = player->inventory->getSelected(); 54 carriedItem = itemInstance == NULL ? 0 : itemInstance->id; 55 56 this->xuid = xuid; 57 this->OnlineXuid = OnlineXuid; 58 m_playerIndex = (BYTE)player->getPlayerIndex(); 59 m_skinId = player->getCustomSkin(); 60 m_capeId = player->getCustomCape(); 61 m_uiGamePrivileges = player->getAllPlayerGamePrivileges(); 62 63 entityData = player->getEntityData(); 64 unpack = NULL; 65} 66 67void AddPlayerPacket::read(DataInputStream *dis) //throws IOException 68{ 69 id = dis->readInt(); 70 name = readUtf(dis, Player::MAX_NAME_LENGTH); 71 x = dis->readInt(); 72 y = dis->readInt(); 73 z = dis->readInt(); 74 yRot = dis->readByte(); 75 xRot = dis->readByte(); 76 yHeadRot = dis->readByte(); // 4J Added 77 carriedItem = dis->readShort(); 78 xuid = dis->readPlayerUID(); 79 OnlineXuid = dis->readPlayerUID(); 80 m_playerIndex = dis->readByte(); 81 INT skinId = dis->readInt(); 82 m_skinId = *(DWORD *)&skinId; 83 INT capeId = dis->readInt(); 84 m_capeId = *(DWORD *)&capeId; 85 INT privileges = dis->readInt(); 86 m_uiGamePrivileges = *(unsigned int *)&privileges; 87 MemSect(1); 88 unpack = SynchedEntityData::unpack(dis); 89 MemSect(0); 90} 91 92void AddPlayerPacket::write(DataOutputStream *dos) //throws IOException 93{ 94 dos->writeInt(id); 95 writeUtf(name, dos); 96 dos->writeInt(x); 97 dos->writeInt(y); 98 dos->writeInt(z); 99 dos->writeByte(yRot); 100 dos->writeByte(xRot); 101 dos->writeByte(yHeadRot); // 4J Added 102 dos->writeShort(carriedItem); 103 dos->writePlayerUID(xuid); 104 dos->writePlayerUID(OnlineXuid); 105 dos->writeByte(m_playerIndex); 106 dos->writeInt(m_skinId); 107 dos->writeInt(m_capeId); 108 dos->writeInt(m_uiGamePrivileges); 109 entityData->packAll(dos); 110 111} 112 113void AddPlayerPacket::handle(PacketListener *listener) 114{ 115 listener->handleAddPlayer(shared_from_this()); 116} 117 118int AddPlayerPacket::getEstimatedSize() 119{ 120 int iSize= sizeof(int) + Player::MAX_NAME_LENGTH + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(BYTE) + sizeof(BYTE) +sizeof(short) + sizeof(PlayerUID) + sizeof(PlayerUID) + sizeof(int) + sizeof(BYTE) + sizeof(unsigned int) + sizeof(byte); 121 122 if( entityData != NULL ) 123 { 124 iSize += entityData->getSizeInBytes(); 125 } 126 else if( unpack != NULL ) 127 { 128 // 4J Stu - This is an incoming value which we aren't currently analysing 129 //iSize += unpack->get 130 } 131 132 return iSize; 133} 134 135vector<shared_ptr<SynchedEntityData::DataItem> > *AddPlayerPacket::getUnpackedData() 136{ 137 if (unpack == NULL) 138 { 139 unpack = entityData->getAll(); 140 } 141 return unpack; 142}