Search in sources :

Example 21 with ClientComponent

use of org.terasology.engine.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();
        // Ensure that the camera isn't destroyed by the purgeWorld command.
        clientComponent.camera.setScope(EntityScope.GLOBAL);
        localPlayer.getClientEntity().saveComponent(clientComponent);
    }
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 22 with ClientComponent

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

the class CameraClientSystem method mountCamera.

private void mountCamera() {
    ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
    EntityRef targetEntityForCamera = GazeAuthoritySystem.getGazeEntityForCharacter(clientComponent.character);
    // TODO: why is the camera setup differently
    LocationComponent cameraLocation = clientComponent.camera.getComponent(LocationComponent.class);
    // if the camera already has a location,  use that as the relative position of the camera
    if (cameraLocation != null) {
        Location.attachChild(targetEntityForCamera, clientComponent.camera, cameraLocation.getLocalPosition(), new Quaternionf());
    } else {
        Location.attachChild(targetEntityForCamera, clientComponent.camera, new Vector3f(0, 0, 0), new Quaternionf());
    }
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 23 with ClientComponent

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

the class LocalPlayer method getViewPosition.

/**
 * position of camera if one is present else use {@link #getPosition(Vector3f)}
 *
 * @param dest will hold the result
 * @return dest
 */
public Vector3f getViewPosition(Vector3f dest) {
    ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
    LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
    return location.getWorldPosition(dest);
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 24 with ClientComponent

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

the class LocalPlayer method getViewRotation.

/**
 * orientation of camera if one is present else use {@link #getPosition(Vector3f)}
 *
 * @param dest will hold the result
 * @return dest
 */
public Quaternionf getViewRotation(Quaternionf dest) {
    ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
    LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
    return location.getWorldRotation(dest);
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 25 with ClientComponent

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

Aggregations

ClientComponent (org.terasology.engine.network.ClientComponent)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)30 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)27 Vector3f (org.joml.Vector3f)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)13 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)8 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)6 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Quaternionf (org.joml.Quaternionf)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)3 Client (org.terasology.engine.network.Client)3 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2