Search in sources :

Example 56 with LocationComponent

use of org.terasology.engine.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(new Vector3f());
        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.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 57 with LocationComponent

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

the class SaveTransaction method createChunkPosToUnsavedOwnerLessEntitiesMap.

private Map<Vector3i, Collection<EntityRef>> createChunkPosToUnsavedOwnerLessEntitiesMap() {
    Map<Vector3i, Collection<EntityRef>> chunkPosToEntitiesMap = Maps.newHashMap();
    for (EntityRef entity : privateEntityManager.getEntitiesWith(LocationComponent.class)) {
        /*
             * Note: Entities with owners get saved with the owner. Entities that are always relevant don't get stored
             * in chunk as the chunk is not always loaded
             */
        if (entity.isPersistent() && !entity.getOwner().exists() && !entity.hasComponent(ClientComponent.class) && !entity.isAlwaysRelevant()) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            if (locationComponent != null) {
                Vector3f loc = locationComponent.getWorldPosition(new Vector3f());
                Vector3i chunkPos = Chunks.toChunkPos((int) loc.x, (int) loc.y, (int) loc.z, new Vector3i());
                Collection<EntityRef> collection = chunkPosToEntitiesMap.get(chunkPos);
                if (collection == null) {
                    collection = Lists.newArrayList();
                    chunkPosToEntitiesMap.put(chunkPos, collection);
                }
                collection.add(entity);
            }
        }
    }
    return chunkPosToEntitiesMap;
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Collection(java.util.Collection) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 58 with LocationComponent

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

the class PlayerStoreInternal method setCharacter.

@Override
public void setCharacter(EntityRef character) {
    this.character = character;
    hasCharacter = character.exists();
    LocationComponent location = character.getComponent(LocationComponent.class);
    if (location == null) {
        return;
    }
    Vector3f position = location.getWorldPosition(new Vector3f());
    if (position.isFinite()) {
        setRelevanceLocation(position);
    }
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 59 with LocationComponent

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

the class ReadWriteStorageManager method createPlayerStore.

private PlayerStoreBuilder createPlayerStore(Client client, EntityRef character) {
    LocationComponent location = character.getComponent(LocationComponent.class);
    Vector3f relevanceLocation;
    if (location != null) {
        relevanceLocation = location.getWorldPosition(new Vector3f());
    } else {
        relevanceLocation = new Vector3f();
    }
    Long characterId;
    if (character.exists()) {
        characterId = character.getId();
    } else {
        characterId = null;
    }
    return new PlayerStoreBuilder(characterId, relevanceLocation);
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 60 with LocationComponent

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

the class BulletPhysics method updateTrigger.

@Override
public // TODO: update if detectGroups changed
boolean updateTrigger(EntityRef entity) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    if (location == null) {
        logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity);
        return false;
    }
    btPairCachingGhostObject triggerObj = entityTriggers.get(entity);
    if (triggerObj != null) {
        float scale = location.getWorldScale();
        if (Math.abs(triggerObj.getCollisionShape().getLocalScaling().x - scale) > SIMD_EPSILON) {
            discreteDynamicsWorld.removeCollisionObject(triggerObj);
            newTrigger(entity);
        } else {
            Quaternionf worldRotation = location.getWorldRotation(new Quaternionf());
            Vector3f position = location.getWorldPosition(new Vector3f());
            if (!position.isFinite() || !worldRotation.isFinite()) {
                logger.warn("Can't update Trigger entity with a non-finite position/rotation?! Entity: {}", entity);
                return false;
            }
            triggerObj.setWorldTransform(new Matrix4f().translationRotateScale(position, worldRotation, 1.0f));
        }
        return true;
    } else {
        newTrigger(entity);
        return false;
    }
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) LocationComponent(org.terasology.engine.logic.location.LocationComponent) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject)

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