use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ClientCharacterPredictionSystem method onDestroy.
@ReceiveEvent(components = { CharacterComponent.class, CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onDestroy(final BeforeDeactivateComponent event, final EntityRef entity) {
CharacterComponent character = entity.getComponent(CharacterComponent.class);
ClientComponent controller = character.controller.getComponent(ClientComponent.class);
if (controller != null && controller.local) {
predictedState = null;
authoritiveState = null;
inputs.clear();
}
physics.removeCharacterCollider(entity);
playerStates.remove(entity);
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class VisualCharacterSystem method onCreateDefaultVisualCharacter.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onCreateDefaultVisualCharacter(CreateVisualCharacterEvent event, EntityRef characterEntity) {
Prefab prefab = assetManager.getAsset("engine:defaultVisualCharacter", Prefab.class).get();
EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
entityBuilder.addPrefab(prefab);
event.consume();
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerSystem method setSpawnLocationOnRespawnRequest.
@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
EntityRef character = clientComponent.character;
EntityRef clientInfo = clientComponent.clientInfo;
Vector3fc spawnPosition;
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
} else {
spawnPosition = worldGenerator.getSpawnPosition(entity);
}
LocationComponent loc = character.getComponent(LocationComponent.class);
loc.setWorldPosition(spawnPosition);
// reset rotation
loc.setLocalRotation(new Quaternionf());
character.saveComponent(loc);
}
use of org.terasology.engine.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 == null) {
return;
}
EntityRef target = event.getNewTarget();
LocationComponent locationComponent = target.getComponent(LocationComponent.class);
if (locationComponent == null) {
return;
}
Vector3f targetLocation = locationComponent.getWorldPosition(new Vector3f());
if (blockSelectionComponent.isMovable) {
Vector3i pos = new Vector3i(targetLocation, RoundingMode.FLOOR);
Vector3i size = blockSelectionComponent.currentSelection.getSize(new Vector3i());
blockSelectionComponent.currentSelection.set(pos, pos).expand(size.x() / 2, 0, size.z() / 2);
blockSelectionComponentEntity.saveComponent(blockSelectionComponent);
return;
}
if (blockSelectionComponent.startPosition == null) {
return;
}
target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerBlockSelectionByItemSystem method onLeftMouseButtonDown.
/**
* This marks the end of the camera position binding with the region position.
* @param event LeftMouseButtonDownEvent
* @param entity Entity sending the event
*/
@ReceiveEvent
public void onLeftMouseButtonDown(LeftMouseDownButtonEvent event, EntityRef entity) {
if (this.blockSelectionComponentEntity != null && this.blockSelectionComponentEntity != EntityRef.NULL) {
BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
if (blockSelectionComponent != null && blockSelectionComponent.isMovable) {
blockSelectionComponentEntity.send(new MovableSelectionEndEvent(blockSelectionComponent.currentSelection));
blockSelectionComponentEntity.destroy();
}
}
}
Aggregations