Search in sources :

Example 1 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onJump.

@ReceiveEvent
public void onJump(JumpEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = null;
        if (characterSounds.jumpSounds.size() > 0) {
            sound = random.nextItem(characterSounds.jumpSounds);
        } else if (characterSounds.footstepSounds.size() > 0) {
            sound = random.nextItem(characterSounds.footstepSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.jumpVolume));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onDeath.

@ReceiveEvent
public void onDeath(DoDestroyEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.deathSounds.size() > 0) {
        StaticSound sound = random.nextItem(characterSounds.deathSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.deathVolume));
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 3 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onFootstep.

@ReceiveEvent
public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent locationComponent, CharacterSoundComponent characterSounds) {
    List<StaticSound> footstepSounds = characterSounds.footstepSounds;
    // Check if the block the character is standing on has footstep sounds
    Vector3i blockPos = new Vector3i(locationComponent.getLocalPosition());
    // The block *below* the character's feet is interesting to us
    blockPos.y--;
    Block block = worldProvider.getBlock(blockPos);
    if (block != null) {
        if (block.getSounds() == null) {
            logger.error("Block '{}' has no sounds", block.getURI());
        } else if (!block.getSounds().getStepSounds().isEmpty()) {
            footstepSounds = block.getSounds().getStepSounds();
        }
    }
    if (footstepSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(footstepSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.footstepVolume));
        characterSounds.lastSoundTime = time.getGameTimeInMs();
        entity.saveComponent(characterSounds);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onRespawn.

@ReceiveEvent
public void onRespawn(OnPlayerRespawnedEvent event, EntityRef character, CharacterSoundComponent characterSounds) {
    if (characterSounds.respawnSounds.size() > 0) {
        StaticSound sound = random.nextItem(characterSounds.respawnSounds);
        character.send(new PlaySoundEvent(character, sound, characterSounds.respawnVolume));
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 5 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class ExplosionAuthoritySystem method onActivateFuseOnBlock.

@ReceiveEvent(components = ItemComponent.class)
public void onActivateFuseOnBlock(ActivateEvent event, EntityRef entityRef, TimedExplosionComponent timedExplosionComponent) {
    if (event.getTarget().hasComponent(BlockComponent.class) && event.getTarget().hasComponent(ExplosionActionComponent.class) && !event.getTarget().hasComponent(TimedExplosionComponent.class)) {
        Optional<StaticSound> fuseBurningSound = Assets.getSound("core:FuseBurning");
        if (fuseBurningSound.isPresent()) {
            event.getTarget().send(new PlaySoundEvent(fuseBurningSound.get(), 1f));
        }
        // add a timed explosion to the block so that it stays active
        event.getTarget().addComponent(new TimedExplosionComponent());
        delayManager.addDelayedAction(event.getTarget(), DELAYED_EXPLOSION_ACTION_ID, timedExplosionComponent.fuseTimeMs);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

StaticSound (org.terasology.audio.StaticSound)15 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)13 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)13 Vector3f (org.terasology.math.geom.Vector3f)4 BlockSounds (org.terasology.world.block.sounds.BlockSounds)2 PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)1 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Block (org.terasology.world.block.Block)1 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1