aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ExplodePacket.cpp
blob: 30d09e4643c4f58c8d7175fbe84b633d110e5a01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "net.minecraft.world.level.h"
#include "PacketListener.h"
#include "ExplodePacket.h"



ExplodePacket::ExplodePacket() 
{
	x = 0;
	y = 0;
	z = 0;
	r = 0.0f;
	m_bKnockbackOnly = false;
	knockbackX = 0.0f;
	knockbackY = 0.0f;
	knockbackZ = 0.0f;
}

ExplodePacket::ExplodePacket(double x, double y, double z, float r, unordered_set<TilePos, TilePosKeyHash, TilePosKeyEq> *toBlow, Vec3 *knockback, bool knockBackOnly)
{
	this->x = x;
	this->y = y;
	this->z = z;
	this->r = r;
	m_bKnockbackOnly = knockBackOnly;

	if(toBlow != nullptr)
	{
		this->toBlow.assign(toBlow->begin(),toBlow->end());
	}

	if (knockback != nullptr)
	{
		knockbackX = (float) knockback->x;
		knockbackY = (float) knockback->y;
		knockbackZ = (float) knockback->z;
	}
}

void ExplodePacket::read(DataInputStream *dis) //throws IOException 
{
	m_bKnockbackOnly = dis->readBoolean();

	if(!m_bKnockbackOnly)
	{
		x = dis->readDouble();
		y = dis->readDouble();
		z = dis->readDouble();
		r = dis->readFloat();
		int count = dis->readInt();

		int xp = (int)x;
		int yp = (int)y;
		int zp = (int)z;
		for (int i=0; i<count; i++) 
		{
			int xx = ((signed char)dis->readByte())+xp;
			int yy = ((signed char)dis->readByte())+yp;
			int zz = ((signed char)dis->readByte())+zp;
			toBlow.push_back( TilePos(xx, yy, zz) );
		}
	}

	knockbackX = dis->readFloat();
	knockbackY = dis->readFloat();
	knockbackZ = dis->readFloat();
}

void ExplodePacket::write(DataOutputStream *dos) //throws IOException 
{
	dos->writeBoolean(m_bKnockbackOnly);

	if(!m_bKnockbackOnly)
	{
		dos->writeDouble(x);
		dos->writeDouble(y);
		dos->writeDouble(z);
		dos->writeFloat(r);
		dos->writeInt((int)toBlow.size());

		int xp = (int)x;
		int yp = (int)y;
		int zp = (int)z;

		for ( const TilePos& tp : toBlow )
		{
			int xx = tp.x-xp;
			int yy = tp.y-yp;
			int zz = tp.z-zp;
			dos->writeByte(xx);
			dos->writeByte(yy);
			dos->writeByte(zz);
		}
	}

	dos->writeFloat(knockbackX);
	dos->writeFloat(knockbackY);
	dos->writeFloat(knockbackZ);
}

void ExplodePacket::handle(PacketListener *listener)
{
	listener->handleExplosion(shared_from_this());
}

int ExplodePacket::getEstimatedSize() 
{
	return 8*3+4+4+(int)toBlow.size()*3+12;
}

float ExplodePacket::getKnockbackX()
{
	return knockbackX;
}

float ExplodePacket::getKnockbackY()
{
	return knockbackY;
}

float ExplodePacket::getKnockbackZ()
{
	return knockbackZ;
}