Search in sources :

Example 6 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onStartSelectionAtEntity.

@ReceiveEvent
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity, LocationComponent locationComponent) {
    if (null == locationComponent) {
        // entity isn't LocationComponent, which shouldn't ever be the case
        return;
    }
    BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
    if (null == blockSelectionComponent) {
        // event did not provide a BlockSelection component to modify
        return;
    }
    Vector3i startPosition = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR);
    blockSelectionComponent.startPosition = startPosition;
    blockSelectionComponent.currentSelection = new BlockRegion(startPosition);
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 7 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent 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 8 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent 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 9 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent 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 10 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent 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)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2