diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/LevelSoundPacket.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/LevelSoundPacket.cpp')
| -rw-r--r-- | Minecraft.World/LevelSoundPacket.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/Minecraft.World/LevelSoundPacket.cpp b/Minecraft.World/LevelSoundPacket.cpp new file mode 100644 index 00000000..cbe31a2d --- /dev/null +++ b/Minecraft.World/LevelSoundPacket.cpp @@ -0,0 +1,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 = (int) (x * LOCATION_ACCURACY); + this->y = (int) (y * LOCATION_ACCURACY); + this->z = (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; +} |
