3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Merge remote-tracking branch 'upstream/master' into feature/blocky

Dieser Commit ist enthalten in:
Joshua Castle 2022-12-20 22:24:26 -08:00
Commit b5eeaffb2f

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.util; package org.geysermc.geyser.util;
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound; import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
@ -65,10 +66,7 @@ public final class SoundUtils {
* @return a Bedrock sound * @return a Bedrock sound
*/ */
public static String translatePlaySound(String javaIdentifier) { public static String translatePlaySound(String javaIdentifier) {
// Drop the Minecraft namespace if applicable javaIdentifier = trim(javaIdentifier);
if (javaIdentifier.startsWith("minecraft:")) {
javaIdentifier = javaIdentifier.substring("minecraft:".length());
}
SoundMapping soundMapping = Registries.SOUNDS.get(javaIdentifier); SoundMapping soundMapping = Registries.SOUNDS.get(javaIdentifier);
if (soundMapping == null || soundMapping.getPlaysound() == null) { if (soundMapping == null || soundMapping.getPlaysound() == null) {
@ -79,6 +77,23 @@ public final class SoundUtils {
return soundMapping.getPlaysound(); return soundMapping.getPlaysound();
} }
private static String trim(String identifier) {
// Drop the Minecraft namespace if applicable
if (identifier.startsWith("minecraft:")) {
return identifier.substring("minecraft:".length());
}
return identifier;
}
private static void playSound(GeyserSession session, String bedrockName, Vector3f position, float volume, float pitch) {
PlaySoundPacket playSoundPacket = new PlaySoundPacket();
playSoundPacket.setSound(bedrockName);
playSoundPacket.setPosition(position);
playSoundPacket.setVolume(volume);
playSoundPacket.setPitch(pitch);
session.sendUpstreamPacket(playSoundPacket);
}
/** /**
* Translates and plays a Java Builtin Sound for a Bedrock client * Translates and plays a Java Builtin Sound for a Bedrock client
* *
@ -88,22 +103,24 @@ public final class SoundUtils {
* @param pitch the pitch * @param pitch the pitch
*/ */
public static void playSound(GeyserSession session, Sound javaSound, Vector3f position, float volume, float pitch) { public static void playSound(GeyserSession session, Sound javaSound, Vector3f position, float volume, float pitch) {
String packetSound = javaSound.getName(); String packetSound;
if (!(javaSound instanceof BuiltinSound)) {
// Identifier needs trimmed probably.
packetSound = trim(javaSound.getName());
} else {
packetSound = javaSound.getName();
}
SoundMapping soundMapping = Registries.SOUNDS.get(packetSound); SoundMapping soundMapping = Registries.SOUNDS.get(packetSound);
if (soundMapping == null) { if (soundMapping == null) {
session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + packetSound + " not found"); session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + packetSound + " not found; assuming custom.");
playSound(session, packetSound, position, volume, pitch);
return; return;
} }
if (soundMapping.getPlaysound() != null) { if (soundMapping.getPlaysound() != null) {
// We always prefer the PlaySound mapping because we can control volume and pitch // We always prefer the PlaySound mapping because we can control volume and pitch
PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSound(session, soundMapping.getPlaysound(), position, volume, pitch);
playSoundPacket.setSound(soundMapping.getPlaysound());
playSoundPacket.setPosition(position);
playSoundPacket.setVolume(volume);
playSoundPacket.setPitch(pitch);
session.sendUpstreamPacket(playSoundPacket);
return; return;
} }