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);
}
}
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);
}
}
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);
}
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));
}
}
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);
}
}
Aggregations