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