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()));
}
}
Aggregations