mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
SoundCategories
This commit is contained in:
parent
853075c2d6
commit
28b8ddc874
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
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.game.datatypes.entities.Location;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
@ -26,7 +27,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket {
|
|||||||
String sound;
|
String sound;
|
||||||
float volume;
|
float volume;
|
||||||
float pitch;
|
float pitch;
|
||||||
int category;
|
SoundCategories category;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean read(InByteBuffer buffer) {
|
public boolean read(InByteBuffer buffer) {
|
||||||
@ -40,7 +41,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket {
|
|||||||
return true;
|
return true;
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
sound = buffer.readString();
|
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);
|
location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4);
|
||||||
volume = buffer.readFloat();
|
volume = buffer.readFloat();
|
||||||
pitch = (buffer.readByte() * pitchCalc) / 100F;
|
pitch = (buffer.readByte() * pitchCalc) / 100F;
|
||||||
@ -50,7 +51,7 @@ public class PacketNamedSoundEffect implements ClientboundPacket {
|
|||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
sound = buffer.readString();
|
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);
|
location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4);
|
||||||
volume = buffer.readFloat();
|
volume = buffer.readFloat();
|
||||||
pitch = buffer.readFloat();
|
pitch = buffer.readFloat();
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
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.game.datatypes.entities.Location;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
@ -23,8 +24,8 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
|||||||
public class PacketSoundEffect implements ClientboundPacket {
|
public class PacketSoundEffect implements ClientboundPacket {
|
||||||
static final float pitchCalc = 100.0F / 63.0F;
|
static final float pitchCalc = 100.0F / 63.0F;
|
||||||
Location location;
|
Location location;
|
||||||
|
SoundCategories category;
|
||||||
int sound;
|
int sound;
|
||||||
int category;
|
|
||||||
float volume;
|
float volume;
|
||||||
float pitch;
|
float pitch;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class PacketSoundEffect implements ClientboundPacket {
|
|||||||
switch (buffer.getVersion()) {
|
switch (buffer.getVersion()) {
|
||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
sound = buffer.readVarInt();
|
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);
|
location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4);
|
||||||
volume = buffer.readFloat();
|
volume = buffer.readFloat();
|
||||||
pitch = (buffer.readByte() * pitchCalc) / 100F;
|
pitch = (buffer.readByte() * pitchCalc) / 100F;
|
||||||
@ -43,7 +44,7 @@ public class PacketSoundEffect implements ClientboundPacket {
|
|||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
sound = buffer.readVarInt();
|
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);
|
location = new Location(buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4, buffer.readFixedPointNumberInteger() * 4);
|
||||||
volume = buffer.readFloat();
|
volume = buffer.readFloat();
|
||||||
pitch = buffer.readFloat();
|
pitch = buffer.readFloat();
|
||||||
@ -81,4 +82,8 @@ public class PacketSoundEffect implements ClientboundPacket {
|
|||||||
public float getVolume() {
|
public float getVolume() {
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SoundCategories getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
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.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||||
@ -20,7 +21,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
|||||||
import de.bixilon.minosoft.util.BitByte;
|
import de.bixilon.minosoft.util.BitByte;
|
||||||
|
|
||||||
public class PacketStopSound implements ClientboundPacket {
|
public class PacketStopSound implements ClientboundPacket {
|
||||||
Integer soundId;
|
SoundCategories category;
|
||||||
String soundIdentifier;
|
String soundIdentifier;
|
||||||
|
|
||||||
|
|
||||||
@ -30,17 +31,17 @@ public class PacketStopSound implements ClientboundPacket {
|
|||||||
case VERSION_1_9_4:
|
case VERSION_1_9_4:
|
||||||
case VERSION_1_10:
|
case VERSION_1_10:
|
||||||
case VERSION_1_11_2:
|
case VERSION_1_11_2:
|
||||||
buffer.readString(); // category
|
category = SoundCategories.valueOf(buffer.readString().toUpperCase());
|
||||||
soundIdentifier = buffer.readString();
|
soundIdentifier = buffer.readString();
|
||||||
return true;
|
return true;
|
||||||
case VERSION_1_12_2:
|
case VERSION_1_12_2:
|
||||||
soundIdentifier = buffer.readString();
|
soundIdentifier = buffer.readString();
|
||||||
buffer.readString(); // category
|
category = SoundCategories.valueOf(buffer.readString().toUpperCase());
|
||||||
return true;
|
return true;
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
byte flags = buffer.readByte();
|
byte flags = buffer.readByte();
|
||||||
if (BitByte.isBitMask(flags, 0x01)) {
|
if (BitByte.isBitMask(flags, 0x01)) {
|
||||||
soundId = buffer.readVarInt();
|
category = SoundCategories.byId(buffer.readVarInt());
|
||||||
}
|
}
|
||||||
if (BitByte.isBitMask(flags, 0x02)) {
|
if (BitByte.isBitMask(flags, 0x02)) {
|
||||||
soundIdentifier = buffer.readString();
|
soundIdentifier = buffer.readString();
|
||||||
@ -53,7 +54,7 @@ public class PacketStopSound implements ClientboundPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log() {
|
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
|
@Override
|
||||||
@ -61,8 +62,8 @@ public class PacketStopSound implements ClientboundPacket {
|
|||||||
h.handle(this);
|
h.handle(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getSoundId() {
|
public SoundCategories getSoundId() {
|
||||||
return soundId;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSoundIdentifier() {
|
public String getSoundIdentifier() {
|
||||||
|
@ -17,7 +17,6 @@ import de.bixilon.minosoft.game.datatypes.Tag;
|
|||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||||
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
|
||||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||||
|
|
||||||
public class PacketTags implements ClientboundPacket {
|
public class PacketTags implements ClientboundPacket {
|
||||||
@ -38,7 +37,7 @@ public class PacketTags implements ClientboundPacket {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tag[] readTags(InPacketBuffer buffer) {
|
private Tag[] readTags(InByteBuffer buffer) {
|
||||||
Tag[] ret = new Tag[buffer.readVarInt()];
|
Tag[] ret = new Tag[buffer.readVarInt()];
|
||||||
switch (buffer.getVersion()) {
|
switch (buffer.getVersion()) {
|
||||||
case VERSION_1_13_2:
|
case VERSION_1_13_2:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user