Search in sources :

Example 1 with ClientboundCustomSoundPacket

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

the class LevelMixin_API method playSound.

// ArchetypeVolumeCreator
// Audience
@Override
public void playSound(final Sound sound, final double x, final double y, final double z) {
    // Check if the event is registered (ie has an integer ID)
    final ResourceLocation soundKey = SpongeAdventure.asVanilla(sound.name());
    final Optional<SoundEvent> event = Registry.SOUND_EVENT.getOptional(soundKey);
    final SoundSource soundCategory = SpongeAdventure.asVanilla(sound.source());
    if (event.isPresent()) {
        this.shadow$playSound(null, x, y, z, event.get(), soundCategory, sound.volume(), sound.pitch());
    } else {
        // Otherwise send it as a custom sound
        final float volume = sound.volume();
        final double radius = volume > 1.0f ? (16.0f * volume) : 16.0d;
        final ClientboundCustomSoundPacket packet = new ClientboundCustomSoundPacket(soundKey, soundCategory, new net.minecraft.world.phys.Vec3(x, y, z), volume, sound.pitch());
        this.shadow$getServer().getPlayerList().broadcast(null, x, y, z, radius, this.shadow$dimension(), packet);
    }
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) SoundEvent(net.minecraft.sounds.SoundEvent) ResourceLocation(net.minecraft.resources.ResourceLocation) ClientboundCustomSoundPacket(net.minecraft.network.protocol.game.ClientboundCustomSoundPacket)

Aggregations

ClientboundCustomSoundPacket (net.minecraft.network.protocol.game.ClientboundCustomSoundPacket)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 SoundEvent (net.minecraft.sounds.SoundEvent)1 SoundSource (net.minecraft.sounds.SoundSource)1