the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 140 lines 3.0 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "net.minecraft.world.entity.h" 5#include "PacketListener.h" 6#include "AddMobPacket.h" 7 8 9 10AddMobPacket::AddMobPacket() 11{ 12 id = -1; 13 type = 0; 14 x = 0; 15 y = 0; 16 z = 0; 17 yRot = 0; 18 xRot = 0; 19 entityData = nullptr; 20 unpack = NULL; 21} 22 23AddMobPacket::~AddMobPacket() 24{ 25 delete unpack; 26} 27 28AddMobPacket::AddMobPacket(shared_ptr<LivingEntity> mob, int yRotp, int xRotp, int xp, int yp, int zp, int yHeadRotp) 29{ 30 id = mob->entityId; 31 32 type = (byte) EntityIO::getId(mob); 33 // 4J Stu - We should add entities at their "last sent" position so that the relative update packets 34 // put them in the correct place 35 x = xp;//Mth::floor(mob->x * 32); 36 y = yp;//Mth::floor(mob->y * 32); 37 z = zp;//Mth::floor(mob->z * 32); 38 // 4J - changed - send current "previously sent" value of rotations to put this in sync with other clients 39 yRot = yRotp; 40 xRot = xRotp; 41 yHeadRot = yHeadRotp; 42 // yRot = (byte) (mob->yRot * 256 / 360); 43 // xRot = (byte) (mob->xRot * 256 / 360); 44 // yHeadRot = (byte) (mob->yHeadRot * 256 / 360); 45 46 // From SetEntityMotionpacket 47 double m = 3.9; 48 double xd = mob->xd; 49 double yd = mob->yd; 50 double zd = mob->zd; 51 if (xd < -m) xd = -m; 52 if (yd < -m) yd = -m; 53 if (zd < -m) zd = -m; 54 if (xd > m) xd = m; 55 if (yd > m) yd = m; 56 if (zd > m) zd = m; 57 this->xd = (int) (xd * 8000.0); 58 this->yd = (int) (yd * 8000.0); 59 this->zd = (int) (zd * 8000.0); 60 61 // printf("%d: New add mob rot %d\n",id,yRot); 62 63 entityData = mob->getEntityData(); 64 unpack = NULL; 65} 66 67void AddMobPacket::read(DataInputStream *dis) //throws IOException 68{ 69 id = dis->readShort(); 70 type = dis->readByte() & 0xff; 71#ifdef _LARGE_WORLDS 72 x = dis->readInt(); 73 y = dis->readInt(); 74 z = dis->readInt(); 75#else 76 x = dis->readShort(); 77 y = dis->readShort(); 78 z = dis->readShort(); 79#endif 80 yRot = dis->readByte(); 81 xRot = dis->readByte(); 82 yHeadRot = dis->readByte(); 83 xd = dis->readShort(); 84 yd = dis->readShort(); 85 zd = dis->readShort(); 86 MemSect(1); 87 unpack = SynchedEntityData::unpack(dis); 88 MemSect(0); 89} 90 91void AddMobPacket::write(DataOutputStream *dos) //throws IOException 92{ 93 dos->writeShort(id); 94 dos->writeByte(type & 0xff); 95#ifdef _LARGE_WORLDS 96 dos->writeInt(x); 97 dos->writeInt(y); 98 dos->writeInt(z); 99#else 100 dos->writeShort(x); 101 dos->writeShort(y); 102 dos->writeShort(z); 103#endif 104 dos->writeByte(yRot); 105 dos->writeByte(xRot); 106 dos->writeByte(yHeadRot); 107 dos->writeShort(xd); 108 dos->writeShort(yd); 109 dos->writeShort(zd); 110 entityData->packAll(dos); 111} 112 113void AddMobPacket::handle(PacketListener *listener) 114{ 115 listener->handleAddMob(shared_from_this()); 116} 117 118int AddMobPacket::getEstimatedSize() 119{ 120 int size = 11; 121 if( entityData != NULL ) 122 { 123 size += entityData->getSizeInBytes(); 124 } 125 else if( unpack != NULL ) 126 { 127 // 4J Stu - This is an incoming value which we aren't currently analysing 128 //size += unpack->get 129 } 130 return size; 131} 132 133vector<shared_ptr<SynchedEntityData::DataItem> > *AddMobPacket::getUnpackedData() 134{ 135 if (unpack == NULL) 136 { 137 unpack = entityData->getAll(); 138 } 139 return unpack; 140}