diff --git a/src/main/java/de/bixilon/minosoft/game/datatypes/SoundCategories.java b/src/main/java/de/bixilon/minosoft/game/datatypes/SoundCategories.java new file mode 100644 index 000000000..9ab3e5b45 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/game/datatypes/SoundCategories.java @@ -0,0 +1,47 @@ +/* + * Codename Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.game.datatypes; + +public enum SoundCategories { + MASTER(0), + MUSIC(1), + RECORD(2), + WEATHER(3), + BLOCK(4), + HOSTILE(5), + NEUTRAL(6), + PLAYER(7), + AMBIENT(8), + VOICE(9); + + + final int id; + + SoundCategories(int id) { + this.id = id; + } + + public static SoundCategories byId(int id) { + for (SoundCategories category : values()) { + if (category.getId() == id) { + return category; + } + } + return null; + } + + public int getId() { + return id; + } +} \ No newline at end of file diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java index a9e8acadb..daad96287 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java @@ -13,6 +13,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; +import de.bixilon.minosoft.game.datatypes.SoundCategories; import de.bixilon.minosoft.game.datatypes.entities.Location; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; @@ -26,7 +27,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket { String sound; float volume; float pitch; - int category; + SoundCategories category; @Override public boolean read(InByteBuffer buffer) { @@ -40,7 +41,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket { return true; case VERSION_1_9_4: sound = buffer.readString(); - category = buffer.readVarInt(); // ToDo: category + category = SoundCategories.byId(buffer.readVarInt()); location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4); volume = buffer.readFloat(); pitch = (buffer.readByte() * pitchCalc) / 100F; @@ -50,7 +51,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket { case VERSION_1_12_2: case VERSION_1_13_2: sound = buffer.readString(); - category = buffer.readVarInt(); // ToDo: category + category = SoundCategories.byId(buffer.readVarInt()); location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4); volume = buffer.readFloat(); pitch = buffer.readFloat(); diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java index 4fa86b03e..3633dbf0e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java @@ -13,6 +13,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; +import de.bixilon.minosoft.game.datatypes.SoundCategories; import de.bixilon.minosoft.game.datatypes.entities.Location; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; @@ -23,8 +24,8 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketSoundEffect implements ClientboundPacket { static final float pitchCalc = 100.0F / 63.0F; Location location; + SoundCategories category; int sound; - int category; float volume; float pitch; @@ -33,7 +34,7 @@ public class PacketSoundEffect implements ClientboundPacket { switch (buffer.getVersion()) { case VERSION_1_9_4: sound = buffer.readVarInt(); - category = buffer.readVarInt(); // ToDo: category + category = SoundCategories.byId(buffer.readVarInt()); location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4); volume = buffer.readFloat(); pitch = (buffer.readByte() * pitchCalc) / 100F; @@ -43,7 +44,7 @@ public class PacketSoundEffect implements ClientboundPacket { case VERSION_1_12_2: case VERSION_1_13_2: sound = buffer.readVarInt(); - category = buffer.readVarInt(); // ToDo: category + category = SoundCategories.byId(buffer.readVarInt()); location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4); volume = buffer.readFloat(); pitch = buffer.readFloat(); @@ -81,4 +82,8 @@ public class PacketSoundEffect implements ClientboundPacket { public float getVolume() { return volume; } + + public SoundCategories getCategory() { + return category; + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java index 412d030c7..fd12575c2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java @@ -13,6 +13,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; +import de.bixilon.minosoft.game.datatypes.SoundCategories; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; @@ -20,7 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler; import de.bixilon.minosoft.util.BitByte; public class PacketStopSound implements ClientboundPacket { - Integer soundId; + SoundCategories category; String soundIdentifier; @@ -30,17 +31,17 @@ public class PacketStopSound implements ClientboundPacket { case VERSION_1_9_4: case VERSION_1_10: case VERSION_1_11_2: - buffer.readString(); // category + category = SoundCategories.valueOf(buffer.readString().toUpperCase()); soundIdentifier = buffer.readString(); return true; case VERSION_1_12_2: soundIdentifier = buffer.readString(); - buffer.readString(); // category + category = SoundCategories.valueOf(buffer.readString().toUpperCase()); return true; case VERSION_1_13_2: byte flags = buffer.readByte(); if (BitByte.isBitMask(flags, 0x01)) { - soundId = buffer.readVarInt(); + category = SoundCategories.byId(buffer.readVarInt()); } if (BitByte.isBitMask(flags, 0x02)) { soundIdentifier = buffer.readString(); @@ -53,7 +54,7 @@ public class PacketStopSound implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("Received stop sound (soundId=%d, soundIdentifier=%s)", soundId, soundIdentifier)); + Log.protocol(String.format("Received stop sound (category=%d, soundIdentifier=%s)", category, soundIdentifier)); } @Override @@ -61,8 +62,8 @@ public class PacketStopSound implements ClientboundPacket { h.handle(this); } - public Integer getSoundId() { - return soundId; + public SoundCategories getSoundId() { + return category; } public String getSoundIdentifier() { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java index 0443efcc8..1f6690b13 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java @@ -17,7 +17,6 @@ import de.bixilon.minosoft.game.datatypes.Tag; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; -import de.bixilon.minosoft.protocol.protocol.InPacketBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketTags implements ClientboundPacket { @@ -38,7 +37,7 @@ public class PacketTags implements ClientboundPacket { return false; } - private Tag[] readTags(InPacketBuffer buffer) { + private Tag[] readTags(InByteBuffer buffer) { Tag[] ret = new Tag[buffer.readVarInt()]; switch (buffer.getVersion()) { case VERSION_1_13_2: