Search in sources :

Example 1 with PlaySoundEvent

use of org.spongepowered.api.event.sound.PlaySoundEvent in project SpongeCommon by SpongePowered.

the class SpongeCommonEventFactory method callPlaySoundBroadcastEvent.

public static PlaySoundEvent.@Nullable Broadcast callPlaySoundBroadcastEvent(final CauseStackManager.StackFrame frame, final LevelBridge bridge, final BlockPos pos, final int effectID) {
    final Supplier<SoundType> soundType;
    final float volume;
    if (effectID == Constants.WorldEvents.PLAY_WITHER_SPAWN_EVENT) {
        soundType = SoundTypes.ENTITY_WITHER_SPAWN;
        volume = 1.0F;
    } else if (effectID == Constants.WorldEvents.PLAY_ENDERDRAGON_DEATH_EVENT) {
        soundType = SoundTypes.ENTITY_ENDER_DRAGON_DEATH;
        volume = 5.0F;
    } else if (effectID == Constants.WorldEvents.PLAY_BLOCK_END_PORTAL_SPAWN_EVENT) {
        soundType = SoundTypes.BLOCK_END_PORTAL_SPAWN;
        volume = 1.0F;
    } else {
        return null;
    }
    final ServerLocation location = ServerLocation.of((ServerWorld) bridge, pos.getX(), pos.getY(), pos.getZ());
    final PlaySoundEvent.Broadcast event = SpongeEventFactory.createPlaySoundEventBroadcast(frame.currentCause(), location, Sound.Source.HOSTILE, soundType.get(), 1.0F, volume);
    SpongeCommon.post(event);
    return event;
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) ServerLocation(org.spongepowered.api.world.server.ServerLocation) PlaySoundEvent(org.spongepowered.api.event.sound.PlaySoundEvent)

Aggregations

SoundType (org.spongepowered.api.effect.sound.SoundType)1 PlaySoundEvent (org.spongepowered.api.event.sound.PlaySoundEvent)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)1