Search in sources :

Example 11 with StaticSound

use of org.terasology.engine.audio.StaticSound 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

StaticSound (org.terasology.engine.audio.StaticSound)11 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 Vector3f (org.joml.Vector3f)4 Vector3i (org.joml.Vector3i)1 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 Block (org.terasology.engine.world.block.Block)1 BlockDamageModifierComponent (org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent)1 BlockSounds (org.terasology.engine.world.block.sounds.BlockSounds)1