Search in sources :

Example 11 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method playerHeight.

@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
    try {
        ClientComponent clientComp = client.getComponent(ClientComponent.class);
        CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
        if (move != null) {
            float prevHeight = move.height;
            move.height = amount;
            clientComp.character.saveComponent(move);
            LocationComponent loc = client.getComponent(LocationComponent.class);
            Vector3f currentPosition = loc.getWorldPosition();
            clientComp.character.send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ())));
            physics.removeCharacterCollider(clientComp.character);
            physics.getCharacterCollider(clientComp.character);
            return "Height of player set to " + amount + " (was " + prevHeight + ")";
        }
        return "";
    } catch (NullPointerException e) {
        e.printStackTrace();
        return "";
    }
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 12 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method teleportPlayerToMe.

@Command(shortDescription = "Teleport player to you", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToMe(@Sender EntityRef sender, @CommandParam("username") String username) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (username.equalsIgnoreCase(name.name)) {
            LocationComponent locationComponent = sender.getComponent(LocationComponent.class);
            if (locationComponent != null) {
                Vector3f vLocation = locationComponent.getWorldPosition();
                ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
                if (clientComp != null) {
                    clientComp.character.send(new CharacterTeleportEvent(vLocation));
                    return "Teleporting " + username + " to you at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
                }
            }
        }
    }
    throw new IllegalArgumentException("No such user '" + username + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 13 with LocationComponent

use of org.terasology.logic.location.LocationComponent 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);
    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 Quat4f(Quat4f.IDENTITY));
    } else {
        Location.attachChild(targetEntityForCamera, clientComponent.camera, Vector3f.zero(), new Quat4f(Quat4f.IDENTITY));
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 14 with LocationComponent

use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class FirstPersonClientSystem method linkHeldItemLocationForLocalPlayer.

/**
 * Changes held item entity.
 *
 * <p>Detaches old held item and removes it's components. Adds components to new held item and
 * attaches it to the mount point entity.</p>
 */
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem) {
    if (!newItem.equals(currentHeldItem)) {
        EntityRef camera = localPlayer.getCameraEntity();
        FirstPersonHeldItemMountPointComponent mountPointComponent = camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
        if (mountPointComponent != null) {
            // currentHeldItem is at this point the old item
            if (currentHeldItem != EntityRef.NULL) {
                currentHeldItem.destroy();
            }
            // use the hand if there is no new item
            EntityRef newHeldItem;
            if (newItem == EntityRef.NULL) {
                newHeldItem = getHandEntity();
            } else {
                newHeldItem = newItem;
            }
            // create client side held item entity
            currentHeldItem = entityManager.create();
            // add the visually relevant components
            for (Component component : newHeldItem.iterateComponents()) {
                if (component instanceof VisualComponent) {
                    currentHeldItem.addComponent(component);
                }
            }
            // ensure world location is set
            currentHeldItem.addComponent(new LocationComponent());
            currentHeldItem.addComponent(new ItemIsHeldComponent());
            FirstPersonHeldItemTransformComponent heldItemTransformComponent = currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
            if (heldItemTransformComponent == null) {
                heldItemTransformComponent = new FirstPersonHeldItemTransformComponent();
                currentHeldItem.addComponent(heldItemTransformComponent);
            }
            Location.attachChild(mountPointComponent.mountPointEntity, currentHeldItem, heldItemTransformComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z), heldItemTransformComponent.scale);
        }
    }
}
Also used : VisualComponent(org.terasology.rendering.logic.VisualComponent) VisualComponent(org.terasology.rendering.logic.VisualComponent) CharacterHeldItemComponent(org.terasology.logic.characters.CharacterHeldItemComponent) OnActivatedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent) OnChangedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnChangedComponent) CharacterComponent(org.terasology.logic.characters.CharacterComponent) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 15 with LocationComponent

use of org.terasology.logic.location.LocationComponent 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)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)69 EntityRef (org.terasology.entitySystem.entity.EntityRef)40 Vector3f (org.terasology.math.geom.Vector3f)39 ClientComponent (org.terasology.network.ClientComponent)17 Quat4f (org.terasology.math.geom.Quat4f)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Command (org.terasology.logic.console.commandSystem.annotations.Command)10 Vector3i (org.terasology.math.geom.Vector3i)10 BlockComponent (org.terasology.world.block.BlockComponent)7 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 Vector3f (javax.vecmath.Vector3f)5 Component (org.terasology.entitySystem.Component)5 BaseVector3f (org.terasology.math.geom.BaseVector3f)5 MeshComponent (org.terasology.rendering.logic.MeshComponent)5 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)4 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)4 Matrix4f (org.terasology.math.geom.Matrix4f)4 BlockFamily (org.terasology.world.block.family.BlockFamily)4 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)3