Search in sources :

Example 61 with LocationComponent

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

the class MovementDebugCommands method teleportPlayerToPlayer.

@Command(shortDescription = "Teleport User1 to User2", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToPlayer(@CommandParam("usernameFrom") String usernameFrom, @CommandParam("usernameTo") String usernameTo) {
    if (usernameFrom.equalsIgnoreCase(usernameTo)) {
        throw new IllegalArgumentException("Why teleport to yourself...");
    }
    EntityRef entityFrom = null;
    EntityRef entityTo = null;
    boolean foundEntityFrom = false;
    boolean foundEntityTo = false;
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (!foundEntityFrom && usernameFrom.equalsIgnoreCase(name.name)) {
            entityFrom = clientEntity;
            foundEntityFrom = true;
        } else if (!foundEntityTo && usernameTo.equalsIgnoreCase(name.name)) {
            entityTo = clientEntity;
            foundEntityTo = true;
        }
        if (foundEntityFrom && foundEntityTo) {
            break;
        }
    }
    if (!foundEntityFrom) {
        throw new IllegalArgumentException("No such user '" + usernameFrom + "'");
    }
    if (!foundEntityTo) {
        throw new IllegalArgumentException("No such user '" + usernameTo + "'");
    }
    LocationComponent locationComponent = entityTo.getComponent(LocationComponent.class);
    if (locationComponent != null) {
        Vector3f vLocation = locationComponent.getWorldPosition();
        ClientComponent clientComp = entityFrom.getComponent(ClientComponent.class);
        if (clientComp != null) {
            clientComp.character.send(new CharacterTeleportEvent(vLocation));
            return "Teleporting " + usernameFrom + " to " + usernameTo + " at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
        }
    }
    throw new IllegalArgumentException("User " + usernameTo + " has an invalid location.");
}
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 62 with LocationComponent

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

the class ItemPickupAuthoritySystem method onDropItemEvent.

@ReceiveEvent
public void onDropItemEvent(DropItemEvent event, EntityRef itemEntity, ItemComponent itemComponent) {
    for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
        Component componentCopy = library.getComponentLibrary().copy(component);
        if (componentCopy instanceof LocationComponent) {
            ((LocationComponent) componentCopy).setWorldPosition(event.getPosition());
        }
        itemEntity.addOrSaveComponent(componentCopy);
    }
    if (!itemEntity.hasComponent(LocationComponent.class)) {
        itemEntity.addComponent(new LocationComponent(event.getPosition()));
    }
}
Also used : LocationComponent(org.terasology.logic.location.LocationComponent) RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) OnAddedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent) Component(org.terasology.entitySystem.Component) BoxShapeComponent(org.terasology.physics.components.shapes.BoxShapeComponent) BlockItemComponent(org.terasology.world.block.items.BlockItemComponent) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 63 with LocationComponent

use of org.terasology.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 Quat4f(1, 0, 0, 0));
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) FloatingTextComponent(org.terasology.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 64 with LocationComponent

use of org.terasology.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 Quat4f(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.terasology.math.geom.Vector3f) CharacterHeldItemComponent(org.terasology.logic.characters.CharacterHeldItemComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 65 with LocationComponent

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

the class LocalPlayer method getViewRotation.

public Quat4f getViewRotation() {
    ClientComponent clientComponent = getClientEntity().getComponent(ClientComponent.class);
    if (clientComponent == null) {
        return new Quat4f(Quat4f.IDENTITY);
    }
    LocationComponent location = clientComponent.camera.getComponent(LocationComponent.class);
    if (location == null) {
        return getRotation();
    }
    return location.getWorldRotation();
}
Also used : ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

LocationComponent (org.terasology.logic.location.LocationComponent)68 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