Search in sources :

Example 31 with LocationComponent

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

the class MovementDebugCommands method teleportMeToPlayer.

@Command(shortDescription = "Teleport to player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String teleportMeToPlayer(@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 = clientEntity.getComponent(LocationComponent.class);
            if (locationComponent != null) {
                Vector3f vLocation = locationComponent.getWorldPosition(new Vector3f());
                ClientComponent clientComp = sender.getComponent(ClientComponent.class);
                if (clientComp != null) {
                    clientComp.character.send(new CharacterTeleportEvent(vLocation));
                    return "Teleporting you to " + username + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
                }
            }
        }
    }
    throw new IllegalArgumentException("No such user '" + username + "'");
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.engine.logic.characters.CharacterTeleportEvent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 32 with LocationComponent

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

the class FirstPersonClientSystem method update.

/**
 * modifies the held item mount point to move the held item in first person view
 */
@Override
public void update(float delta) {
    // ensure empty hand is shown if no item is hold at the moment
    if (!currentHeldItem.exists() && currentHeldItem != getHandEntity()) {
        linkHeldItemLocationForLocalPlayer(getHandEntity());
    }
    // ensure that there are no lingering items that are marked as still held. This situation happens with client side predicted items
    for (EntityRef entityRef : entityManager.getEntitiesWith(ItemIsHeldComponent.class)) {
        if (!entityRef.equals(currentHeldItem) && !entityRef.equals(handEntity)) {
            entityRef.destroy();
        }
    }
    // get the first person mount point and rotate it away from the camera
    CharacterHeldItemComponent characterHeldItemComponent = localPlayer.getCharacterEntity().getComponent(CharacterHeldItemComponent.class);
    FirstPersonHeldItemMountPointComponent mountPointComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (characterHeldItemComponent == null || mountPointComponent == null) {
        return;
    }
    LocationComponent locationComponent = mountPointComponent.mountPointEntity.getComponent(LocationComponent.class);
    if (locationComponent == null) {
        return;
    }
    long timeElapsedSinceLastUsed = time.getGameTimeInMs() - characterHeldItemComponent.lastItemUsedTime;
    float animateAmount = 0f;
    if (timeElapsedSinceLastUsed < USEANIMATIONLENGTH) {
        // half way through the animation will be the maximum extent of rotation and translation
        animateAmount = 1f - Math.abs(((float) timeElapsedSinceLastUsed / (float) USEANIMATIONLENGTH) - 0.5f);
    }
    float addPitch = 15f * animateAmount;
    float addYaw = 10f * animateAmount;
    locationComponent.setLocalRotation(new Quaternionf().rotationYXZ(TeraMath.DEG_TO_RAD * (mountPointComponent.rotateDegrees.y + addYaw), TeraMath.DEG_TO_RAD * (mountPointComponent.rotateDegrees.x + addPitch), TeraMath.DEG_TO_RAD * mountPointComponent.rotateDegrees.z));
    Vector3f offset = new Vector3f(0.25f * animateAmount, -0.12f * animateAmount, 0f);
    offset.add(mountPointComponent.translate);
    locationComponent.setLocalPosition(offset);
    mountPointComponent.mountPointEntity.saveComponent(locationComponent);
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) CharacterHeldItemComponent(org.terasology.engine.logic.characters.CharacterHeldItemComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 33 with LocationComponent

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

the class NameTagClientSystem method createOrUpdateNameTagFor.

private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
    EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
    Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
    if (nameTag != null) {
        FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
        floatingText.text = nameTagComponent.text;
        floatingText.textColor = nameTagComponent.textColor;
        floatingText.scale = nameTagComponent.scale;
        nameTag.saveComponent(floatingText);
        LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
        nameTagLoc.setLocalPosition(offset);
        nameTag.saveComponent(nameTagLoc);
    } else {
        EntityBuilder nameTagBuilder = entityManager.newBuilder();
        FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
        nameTagBuilder.addComponent(floatingTextComponent);
        LocationComponent locationComponent = new LocationComponent();
        nameTagBuilder.addComponent(locationComponent);
        floatingTextComponent.text = nameTagComponent.text;
        floatingTextComponent.textColor = nameTagComponent.textColor;
        floatingTextComponent.scale = nameTagComponent.scale;
        nameTagBuilder.setOwner(entity);
        nameTagBuilder.setPersistent(false);
        nameTag = nameTagBuilder.build();
        nameTagEntityToFloatingTextMap.put(entity, nameTag);
        Location.attachChild(entity, nameTag, offset, new Quaternionf());
    }
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) FloatingTextComponent(org.terasology.engine.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 34 with LocationComponent

use of org.terasology.engine.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);
    // 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 35 with LocationComponent

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

Aggregations

LocationComponent (org.terasology.engine.logic.location.LocationComponent)65 Vector3f (org.joml.Vector3f)46 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)40 Quaternionf (org.joml.Quaternionf)18 ClientComponent (org.terasology.engine.network.ClientComponent)17 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)9 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)9 Matrix4f (org.joml.Matrix4f)7 Vector3i (org.joml.Vector3i)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)5 Vector3fc (org.joml.Vector3fc)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)4 CharacterHeldItemComponent (org.terasology.engine.logic.characters.CharacterHeldItemComponent)4 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)4 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)4 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 Bone (org.terasology.engine.rendering.assets.skeletalmesh.Bone)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Component (org.terasology.gestalt.entitysystem.component.Component)4