Search in sources :

Example 1 with AliveCharacterComponent

use of org.terasology.logic.characters.AliveCharacterComponent 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 = clientEntity.getComponent(LocationComponent.class);
    PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
    Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
    location.setWorldPosition(spawnPosition);
    clientEntity.saveComponent(location);
    playerCharacter.addComponent(new AliveCharacterComponent());
    playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
    logger.debug("Re-spawing player at: {}", spawnPosition);
    Client clientListener = networkSystem.getOwner(clientEntity);
    Vector3i distance = clientListener.getViewDistance().getChunkDistance();
    updateRelevanceEntity(clientEntity, distance);
    playerCharacter.send(new OnPlayerRespawnedEvent());
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) OnPlayerRespawnedEvent(org.terasology.logic.players.event.OnPlayerRespawnedEvent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent)

Example 2 with AliveCharacterComponent

use of org.terasology.logic.characters.AliveCharacterComponent in project Terasology by MovingBlocks.

the class PlayerSystem method restoreCharacter.

private void restoreCharacter(EntityRef entity, EntityRef character) {
    Client clientListener = networkSystem.getOwner(entity);
    updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());
    ClientComponent client = entity.getComponent(ClientComponent.class);
    client.character = character;
    entity.saveComponent(client);
    CharacterComponent characterComp = character.getComponent(CharacterComponent.class);
    if (characterComp != null) {
        characterComp.controller = entity;
        character.saveComponent(characterComp);
        character.setOwner(entity);
        if (!character.hasComponent(AliveCharacterComponent.class)) {
            character.addComponent(new AliveCharacterComponent());
        }
        Location.attachChild(character, entity, new Vector3f(), new Quat4f(0, 0, 0, 1));
    } else {
        character.destroy();
        spawnPlayer(entity);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) CharacterComponent(org.terasology.logic.characters.CharacterComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

AliveCharacterComponent (org.terasology.logic.characters.AliveCharacterComponent)2 Vector3f (org.terasology.math.geom.Vector3f)2 Client (org.terasology.network.Client)2 ClientComponent (org.terasology.network.ClientComponent)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 CharacterComponent (org.terasology.logic.characters.CharacterComponent)1 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 OnPlayerRespawnedEvent (org.terasology.logic.players.event.OnPlayerRespawnedEvent)1 Quat4f (org.terasology.math.geom.Quat4f)1 Vector3i (org.terasology.math.geom.Vector3i)1