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