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 "net.minecraft.world.entity.h"
5#include "PacketListener.h"
6#include "SetEntityMotionPacket.h"
7
8
9
10void SetEntityMotionPacket::_init(int id, double xd, double yd, double zd)
11{
12 this->id = id;
13 double m = 3.9;
14 if (xd < -m) xd = -m;
15 if (yd < -m) yd = -m;
16 if (zd < -m) zd = -m;
17 if (xd > m) xd = m;
18 if (yd > m) yd = m;
19 if (zd > m) zd = m;
20 xa = (int) (xd * 8000.0);
21 ya = (int) (yd * 8000.0);
22 za = (int) (zd * 8000.0);
23 // 4J - if we could transmit this as bytes (in 1/16 accuracy) then flag to do so
24 if( ( xa >= (-128 * 16 ) ) && ( ya >= (-128 * 16 ) ) && ( za >= (-128 * 16 ) ) &&
25 ( xa < (128 * 16 ) ) && ( ya < (128 * 16 ) ) && ( za < (128 * 16 ) ) )
26 {
27 useBytes = true;
28 }
29 else
30 {
31 useBytes = false;
32 }
33}
34
35SetEntityMotionPacket::SetEntityMotionPacket()
36{
37 _init(0, 0.0f, 0.0f, 0.0f);
38}
39
40SetEntityMotionPacket::SetEntityMotionPacket(shared_ptr<Entity> e)
41{
42 _init(e->entityId, e->xd, e->yd, e->zd);
43}
44
45SetEntityMotionPacket::SetEntityMotionPacket(int id, double xd, double yd, double zd)
46{
47 _init(id, xd, yd, zd);
48}
49
50void SetEntityMotionPacket::read(DataInputStream *dis) //throws IOException
51{
52 short idAndFlag = dis->readShort();
53 id = idAndFlag & 0x07ff;
54 if( idAndFlag & 0x0800 )
55 {
56 xa = (int)dis->readByte();
57 ya = (int)dis->readByte();
58 za = (int)dis->readByte();
59 xa = ( xa << 24 ) >> 24;
60 ya = ( ya << 24 ) >> 24;
61 za = ( za << 24 ) >> 24;
62 xa *= 16;
63 ya *= 16;
64 za *= 16;
65 useBytes = true;
66 }
67 else
68 {
69 xa = dis->readShort();
70 ya = dis->readShort();
71 za = dis->readShort();
72 useBytes = false;
73 }
74}
75
76void SetEntityMotionPacket::write(DataOutputStream *dos) //throws IOException
77{
78 if( useBytes )
79 {
80 dos->writeShort(id | 0x800);
81 dos->writeByte(xa/16);
82 dos->writeByte(ya/16);
83 dos->writeByte(za/16);
84 }
85 else
86 {
87 dos->writeShort(id);
88 dos->writeShort(xa);
89 dos->writeShort(ya);
90 dos->writeShort(za);
91 }
92}
93
94void SetEntityMotionPacket::handle(PacketListener *listener)
95{
96 listener->handleSetEntityMotion(shared_from_this());
97}
98
99int SetEntityMotionPacket::getEstimatedSize()
100{
101 return useBytes ? 5 : 8;
102}
103
104bool SetEntityMotionPacket::canBeInvalidated()
105{
106 return true;
107}
108
109bool SetEntityMotionPacket::isInvalidatedBy(shared_ptr<Packet> packet)
110{
111 shared_ptr<SetEntityMotionPacket> target = dynamic_pointer_cast<SetEntityMotionPacket>(packet);
112 return target->id == id;
113}