Search in sources :

Example 11 with PlaySoundEvent

use of org.terasology.engine.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDestroyed.

private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
    entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
    BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
    // TODO: Configurable via block definition
    if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
        // dust particle effect
        if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
            // TODO: particle system stuff should be split out better - this is effectively a stealth dependency on
            // 'CoreAssets' from the engine
            EntityBuilder dustBuilder = entityManager.newBuilder("CoreAssets:dustEffect");
            if (dustBuilder.hasComponent(LocationComponent.class)) {
                dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition(new Vector3f()));
                dustBuilder.build();
            }
        }
        // sound to play for destroyed block
        BlockSounds sounds = block.getSounds();
        if (!sounds.getDestroySounds().isEmpty()) {
            StaticSound sound = random.nextItem(sounds.getDestroySounds());
            entity.send(new PlaySoundEvent(sound, 0.6f));
        }
    }
}
Also used : BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BlockDamageModifierComponent(org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Aggregations

PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)11 StaticSound (org.terasology.engine.audio.StaticSound)9 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)9 Vector3f (org.joml.Vector3f)2 Vector3i (org.joml.Vector3i)2 Block (org.terasology.engine.world.block.Block)2 Vector2f (org.joml.Vector2f)1 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 BindAxisEvent (org.terasology.engine.input.BindAxisEvent)1 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)1 CameraTargetChangedEvent (org.terasology.engine.input.cameraTarget.CameraTargetChangedEvent)1 KeyEvent (org.terasology.engine.input.events.KeyEvent)1 MouseAxisEvent (org.terasology.engine.input.events.MouseAxisEvent)1 MouseButtonEvent (org.terasology.engine.input.events.MouseButtonEvent)1 MouseWheelEvent (org.terasology.engine.input.events.MouseWheelEvent)1 CharacterMoveInputEvent (org.terasology.engine.logic.characters.CharacterMoveInputEvent)1 GetMaxSpeedEvent (org.terasology.engine.logic.characters.GetMaxSpeedEvent)1 AttackEvent (org.terasology.engine.logic.characters.events.AttackEvent)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 Side (org.terasology.engine.math.Side)1