Search in sources :

Example 1 with PlaySoundEvent

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

Example 2 with PlaySoundEvent

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

Example 3 with PlaySoundEvent

use of org.terasology.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());
    // 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 PlaySoundEvent

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

Example 5 with PlaySoundEvent

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

the class DoorSystem method placeDoor.

@ReceiveEvent(components = { DoorComponent.class, ItemComponent.class })
public void placeDoor(ActivateEvent event, EntityRef entity) {
    DoorComponent door = entity.getComponent(DoorComponent.class);
    BlockComponent targetBlockComp = event.getTarget().getComponent(BlockComponent.class);
    if (targetBlockComp == null) {
        event.consume();
        return;
    }
    Vector3f horizDir = new Vector3f(event.getDirection());
    horizDir.y = 0;
    Side facingDir = Side.inDirection(horizDir);
    if (!facingDir.isHorizontal()) {
        event.consume();
        return;
    }
    Vector3f offset = new Vector3f(event.getHitPosition());
    offset.sub(targetBlockComp.getPosition().toVector3f());
    Side offsetDir = Side.inDirection(offset);
    Vector3i primePos = new Vector3i(targetBlockComp.getPosition());
    primePos.add(offsetDir.getVector3i());
    Block primeBlock = worldProvider.getBlock(primePos);
    if (!primeBlock.isReplacementAllowed()) {
        event.consume();
        return;
    }
    Block belowBlock = worldProvider.getBlock(primePos.x, primePos.y - 1, primePos.z);
    Block aboveBlock = worldProvider.getBlock(primePos.x, primePos.y + 1, primePos.z);
    // Determine top and bottom blocks
    Vector3i bottomBlockPos;
    Vector3i topBlockPos;
    if (belowBlock.isReplacementAllowed()) {
        bottomBlockPos = new Vector3i(primePos.x, primePos.y - 1, primePos.z);
        topBlockPos = primePos;
    } else if (aboveBlock.isReplacementAllowed()) {
        bottomBlockPos = primePos;
        topBlockPos = new Vector3i(primePos.x, primePos.y + 1, primePos.z);
    } else {
        event.consume();
        return;
    }
    Side attachSide = determineAttachSide(facingDir, offsetDir, bottomBlockPos, topBlockPos);
    if (attachSide == null) {
        event.consume();
        return;
    }
    Side closedSide = facingDir.reverse();
    if (closedSide == attachSide || closedSide.reverse() == attachSide) {
        closedSide = attachSide.yawClockwise(1);
    }
    Block newBottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
    Block newTopBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
    Map<Vector3i, Block> blockMap = new HashMap<>();
    blockMap.put(bottomBlockPos, newBottomBlock);
    blockMap.put(topBlockPos, newTopBlock);
    PlaceBlocks blockEvent = new PlaceBlocks(blockMap, event.getInstigator());
    worldProvider.getWorldEntity().send(blockEvent);
    if (!blockEvent.isConsumed()) {
        EntityRef newDoor = entityManager.create(door.doorRegionPrefab);
        entity.removeComponent(MeshComponent.class);
        newDoor.addComponent(new BlockRegionComponent(Region3i.createBounded(bottomBlockPos, topBlockPos)));
        Vector3f doorCenter = bottomBlockPos.toVector3f();
        doorCenter.y += 0.5f;
        newDoor.addComponent(new LocationComponent(doorCenter));
        DoorComponent newDoorComp = newDoor.getComponent(DoorComponent.class);
        newDoorComp.closedSide = closedSide;
        newDoorComp.openSide = attachSide.reverse();
        newDoorComp.isOpen = false;
        newDoor.saveComponent(newDoorComp);
        newDoor.send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
        logger.info("Closed Side: {}", newDoorComp.closedSide);
        logger.info("Open Side: {}", newDoorComp.openSide);
        newDoor.send(new DoorPlacedEvent(event.getInstigator()));
    }
}
Also used : HashMap(java.util.HashMap) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) LocationComponent(org.terasology.logic.location.LocationComponent) BlockComponent(org.terasology.world.block.BlockComponent) Side(org.terasology.math.Side) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) PlaceBlocks(org.terasology.world.block.entity.placement.PlaceBlocks) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)18 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Side (org.terasology.math.Side)4 Vector3f (org.terasology.math.geom.Vector3f)4 Vector3i (org.terasology.math.geom.Vector3i)4 LocationComponent (org.terasology.logic.location.LocationComponent)3 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 BlockComponent (org.terasology.world.block.BlockComponent)2 PlaceBlocks (org.terasology.world.block.entity.placement.PlaceBlocks)2 BlockSounds (org.terasology.world.block.sounds.BlockSounds)2 HashMap (java.util.HashMap)1 PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)1 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)1 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1