mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-18 00:25:30 +01:00
Merge pull request #195 from kezz/fix-non-location-sound
Use EntitySoundEffectPacket in no location playSound method, fixes #194
This commit is contained in:
commit
36813c6858
@ -6,8 +6,12 @@ import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.sound.SoundStop;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.play.EntitySoundEffectPacket;
|
||||
import net.minestom.server.network.packet.server.play.NamedSoundEffectPacket;
|
||||
import net.minestom.server.network.packet.server.play.SoundEffectPacket;
|
||||
import net.minestom.server.network.packet.server.play.StopSoundPacket;
|
||||
@ -124,6 +128,28 @@ public class AdventurePacketConvertor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an entity sound packet from an Adventure sound.
|
||||
* @param sound the sound
|
||||
* @param entity the entity the sound is coming from
|
||||
* @return the packet
|
||||
*/
|
||||
public static ServerPacket createEntitySoundPacket(@NotNull Sound sound, @NotNull Entity entity) {
|
||||
SoundEvent soundEvent = Registries.getSoundEvent(sound.name());
|
||||
|
||||
if (soundEvent == null) {
|
||||
throw new IllegalArgumentException("Sound must be a valid sound event.");
|
||||
} else {
|
||||
EntitySoundEffectPacket packet = new EntitySoundEffectPacket();
|
||||
packet.soundId = soundEvent.getId();
|
||||
packet.soundSource = sound.source();
|
||||
packet.entityId = entity.getEntityId();
|
||||
packet.volume = sound.volume();
|
||||
packet.pitch = sound.pitch();
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sound stop packet from a sound stop.
|
||||
* @param stop the sound stop
|
||||
|
@ -6,6 +6,7 @@ import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.sound.SoundStop;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
@ -920,12 +921,12 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(net.kyori.adventure.sound.@NotNull Sound sound) {
|
||||
this.playSound(sound, this.position.getX(), this.position.getY(), this.position.getZ());
|
||||
public void playSound(@NotNull Sound sound) {
|
||||
playerConnection.sendPacket(AdventurePacketConvertor.createEntitySoundPacket(sound, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(net.kyori.adventure.sound.@NotNull Sound sound, double x, double y, double z) {
|
||||
public void playSound(@NotNull Sound sound, double x, double y, double z) {
|
||||
playerConnection.sendPacket(AdventurePacketConvertor.createSoundPacket(sound, x, y, z));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user