use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSystem method beforeDestroy.
@ReceiveEvent
public void beforeDestroy(BeforeDestroyEvent event, EntityRef character, CharacterComponent characterComponent, AliveCharacterComponent aliveCharacterComponent) {
if (character.hasComponent(PlayerCharacterComponent.class)) {
// Consume the BeforeDestroyEvent so that the DoDestroy event is never sent for player entities
event.consume();
// PlayerDeathEvent only sent to the client for the player entity.
PlayerDeathEvent playerDeathEvent = new PlayerDeathEvent();
// Store the details of the death in the event for display on the death screen
playerDeathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
playerDeathEvent.instigatorName = getInstigatorName(event.getInstigator());
character.send(playerDeathEvent);
}
// DeathEvent sent to client for any character entity.
DeathEvent deathEvent = new DeathEvent();
deathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
deathEvent.instigatorName = getInstigatorName(event.getInstigator());
characterComponent.controller.send(deathEvent);
character.removeComponent(AliveCharacterComponent.class);
// TODO: Don't just destroy, ragdoll or create particle effect or something (possible allow another system to handle)
// entity.removeComponent(CharacterComponent.class);
// entity.removeComponent(CharacterMovementComponent.class);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class GazeAuthoritySystem method ensureGazeContainerEntitiesCreated.
@ReceiveEvent
public void ensureGazeContainerEntitiesCreated(OnActivatedComponent event, EntityRef entityRef, GazeMountPointComponent gazeMountPointComponent, LocationComponent locationComponent) {
if (!gazeMountPointComponent.gazeEntity.exists()) {
gazeMountPointComponent.gazeEntity = createGazeEntity();
entityRef.saveComponent(gazeMountPointComponent);
}
gazeMountPointComponent.translate.y = config.getPlayer().getEyeHeight();
Location.attachChild(entityRef, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY));
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ServerCharacterPredictionSystem method onPlayerInput.
@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onPlayerInput(CharacterMoveInputEvent input, EntityRef entity) {
CharacterCollider characterCollider = physics.getCharacterCollider(entity);
if (characterCollider.isPending()) {
logger.debug("Skipping input, collision not yet established");
return;
}
CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
CharacterStateEvent lastState = stateBuffer.getLast();
float delta = input.getDelta() + lastState.getTime() - (time.getGameTimeInMs() + MAX_INPUT_OVERFLOW);
if (delta < 0) {
CharacterStateEvent newState = stepState(input, lastState, entity);
stateBuffer.add(newState);
characterMovementSystemUtility.setToState(entity, newState);
lastInputEvent.put(entity, input);
} else {
logger.warn("Received too much input from {}, dropping input. Delta difference: {}", entity, delta);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ServerCharacterPredictionSystem method onTeleport.
@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onTeleport(CharacterTeleportEvent event, EntityRef entity) {
CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
CharacterStateEvent lastState = stateBuffer.getLast();
CharacterStateEvent newState = new CharacterStateEvent(lastState);
newState.setPosition(new Vector3f(event.getTargetPosition()));
newState.setTime(time.getGameTimeInMs());
stateBuffer.add(newState);
characterMovementSystemUtility.setToState(entity, newState);
}
use of org.terasology.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();
}
Aggregations