Search in sources :

Example 1 with PlaySoundEvent

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

Example 2 with PlaySoundEvent

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

Example 3 with PlaySoundEvent

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

the class CharacterSoundSystem method onLanded.

@ReceiveEvent
public void onLanded(VerticalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    Vector3f velocity = event.getVelocity();
    float soundVolumeModifier = (velocity.y * -1 - LANDING_VELOCITY_THRESHOLD) * LANDING_VOLUME_MODIFIER;
    if (soundVolumeModifier <= 0f) {
        return;
    }
    if (soundVolumeModifier > LANDING_VOLUME_MAX) {
        soundVolumeModifier = LANDING_VOLUME_MAX;
    }
    if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = null;
        if (characterSounds.landingSounds.size() > 0) {
            sound = random.nextItem(characterSounds.landingSounds);
        } else if (characterSounds.footstepSounds.size() > 0) {
            sound = random.nextItem(characterSounds.footstepSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.landingVolume * soundVolumeModifier));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with PlaySoundEvent

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

the class CharacterSoundSystem method onSwimStroke.

@ReceiveEvent
public void onSwimStroke(SwimStrokeEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.swimSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(characterSounds.swimSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.swimmingVolume));
        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 5 with PlaySoundEvent

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

the class BlockItemSystem method onPlaceBlock.

@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
    if (!event.getTarget().exists()) {
        event.consume();
        return;
    }
    BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
    BlockFamily blockFamily = blockItem.blockFamily;
    Side surfaceSide = Side.inDirection(event.getHitNormal());
    BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
    if (blockComponent == null) {
        // If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
        event.consume();
        return;
    }
    Vector3i targetBlock = new Vector3i(blockComponent.getPosition());
    Vector3i placementPos = new Vector3i(targetBlock);
    placementPos.add(surfaceSide.direction());
    Vector2f relativeAttachmentPosition = getRelativeAttachmentPosition(event);
    Block block = blockFamily.getBlockForPlacement(new BlockPlacementData(placementPos, surfaceSide, event.getDirection(), relativeAttachmentPosition));
    if (canPlaceBlock(block, targetBlock, placementPos)) {
        // TODO: Fix this for changes.
        if (networkSystem.getMode().isAuthority()) {
            PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
            worldProvider.getWorldEntity().send(placeBlocks);
            if (!placeBlocks.isConsumed()) {
                item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos), event.getInstigator()));
            } else {
                event.consume();
            }
        }
        recordBlockPlaced(event, blockFamily);
        event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
    } else {
        event.consume();
    }
}
Also used : Side(org.terasology.engine.math.Side) BlockComponent(org.terasology.engine.world.block.BlockComponent) BlockPlacementData(org.terasology.engine.world.block.family.BlockPlacementData) Vector2f(org.joml.Vector2f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) PlaceBlocks(org.terasology.engine.world.block.entity.placement.PlaceBlocks) 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