Search in sources :

Example 6 with PlaySoundEvent

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

the class EventCopier method copyEvent.

public Event copyEvent(Event toBeCopied) {
    if (toBeCopied instanceof PlaySoundEvent) {
        return toBeCopied;
    } else if (toBeCopied instanceof BindButtonEvent) {
        BindButtonEvent originalEvent = (BindButtonEvent) toBeCopied;
        BindButtonEvent newEvent = (BindButtonEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), originalEvent.getState(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof KeyEvent) {
        KeyEvent originalEvent = (KeyEvent) toBeCopied;
        KeyEvent newEvent = createNewKeyEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof BindAxisEvent) {
        BindAxisEvent originalEvent = (BindAxisEvent) toBeCopied;
        BindAxisEvent newEvent = (BindAxisEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), (float) originalEvent.getValue(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseAxisEvent) {
        MouseAxisEvent originalEvent = (MouseAxisEvent) toBeCopied;
        MouseAxisEvent newEvent = createNewMouseAxisEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof CameraTargetChangedEvent) {
        CameraTargetChangedEvent originalEvent = (CameraTargetChangedEvent) toBeCopied;
        return new CameraTargetChangedEvent(originalEvent.getOldTarget(), originalEvent.getNewTarget());
    } else if (toBeCopied instanceof CharacterMoveInputEvent) {
        CharacterMoveInputEvent originalEvent = (CharacterMoveInputEvent) toBeCopied;
        return new CharacterMoveInputEvent(originalEvent.getSequenceNumber(), originalEvent.getPitch(), originalEvent.getYaw(), originalEvent.getMovementDirection(), originalEvent.isRunning(), originalEvent.isCrouching(), originalEvent.isJumping(), originalEvent.getDeltaMs());
    } else if (toBeCopied instanceof MouseButtonEvent) {
        MouseButtonEvent originalEvent = (MouseButtonEvent) toBeCopied;
        MouseButtonEvent newEvent = new MouseButtonEvent(originalEvent.getButton(), originalEvent.getState(), originalEvent.getDelta());
        newEvent.setMousePosition(originalEvent.getMousePosition());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseWheelEvent) {
        MouseWheelEvent originalEvent = (MouseWheelEvent) toBeCopied;
        MouseWheelEvent newEvent = new MouseWheelEvent(originalEvent.getMousePosition(), originalEvent.getWheelTurns(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof GetMaxSpeedEvent) {
        GetMaxSpeedEvent originalEvent = (GetMaxSpeedEvent) toBeCopied;
        GetMaxSpeedEvent newEvent = new GetMaxSpeedEvent(originalEvent.getBaseValue(), originalEvent.getMovementMode());
        newEvent.setModifiers(originalEvent.getModifiers());
        newEvent.setMultipliers(originalEvent.getMultipliers());
        newEvent.setPostModifiers(originalEvent.getPostModifiers());
        return newEvent;
    } else if (toBeCopied instanceof AttackEvent) {
        AttackEvent originalEvent = (AttackEvent) toBeCopied;
        AttackEvent newEvent = new AttackEvent(originalEvent.getInstigator(), originalEvent.getDirectCause());
        return newEvent;
    } else {
        return null;
    }
}
Also used : KeyEvent(org.terasology.engine.input.events.KeyEvent) CameraTargetChangedEvent(org.terasology.engine.input.cameraTarget.CameraTargetChangedEvent) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) MouseWheelEvent(org.terasology.engine.input.events.MouseWheelEvent) GetMaxSpeedEvent(org.terasology.engine.logic.characters.GetMaxSpeedEvent) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) MouseAxisEvent(org.terasology.engine.input.events.MouseAxisEvent) CharacterMoveInputEvent(org.terasology.engine.logic.characters.CharacterMoveInputEvent) MouseButtonEvent(org.terasology.engine.input.events.MouseButtonEvent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent)

Example 7 with PlaySoundEvent

use of org.terasology.engine.audio.events.PlaySoundEvent 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 8 with PlaySoundEvent

use of org.terasology.engine.audio.events.PlaySoundEvent 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 9 with PlaySoundEvent

use of org.terasology.engine.audio.events.PlaySoundEvent 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 10 with PlaySoundEvent

use of org.terasology.engine.audio.events.PlaySoundEvent 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)

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