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.level.h"
5#include "PacketListener.h"
6#include "ExplodePacket.h"
7
8
9
10ExplodePacket::ExplodePacket()
11{
12 x = 0;
13 y = 0;
14 z = 0;
15 r = 0.0f;
16 m_bKnockbackOnly = false;
17 knockbackX = 0.0f;
18 knockbackY = 0.0f;
19 knockbackZ = 0.0f;
20}
21
22ExplodePacket::ExplodePacket(double x, double y, double z, float r, unordered_set<TilePos, TilePosKeyHash, TilePosKeyEq> *toBlow, Vec3 *knockback, bool knockBackOnly)
23{
24 this->x = x;
25 this->y = y;
26 this->z = z;
27 this->r = r;
28 m_bKnockbackOnly = knockBackOnly;
29
30 if(toBlow != NULL)
31 {
32 this->toBlow.assign(toBlow->begin(),toBlow->end());
33 //for( AUTO_VAR(it, toBlow->begin()); it != toBlow->end(); it++ )
34 //{
35 // this->toBlow.push_back(*it);
36 //}
37 }
38
39 if (knockback != NULL)
40 {
41 knockbackX = (float) knockback->x;
42 knockbackY = (float) knockback->y;
43 knockbackZ = (float) knockback->z;
44 }
45}
46
47void ExplodePacket::read(DataInputStream *dis) //throws IOException
48{
49 m_bKnockbackOnly = dis->readBoolean();
50
51 if(!m_bKnockbackOnly)
52 {
53 x = dis->readDouble();
54 y = dis->readDouble();
55 z = dis->readDouble();
56 r = dis->readFloat();
57 int count = dis->readInt();
58
59 int xp = (int)x;
60 int yp = (int)y;
61 int zp = (int)z;
62 for (int i=0; i<count; i++)
63 {
64 int xx = ((signed char)dis->readByte())+xp;
65 int yy = ((signed char)dis->readByte())+yp;
66 int zz = ((signed char)dis->readByte())+zp;
67 toBlow.push_back( TilePos(xx, yy, zz) );
68 }
69 }
70
71 knockbackX = dis->readFloat();
72 knockbackY = dis->readFloat();
73 knockbackZ = dis->readFloat();
74}
75
76void ExplodePacket::write(DataOutputStream *dos) //throws IOException
77{
78 dos->writeBoolean(m_bKnockbackOnly);
79
80 if(!m_bKnockbackOnly)
81 {
82 dos->writeDouble(x);
83 dos->writeDouble(y);
84 dos->writeDouble(z);
85 dos->writeFloat(r);
86 dos->writeInt((int)toBlow.size());
87
88 int xp = (int)x;
89 int yp = (int)y;
90 int zp = (int)z;
91
92 //(Myset::const_iterator it = c1.begin();
93 //it != c1.end(); ++it)
94
95 for( AUTO_VAR(it, toBlow.begin()); it != toBlow.end(); it++ )
96 {
97 TilePos tp = *it;
98
99 int xx = tp.x-xp;
100 int yy = tp.y-yp;
101 int zz = tp.z-zp;
102 dos->writeByte(xx);
103 dos->writeByte(yy);
104 dos->writeByte(zz);
105 }
106 }
107
108 dos->writeFloat(knockbackX);
109 dos->writeFloat(knockbackY);
110 dos->writeFloat(knockbackZ);
111}
112
113void ExplodePacket::handle(PacketListener *listener)
114{
115 listener->handleExplosion(shared_from_this());
116}
117
118int ExplodePacket::getEstimatedSize()
119{
120 return 8*3+4+4+(int)toBlow.size()*3+12;
121}
122
123float ExplodePacket::getKnockbackX()
124{
125 return knockbackX;
126}
127
128float ExplodePacket::getKnockbackY()
129{
130 return knockbackY;
131}
132
133float ExplodePacket::getKnockbackZ()
134{
135 return knockbackZ;
136}