Search in sources :

Example 1 with ReceiveEvent

use of org.terasology.engine.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;
        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)

Example 2 with ReceiveEvent

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

the class SpawnPrefabAction method onActivate.

/**
 * @param event contains the details for the active event, used here for spawn location
 * @param entity is entity which will be spawned
 */
@ReceiveEvent(components = SpawnPrefabActionComponent.class)
public void onActivate(ActivateEvent event, EntityRef entity) {
    SpawnPrefabActionComponent spawnInfo = entity.getComponent(SpawnPrefabActionComponent.class);
    if (spawnInfo.prefab != null) {
        Vector3f spawnLoc = new Vector3f();
        switch(spawnInfo.spawnLocationRelativeTo) {
            case Instigator:
                spawnLoc.set(event.getInstigatorLocation());
                break;
            case Target:
                Vector3f pos = event.getTargetLocation();
                if (pos != null) {
                    spawnLoc.set(pos);
                }
                break;
            default:
                break;
        }
        entityManager.create(spawnInfo.prefab, spawnLoc);
    }
}
Also used : Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with ReceiveEvent

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

the class EntityAwareWorldProvider method onBlockRegionDeactivated.

@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionDeactivated(BeforeDeactivateComponent event, EntityRef entity) {
    BlockRegion oldRegion = blockRegions.get(entity);
    for (Vector3ic pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    blockRegions.remove(entity);
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with ReceiveEvent

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

the class EntityAwareWorldProvider method onBlockRegionActivated.

@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionActivated(OnActivatedComponent event, EntityRef entity) {
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3ic pos : regionComp.region) {
        blockRegionLookup.put(new Vector3i(pos), entity);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3i(org.joml.Vector3i) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 5 with ReceiveEvent

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

the class EntityAwareWorldProvider method onActivateBlock.

@ReceiveEvent(components = BlockComponent.class)
public void onActivateBlock(OnActivatedComponent event, EntityRef entity) {
    BlockComponent block = entity.getComponent(BlockComponent.class);
    EntityRef oldEntity = blockEntityLookup.put(block.getPosition(new Vector3i()), entity);
    // If this is a client, then an existing block entity may exist. Destroy it.
    if (oldEntity != null && !Objects.equal(oldEntity, entity)) {
        oldEntity.destroy();
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) 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