Search in sources :

Example 16 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class CameraClientSystem method ensureCameraEntityCreated.

private void ensureCameraEntityCreated() {
    if (!localPlayer.getCameraEntity().exists()) {
        ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
        // create the camera from the prefab
        EntityBuilder builder = entityManager.newBuilder("engine:camera");
        builder.setPersistent(false);
        clientComponent.camera = builder.build();
        localPlayer.getClientEntity().saveComponent(clientComponent);
    }
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) ClientComponent(org.terasology.network.ClientComponent)

Example 17 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class LocalPlayer method getViewPosition.

public Vector3f getViewPosition(Vector3f out) {
    ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
    if (clientComponent == null) {
        return out;
    }
    LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
    if (location == null) {
        return getPosition();
    }
    return location.getWorldPosition(out);
}
Also used : ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 18 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class LocalPlayer method setClientEntity.

// TODO: As per Immortius answer in Pull Request #1088,
// TODO: there appears to be situations in which LocalPlayer is instantiated
// TODO: but the client entity is -not- set, i.e. in the headless server.
// TODO: However, it's unclear why the headless server needs a LocalPlayer,
// TODO: instance. If that can be avoided the code in the following method
// TODO: might be more rightfully placed in the LocalPlayer constructor.
public void setClientEntity(EntityRef entity) {
    this.clientEntity = entity;
    ClientComponent clientComp = entity.getComponent(ClientComponent.class);
    if (clientComp != null) {
        clientComp.local = true;
        entity.saveComponent(clientComp);
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent)

Example 19 with ClientComponent

use of org.terasology.network.ClientComponent 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 20 with ClientComponent

use of org.terasology.network.ClientComponent 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

ClientComponent (org.terasology.network.ClientComponent)64 Command (org.terasology.logic.console.commandSystem.annotations.Command)37 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 LocationComponent (org.terasology.logic.location.LocationComponent)13 Vector3f (org.terasology.math.geom.Vector3f)13 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)5 Prefab (org.terasology.entitySystem.prefab.Prefab)5 LocalPlayer (org.terasology.logic.players.LocalPlayer)4 Quat4f (org.terasology.math.geom.Quat4f)4 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Client (org.terasology.network.Client)3 ResourceUrn (org.terasology.assets.ResourceUrn)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)2