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 <exception>
3#include <iostream>
4#include "InputOutputStream.h"
5#include "net.minecraft.world.entity.h"
6#include "PacketListener.h"
7#include "AddEntityPacket.h"
8
9
10
11void AddEntityPacket::_init(shared_ptr<Entity> e, int type, int data, int xp, int yp, int zp, int yRotp, int xRotp)
12{
13 id = e->entityId;
14 // 4J Stu - We should add entities at their "last sent" position so that the relative update packets
15 // put them in the correct place
16 x = xp;//(int) floor(e->x * 32);
17 y = yp;//(int) floor(e->y * 32);
18 z = zp;//(int) floor(e->z * 32);
19 yRot = yRotp;
20 xRot = xRotp;
21 this->type = type;
22 this->data = data;
23 if (data > -1) // 4J - changed "no data" value to be -1, we can have a valid entity id of 0
24 {
25 double xd = e->xd;
26 double yd = e->yd;
27 double zd = e->zd;
28 double m = 3.9;
29 if (xd < -m) xd = -m;
30 if (yd < -m) yd = -m;
31 if (zd < -m) zd = -m;
32 if (xd > m) xd = m;
33 if (yd > m) yd = m;
34 if (zd > m) zd = m;
35 xa = (int) (xd * 8000.0);
36 ya = (int) (yd * 8000.0);
37 za = (int) (zd * 8000.0);
38 }
39}
40
41AddEntityPacket::AddEntityPacket()
42{
43}
44
45AddEntityPacket::AddEntityPacket(shared_ptr<Entity> e, int type, int yRotp, int xRotp, int xp, int yp, int zp )
46{
47 _init(e, type, -1, xp, yp, zp, yRotp, xRotp); // 4J - changed "no data" value to be -1, we can have a valid entity id of 0
48}
49
50AddEntityPacket::AddEntityPacket(shared_ptr<Entity> e, int type, int data, int yRotp, int xRotp, int xp, int yp, int zp )
51{
52 _init(e, type, data, xp, yp, zp, yRotp, xRotp);
53}
54
55void AddEntityPacket::read(DataInputStream *dis) // throws IOException TODO 4J JEV add throws statement
56{
57 id = dis->readShort();
58 type = dis->readByte();
59#ifdef _LARGE_WORLDS
60 x = dis->readInt();
61 y = dis->readInt();
62 z = dis->readInt();
63#else
64 x = dis->readShort();
65 y = dis->readShort();
66 z = dis->readShort();
67#endif
68 yRot = dis->readByte();
69 xRot = dis->readByte();
70 data = dis->readInt();
71 if (data > -1) // 4J - changed "no data" value to be -1, we can have a valid entity id of 0
72 {
73 xa = dis->readShort();
74 ya = dis->readShort();
75 za = dis->readShort();
76 }
77}
78
79void AddEntityPacket::write(DataOutputStream *dos) // throws IOException TODO 4J JEV add throws statement
80{
81 dos->writeShort(id);
82 dos->writeByte(type);
83#ifdef _LARGE_WORLDS
84 dos->writeInt(x);
85 dos->writeInt(y);
86 dos->writeInt(z);
87#else
88 dos->writeShort(x);
89 dos->writeShort(y);
90 dos->writeShort(z);
91#endif
92 dos->writeByte(yRot);
93 dos->writeByte(xRot);
94 dos->writeInt(data);
95 if (data > -1) // 4J - changed "no data" value to be -1, we can have a valid entity id of 0
96 {
97 dos->writeShort(xa);
98 dos->writeShort(ya);
99 dos->writeShort(za);
100 }
101}
102
103void AddEntityPacket::handle(PacketListener *listener)
104{
105 listener->handleAddEntity(shared_from_this());
106}
107
108int AddEntityPacket::getEstimatedSize()
109{
110 return 11 + data > -1 ? 6 : 0;
111}