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 "MovePlayerPacket.h"
6
7MovePlayerPacket::MovePlayerPacket()
8{
9 x = 0;
10 y = 0;
11 z = 0;
12 yView = 0;
13 yRot = 0;
14 xRot = 0;
15 onGround = false;
16 hasPos = false;
17 hasRot = false;
18 isFlying = false;
19}
20
21MovePlayerPacket::MovePlayerPacket(bool onGround, bool isFlying)
22{
23 x = 0;
24 y = 0;
25 z = 0;
26 yView = 0;
27 yRot = 0;
28 xRot = 0;
29 hasPos = false;
30 hasRot = false;
31
32 this->onGround = onGround;
33 this->isFlying = isFlying;
34}
35
36void MovePlayerPacket::handle(PacketListener *listener)
37{
38 listener->handleMovePlayer(shared_from_this());
39}
40
41void MovePlayerPacket::read(DataInputStream *dis) //throws IOException
42{
43 char value = dis->read();
44 onGround = (value & 0x1) != 0;
45 isFlying = (value & 0x2) != 0;
46 //onGround = dis->read() != 0;
47}
48
49void MovePlayerPacket::write(DataOutputStream *dos) //throws IOException
50{
51 char value = (onGround ? 0x1 : 0) | (isFlying ? 0x2 : 0);
52 dos->write(value);
53 //dos->write(onGround ? 1 : 0);
54}
55
56int MovePlayerPacket::getEstimatedSize()
57{
58 return 1;
59}
60
61bool MovePlayerPacket::canBeInvalidated()
62{
63 return true;
64}
65
66bool MovePlayerPacket::isInvalidatedBy(shared_ptr<Packet> packet)
67{
68 return true;
69}
70
71MovePlayerPacket::PosRot::PosRot()
72{
73 hasRot = true;
74 hasPos = true;
75}
76
77MovePlayerPacket::PosRot::PosRot(double x, double y, double yView, double z, float yRot, float xRot, bool onGround, bool isFlying)
78{
79 this->x = x;
80 this->y = y;
81 this->yView = yView;
82 this->z = z;
83 this->yRot = yRot;
84 this->xRot = xRot;
85 this->onGround = onGround;
86 hasRot = true;
87 hasPos = true;
88 this->isFlying = isFlying;
89}
90
91void MovePlayerPacket::PosRot::read(DataInputStream *dis) //throws IOException
92{
93 x = dis->readDouble();
94 y = dis->readDouble();
95 yView = dis->readDouble();
96 z = dis->readDouble();
97 yRot = dis->readFloat();
98 xRot = dis->readFloat();
99 MovePlayerPacket::read(dis);
100}
101
102void MovePlayerPacket::PosRot::write(DataOutputStream *dos) //throws IOException
103{
104 dos->writeDouble(x);
105 dos->writeDouble(y);
106 dos->writeDouble(yView);
107 dos->writeDouble(z);
108 dos->writeFloat(yRot);
109 dos->writeFloat(xRot);
110 MovePlayerPacket::write(dos);
111}
112
113int MovePlayerPacket::PosRot::getEstimatedSize()
114{
115 return 8 * 5 + 1;
116}
117
118MovePlayerPacket::Pos::Pos()
119{
120 hasPos = true;
121}
122
123MovePlayerPacket::Pos::Pos(double x, double y, double yView, double z, bool onGround, bool isFlying)
124{
125 this->x = x;
126 this->y = y;
127 this->yView = yView;
128 this->z = z;
129 this->onGround = onGround;
130 hasPos = true;
131 this->isFlying = isFlying;
132}
133
134void MovePlayerPacket::Pos::read(DataInputStream *dis) //throws IOException
135{
136 x = dis->readDouble();
137 y = dis->readDouble();
138 yView = dis->readDouble();
139 z = dis->readDouble();
140 MovePlayerPacket::read(dis);
141}
142
143void MovePlayerPacket::Pos::write(DataOutputStream *dos) //throws IOException
144{
145 dos->writeDouble(x);
146 dos->writeDouble(y);
147 dos->writeDouble(yView);
148 dos->writeDouble(z);
149 MovePlayerPacket::write(dos);
150}
151
152int MovePlayerPacket::Pos::getEstimatedSize()
153{
154 return 8 * 4 + 1;
155}
156
157MovePlayerPacket::Rot::Rot()
158{
159 hasRot = true;
160}
161
162MovePlayerPacket::Rot::Rot(float yRot, float xRot, bool onGround, bool isFlying)
163{
164 this->yRot = yRot;
165 this->xRot = xRot;
166 this->onGround = onGround;
167 hasRot = true;
168 this->isFlying = isFlying;
169}
170
171void MovePlayerPacket::Rot::read(DataInputStream *dis) //throws IOException
172{
173 yRot = dis->readFloat();
174 xRot = dis->readFloat();
175 MovePlayerPacket::read(dis);
176}
177
178void MovePlayerPacket::Rot::write(DataOutputStream *dos) //throws IOException
179{
180 dos->writeFloat(yRot);
181 dos->writeFloat(xRot);
182 MovePlayerPacket::write(dos);
183}
184
185int MovePlayerPacket::Rot::getEstimatedSize()
186{
187 return 8 + 1;
188}