use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onUseItemButton.
@ReceiveEvent(components = { CharacterComponent.class })
public void onUseItemButton(UseItemButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
if (!event.isDown()) {
return;
}
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
if (!selectedItemEntity.exists()) {
return;
}
boolean requestIsValid;
if (networkSystem.getMode().isAuthority()) {
// Let the ActivationRequest handler trigger the OnItemUseEvent if this is a local client
requestIsValid = true;
} else {
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
entity.send(onItemUseEvent);
requestIsValid = !onItemUseEvent.isConsumed();
}
if (requestIsValid) {
localPlayer.activateOwnedEntityAsClient(selectedItemEntity);
entity.saveComponent(characterHeldItemComponent);
event.consume();
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerSystem method onRespawnRequest.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL, components = { ClientComponent.class })
public void onRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
Vector3f spawnPosition = entity.getComponent(LocationComponent.class).getWorldPosition();
if (worldProvider.isBlockRelevant(spawnPosition)) {
respawnPlayer(entity);
} else {
updateRelevanceEntity(entity, ViewDistance.LEGALLY_BLIND.getChunkDistance());
SpawningClientInfo info = new SpawningClientInfo(entity, spawnPosition);
clientsPreparingToRespawn.add(info);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onPlaced.
@ReceiveEvent(components = { OnItemActivateSelectionComponent.class })
public void onPlaced(ActivateEvent event, EntityRef itemEntity) {
if (event.getTargetLocation() == null) {
return;
}
EntityRef targetLocationEntity = event.getTarget();
this.blockSelectionComponentEntity = itemEntity;
BlockSelectionComponent blockSelectionComponent = itemEntity.getComponent(BlockSelectionComponent.class);
if (null == blockSelectionComponent.startPosition) {
// on the first item click, we start selecting blocks
targetLocationEntity.send(new SetBlockSelectionStartingPointEvent(itemEntity));
blockSelectionComponent.shouldRender = true;
} else {
// on the second item click, we will set the ending selection point and send an ApplyBlockSelectionEvent
targetLocationEntity.send(new SetBlockSelectionEndingPointEvent(itemEntity));
localPlayer.getCharacterEntity().send(new ApplyBlockSelectionEvent(itemEntity, blockSelectionComponent.currentSelection));
blockSelectionComponent.shouldRender = false;
blockSelectionComponent.currentSelection = null;
blockSelectionComponent.startPosition = null;
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onCamTargetChanged.
@ReceiveEvent(components = { LocationComponent.class })
public void onCamTargetChanged(CameraTargetChangedEvent event, EntityRef entity) {
// This method will update the block selection to whatever block is targeted in the players view
if (null == blockSelectionComponentEntity) {
return;
}
BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
if (blockSelectionComponent.startPosition == null) {
return;
}
EntityRef target = event.getNewTarget();
target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onJump.
@ReceiveEvent
public void onJump(JumpEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = null;
if (characterSounds.jumpSounds.size() > 0) {
sound = random.nextItem(characterSounds.jumpSounds);
} else if (characterSounds.footstepSounds.size() > 0) {
sound = random.nextItem(characterSounds.footstepSounds);
}
if (sound != null) {
entity.send(new PlaySoundEvent(entity, sound, characterSounds.jumpVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
Aggregations