Search in sources :

Example 36 with LocationComponent

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

use of org.terasology.engine.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 : Component(org.terasology.gestalt.entitysystem.component.Component) RigidBodyComponent(org.terasology.engine.physics.components.RigidBodyComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) OnAddedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent) BlockItemComponent(org.terasology.engine.world.block.items.BlockItemComponent) BoxShapeComponent(org.terasology.engine.physics.components.shapes.BoxShapeComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 38 with LocationComponent

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

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3fc storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 39 with LocationComponent

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

the class PojoEntityPool method create.

private EntityRef create(Prefab prefab, Vector3fc position, Quaternionfc rotation, boolean sendLifecycleEvents) {
    EntityBuilder builder = newBuilder(prefab);
    builder.setSendLifecycleEvents(sendLifecycleEvents);
    LocationComponent loc = builder.getComponent(LocationComponent.class);
    if (loc == null && (position != null || rotation != null)) {
        loc = new LocationComponent();
        builder.addComponent(loc);
    }
    if (position != null) {
        loc.setWorldPosition(position);
    }
    if (rotation != null) {
        loc.setWorldRotation(rotation);
    }
    return builder.build();
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 40 with LocationComponent

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

the class CharacterSystem method update.

@Override
public void update(float delta) {
    Iterable<EntityRef> characterEntities = entityManager.getEntitiesWith(CharacterComponent.class, LocationComponent.class);
    for (EntityRef characterEntity : characterEntities) {
        CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
        if (characterComponent == null) {
            // could have changed during events below
            continue;
        }
        LocationComponent characterLocation = characterEntity.getComponent(LocationComponent.class);
        if (characterLocation == null) {
            // could have changed during events below
            continue;
        }
        EntityRef target = characterComponent.authorizedInteractionTarget;
        if (target.isActive()) {
            LocationComponent targetLocation = target.getComponent(LocationComponent.class);
            if (targetLocation == null) {
                // could have changed during events below
                continue;
            }
            float maxInteractionRange = characterComponent.interactionRange;
            if (isDistanceToLarge(characterLocation, targetLocation, maxInteractionRange)) {
                InteractionUtil.cancelInteractionAsServer(characterEntity);
            }
        }
    }
}
Also used : PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) 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