Search in sources :

Example 1 with ClientboundSoundEntityPacket

use of net.minecraft.network.protocol.game.ClientboundSoundEntityPacket in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin_API method playSound.

@Override
public void playSound(@NonNull final Sound sound, final Sound.@NotNull Emitter emitter) {
    Objects.requireNonNull(sound, "sound");
    Objects.requireNonNull(emitter, "emitter");
    if (this.impl$isFake) {
        return;
    }
    final Optional<SoundEvent> event = Registry.SOUND_EVENT.getOptional(SpongeAdventure.asVanilla(Objects.requireNonNull(sound, "sound").name()));
    if (event.isPresent()) {
        // The SoundEntityPacket does not support custom sounds
        final Entity tracked;
        if (emitter == Sound.Emitter.self()) {
            tracked = (Entity) (Object) this;
        } else if (emitter instanceof org.spongepowered.api.entity.Entity) {
            tracked = (Entity) emitter;
        } else {
            throw new IllegalArgumentException("Specified emitter '" + emitter + "' is not a Sponge Entity or Emitter.self(), was of type '" + emitter.getClass() + "'");
        }
        this.connection.send(new ClientboundSoundEntityPacket(event.get(), SpongeAdventure.asVanilla(sound.source()), tracked, sound.volume(), sound.pitch()));
    }
}
Also used : SoundEvent(net.minecraft.sounds.SoundEvent) Entity(net.minecraft.world.entity.Entity) ClientboundSoundEntityPacket(net.minecraft.network.protocol.game.ClientboundSoundEntityPacket) Identity(net.kyori.adventure.identity.Identity)

Aggregations

Identity (net.kyori.adventure.identity.Identity)1 ClientboundSoundEntityPacket (net.minecraft.network.protocol.game.ClientboundSoundEntityPacket)1 SoundEvent (net.minecraft.sounds.SoundEvent)1 Entity (net.minecraft.world.entity.Entity)1