the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include <iostream>
3#include "InputOutputStream.h"
4#include "PacketListener.h"
5#include "MoveEntityPacket.h"
6
7MoveEntityPacket::MoveEntityPacket()
8{
9 hasRot = false;
10
11 id = -1;
12 xa = 0;
13 ya = 0;
14 za = 0;
15 yRot = 0;
16 xRot = 0;
17}
18
19MoveEntityPacket::MoveEntityPacket(int id)
20{
21 this->id = id;
22 hasRot = false;
23
24 xa = 0;
25 ya = 0;
26 za = 0;
27 yRot = 0;
28 xRot = 0;
29}
30
31void MoveEntityPacket::read(DataInputStream *dis) //throws IOException
32{
33 id = dis->readShort();
34}
35
36void MoveEntityPacket::write(DataOutputStream *dos) //throws IOException
37{
38 if( (id < 0 ) || (id >= 2048 ) )
39 {
40 // We shouln't be tracking an entity that doesn't have a short type of id
41 __debugbreak();
42 }
43 dos->writeShort((short)id);
44}
45
46void MoveEntityPacket::handle(PacketListener *listener)
47{
48 listener->handleMoveEntity(shared_from_this());
49}
50
51int MoveEntityPacket::getEstimatedSize()
52{
53 return 2;
54}
55
56bool MoveEntityPacket::canBeInvalidated()
57{
58 return true;
59}
60
61bool MoveEntityPacket::isInvalidatedBy(shared_ptr<Packet> packet)
62{
63 shared_ptr<MoveEntityPacket> target = dynamic_pointer_cast<MoveEntityPacket>(packet);
64 return target != NULL && target->id == id;
65}
66
67MoveEntityPacket::PosRot::PosRot()
68{
69 hasRot = true;
70}
71
72MoveEntityPacket::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacket( id )
73{
74 this->xa = xa;
75 this->ya = ya;
76 this->za = za;
77 this->yRot = yRot;
78 this->xRot = xRot;
79 hasRot = true;
80}
81
82void MoveEntityPacket::PosRot::read(DataInputStream *dis) //throws IOException
83{
84 MoveEntityPacket::read(dis);
85 xa = dis->readByte();
86 ya = dis->readByte();
87 za = dis->readByte();
88 yRot = dis->readByte();
89 xRot = dis->readByte();
90}
91
92void MoveEntityPacket::PosRot::write(DataOutputStream *dos) //throws IOException
93{
94 MoveEntityPacket::write(dos);
95 dos->writeByte(xa);
96 dos->writeByte(ya);
97 dos->writeByte(za);
98 dos->writeByte(yRot);
99 dos->writeByte(xRot);
100}
101
102int MoveEntityPacket::PosRot::getEstimatedSize()
103{
104 return 2+5;
105}
106
107MoveEntityPacket::Pos::Pos()
108{
109}
110
111MoveEntityPacket::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacket(id)
112{
113 this->xa = xa;
114 this->ya = ya;
115 this->za = za;
116}
117
118void MoveEntityPacket::Pos::read(DataInputStream *dis) //throws IOException
119{
120 MoveEntityPacket::read(dis);
121 xa = dis->readByte();
122 ya = dis->readByte();
123 za = dis->readByte();
124}
125
126void MoveEntityPacket::Pos::write(DataOutputStream *dos) //throws IOException
127{
128 MoveEntityPacket::write(dos);
129 dos->writeByte(xa);
130 dos->writeByte(ya);
131 dos->writeByte(za);
132}
133
134int MoveEntityPacket::Pos::getEstimatedSize()
135{
136 return 2+3;
137}
138
139MoveEntityPacket::Rot::Rot()
140{
141 hasRot = true;
142}
143
144MoveEntityPacket::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket(id)
145{
146 this->yRot = yRot;
147 this->xRot = xRot;
148 hasRot = true;
149}
150
151void MoveEntityPacket::Rot::read(DataInputStream *dis) //throws IOException
152{
153 MoveEntityPacket::read(dis);
154 yRot = dis->readByte();
155 xRot = dis->readByte();
156}
157
158void MoveEntityPacket::Rot::write(DataOutputStream *dos) //throws IOException
159{
160 MoveEntityPacket::write(dos);
161 dos->writeByte(yRot);
162 dos->writeByte(xRot);
163}
164
165int MoveEntityPacket::Rot::getEstimatedSize()
166{
167 return 2+2;
168}