Search in sources :

Example 6 with StaticSound

use of org.terasology.engine.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.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 7 with StaticSound

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

the class CharacterSoundSystem method onEnterBlock.

@ReceiveEvent
public void onEnterBlock(OnEnterBlockEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    // only play this sound if the feet hit the water
    if (event.getCharacterRelativePosition().y == 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        boolean oldBlockIsLiquid = event.getOldBlock().isLiquid();
        boolean newBlockIsLiquid = event.getNewBlock().isLiquid();
        StaticSound sound = null;
        if (!oldBlockIsLiquid && newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.enterWaterSounds);
        } else if (oldBlockIsLiquid && !newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.leaveWaterSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.diveVolume));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 8 with StaticSound

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

the class CharacterSoundSystem method onPlayerDeath.

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

Example 9 with StaticSound

use of org.terasology.engine.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(), RoundingMode.FLOOR);
    // 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.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 10 with StaticSound

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

the class PlaySoundAction method onActivate.

/**
 * This method plays sound if it wasn't played by prediction system
 *
 * @param event contains the details for the active event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = PlaySoundActionComponent.class)
public void onActivate(ActivateEvent event, EntityRef entity) {
    if (event.getInstigator().equals(localPlayer.getCharacterEntity())) {
        // owner has heard sound from prediction
        return;
    }
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos;
        switch(playSound.relativeTo) {
            case Target:
                pos = event.getTargetLocation();
                break;
            default:
                pos = event.getInstigatorLocation();
                break;
        }
        if (pos == null) {
            pos = event.getOrigin();
        }
        audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

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