Search in sources :

Example 61 with ReceiveEvent

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

Example 62 with ReceiveEvent

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

the class HierarchicalAISystem method onBump.

// TODO change eating thingy to use this
@ReceiveEvent(components = { HierarchicalAIComponent.class })
public void onBump(HorizontalCollisionEvent event, EntityRef entity) {
    CharacterMovementComponent moveComp = entity.getComponent(CharacterMovementComponent.class);
    if (moveComp != null && moveComp.grounded) {
        moveComp.jump = true;
        entity.saveComponent(moveComp);
    }
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 63 with ReceiveEvent

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

the class AudioSystem method onPlaySound.

/**
 * Receives an event send when a sound should be played for the entity owner as well.
 * Calls on the AudioManager to play it.
 *
 * @param playSoundEvent The sound event.
 * @param entity The entity that instigated the event.
 */
@ReceiveEvent
public void onPlaySound(PlaySoundForOwnerEvent playSoundEvent, EntityRef entity) {
    ClientComponent clientComponent = networkSystem.getOwnerEntity(entity).getComponent(ClientComponent.class);
    if (clientComponent != null && !clientComponent.local) {
        return;
    }
    audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume(), AudioManager.PRIORITY_HIGH);
}
Also used : ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 64 with ReceiveEvent

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

the class CharacterSoundSystem method onPlayerDeath.

@ReceiveEvent
public void onPlayerDeath(PlayerDeathEvent event, EntityRef character) {
    CharacterSoundComponent characterSounds = character.getComponent(CharacterSoundComponent.class);
    if (characterSounds.deathSounds.size() > 0) {
        StaticSound sound = random.nextItem(characterSounds.deathSounds);
        character.send(new PlaySoundEvent(character, sound, characterSounds.deathVolume));
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 65 with ReceiveEvent

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