Search in sources :

Example 61 with ReceiveEvent

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

the class ServerPingSystem method onPingFromClient.

@ReceiveEvent(components = ClientComponent.class)
public void onPingFromClient(PingFromClientEvent event, EntityRef entity) {
    Instant end = Instant.now();
    endMap.put(entity, end);
    updatePing(entity);
}
Also used : Instant(java.time.Instant) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 62 with ReceiveEvent

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

the class AudioSystem method onPlaySound.

/**
 * Receives the sound played event and calls on the AudioManager to play it.
 *
 * @param playSoundEvent The sound event.
 * @param entity The entity that instigated the event.
 */
@ReceiveEvent
public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    if (location != null) {
        Vector3f pos = location.getWorldPosition(new Vector3f());
        if (pos.isFinite()) {
            audioManager.playSound(playSoundEvent.getSound(), pos, playSoundEvent.getVolume(), AudioManager.PRIORITY_NORMAL);
            return;
        } else {
            logger.warn("Can't play sound with non-finite position/rotation?! Entity: {}", entity);
        }
    }
    audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 63 with ReceiveEvent

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

the class AfkClientSystem method onDetectAfk.

@ReceiveEvent
public void onDetectAfk(AfkDetectEvent event, EntityRef entityRef) {
    EntityRef entity = localPlayer.getClientEntity();
    long afkTime = time.getGameTimeInMs() - lastActive;
    if (afkTime >= AFK_TIMEOUT) {
        AfkComponent component = entity.getComponent(AfkComponent.class);
        if (!component.afk) {
            component.afk = true;
            AfkRequest request = new AfkRequest(entity, true);
            entity.send(request);
        }
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 64 with ReceiveEvent

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

the class AfkClientSystem method onAfk.

@ReceiveEvent
public void onAfk(AfkEvent event, EntityRef entityRef) {
    if (requireConnection()) {
        return;
    }
    EntityRef entity = event.getTarget();
    AfkComponent component = entity.getComponent(AfkComponent.class);
    if (component != null) {
        component.afk = event.isAfk();
        entity.addOrSaveComponent(component);
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 65 with ReceiveEvent

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

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