aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/LevelSoundPacket.cpp
blob: cc2e29c45abc56d7eb13378d20f359c200485984 (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
#include "stdafx.h"
#include "BasicTypeContainers.h"
#include "InputOutputStream.h"
#include "net.minecraft.network.packet.h"
#include "LevelSoundPacket.h"

const float LevelSoundPacket::PITCH_ACCURACY = Byte::MAX_VALUE / 2.0f;
const float LevelSoundPacket::LOCATION_ACCURACY = 8.0f;

LevelSoundPacket::LevelSoundPacket()
{
	sound = 0;
	x = 0;
	y = Integer::MAX_VALUE;
	z = 0;
	volume = 0.0f;
	pitch = 0;
}

LevelSoundPacket::LevelSoundPacket(int sound, double x, double y, double z, float volume, float pitch)
{
	this->sound = sound;
	this->x = static_cast<int>(x * LOCATION_ACCURACY);
	this->y = static_cast<int>(y * LOCATION_ACCURACY);
	this->z = static_cast<int>(z * LOCATION_ACCURACY);
	this->volume = volume;
	// 4J-PB - Let's make the pitch a float so it doesn't get mangled and make the noteblock people unhappy
	//this->pitch = (int) (pitch * PITCH_ACCURACY);
	this->pitch = pitch;

// 	if (this->pitch < 0) this->pitch = 0;
// 	if (this->pitch > 255) this->pitch = 255;
}

void LevelSoundPacket::read(DataInputStream *dis)
{
	sound = dis->readInt();
	x = dis->readInt();
	y = dis->readInt();
	z = dis->readInt();
	volume = dis->readFloat();
	//pitch = dis->readUnsignedByte();
	pitch = dis->readFloat();
}

void LevelSoundPacket::write(DataOutputStream *dos)
{
	dos->writeInt(sound);
	dos->writeInt(x);
	dos->writeInt(y);
	dos->writeInt(z);
	dos->writeFloat(volume);
	//dos->writeByte(pitch);
	dos->writeFloat(pitch);
}

int LevelSoundPacket::getSound()
{
	return sound;
}

double LevelSoundPacket::getX()
{
	return x / LOCATION_ACCURACY;
}

double LevelSoundPacket::getY()
{
	return y / LOCATION_ACCURACY;
}

double LevelSoundPacket::getZ()
{
	return z / LOCATION_ACCURACY;
}

float LevelSoundPacket::getVolume()
{
	return volume;
}

float LevelSoundPacket::getPitch()
{
	//return pitch / PITCH_ACCURACY;
	return pitch;
}

void LevelSoundPacket::handle(PacketListener *listener)
{
	listener->handleSoundEvent(shared_from_this());
}

int LevelSoundPacket::getEstimatedSize()
{
	return 4 * 6;
}