Search in sources :

Example 1 with OnPlayerRespawnedEvent

use of org.terasology.engine.logic.players.event.OnPlayerRespawnedEvent in project Terasology by MovingBlocks.

the class PlayerSystem method respawnPlayer.

private void respawnPlayer(EntityRef clientEntity) {
    ClientComponent client = clientEntity.getComponent(ClientComponent.class);
    EntityRef playerCharacter = client.character;
    LocationComponent location = playerCharacter.getComponent(LocationComponent.class);
    PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
    Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
    playerCharacter.addComponent(new AliveCharacterComponent());
    playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
    logger.debug("Re-spawing player at: {}", spawnPosition);
    Client clientListener = networkSystem.getOwner(clientEntity);
    Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
    updateRelevanceEntity(clientEntity, distance);
    playerCharacter.send(new OnPlayerRespawnedEvent());
}
Also used : CharacterTeleportEvent(org.terasology.engine.logic.characters.CharacterTeleportEvent) Vector3ic(org.joml.Vector3ic) Vector3f(org.joml.Vector3f) Client(org.terasology.engine.network.Client) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) OnPlayerRespawnedEvent(org.terasology.engine.logic.players.event.OnPlayerRespawnedEvent) AliveCharacterComponent(org.terasology.engine.logic.characters.AliveCharacterComponent)

Aggregations

Vector3f (org.joml.Vector3f)1 Vector3ic (org.joml.Vector3ic)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)1 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 OnPlayerRespawnedEvent (org.terasology.engine.logic.players.event.OnPlayerRespawnedEvent)1 Client (org.terasology.engine.network.Client)1 ClientComponent (org.terasology.engine.network.ClientComponent)1