Search in sources :

Example 56 with ReceiveEvent

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

the class EntityAwareWorldProvider method onDeactivateBlock.

@ReceiveEvent(components = { BlockComponent.class })
public void onDeactivateBlock(BeforeDeactivateComponent event, EntityRef entity) {
    BlockComponent block = entity.getComponent(BlockComponent.class);
    Vector3i pos = new Vector3i(block.getPosition());
    if (blockEntityLookup.get(pos) == entity) {
        blockEntityLookup.remove(pos);
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) Vector3i(org.terasology.math.geom.Vector3i) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 57 with ReceiveEvent

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

Example 58 with ReceiveEvent

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

the class SectorSimulationSystem method chunkLoad.

/**
 * Handles the OnChunkLoaded event for sector entities.
 *
 * Forwards the event to the appropriate sector-scope entities, if they are watching that chunk, and sends a
 * {@link SectorEntityLoad} event if this is the first watched chunk to be loaded for that entity.
 *
 * @param event the event sent when any chunk is loaded
 * @param worldEntity ignored
 */
@ReceiveEvent(components = WorldComponent.class)
public void chunkLoad(OnChunkLoaded event, EntityRef worldEntity) {
    for (EntityRef entity : entityManager.getEntitiesWith(SectorSimulationComponent.class)) {
        if (SectorUtil.getWatchedChunks(entity).contains(event.getChunkPos())) {
            entity.send(new OnChunkLoaded(event.getChunkPos()));
            if (SectorUtil.onlyWatchedChunk(entity, event.getChunkPos(), chunkProvider)) {
                entity.send(new SectorEntityLoad());
            }
            sendLoadedSectorUpdateEvent(entity, simulationDelta(entity));
        }
    }
}
Also used : OnChunkLoaded(org.terasology.world.chunks.event.OnChunkLoaded) BaseEntityRef(org.terasology.entitySystem.entity.internal.BaseEntityRef) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 59 with ReceiveEvent

use of org.terasology.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 = null;
        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.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 60 with ReceiveEvent

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

the class PlaySoundAction method onActivationPredicted.

/**
 * This method plays sound in prediction for preventing not playing song because of server lags
 * @param event contains the details for the predicted event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = { PlaySoundActionComponent.class })
public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos = null;
        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.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2