Search in sources :

Example 41 with LocationComponent

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

the class CharacterMovementSystemUtility method extrapolateLocationComponent.

private void extrapolateLocationComponent(EntityRef entity, CharacterStateEvent state, Vector3f newPos) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    location.setWorldPosition(newPos);
    location.setWorldRotation(state.getRotation());
    entity.saveComponent(location);
}
Also used : LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 42 with LocationComponent

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

the class CharacterMovementSystemUtility method setToState.

/**
 * Sets the state of the given entity to the state represented by the
 * CharacterStateEvent. The state of the entity is determined by its
 * LocationComponent (location and orientation of physics body),
 * CharacterMovementComponent (velocity and various movement state
 * variables) and CharacterComponent for pitch and yaw (used for the camera).
 *
 * @param entity
 * @param state
 */
public void setToState(EntityRef entity, CharacterStateEvent state) {
    LocationComponent location = entity.getComponent(LocationComponent.class);
    CharacterMovementComponent movementComp = entity.getComponent(CharacterMovementComponent.class);
    if (location == null || !location.getWorldPosition(new Vector3f()).isFinite() || movementComp == null) {
        return;
    }
    location.setWorldPosition(state.getPosition());
    location.setWorldRotation(state.getRotation());
    entity.saveComponent(location);
    movementComp.mode = state.getMode();
    movementComp.setVelocity(state.getVelocity());
    movementComp.grounded = state.isGrounded();
    movementComp.footstepDelta = state.getFootstepDelta();
    entity.saveComponent(movementComp);
    setPhysicsLocation(entity, state.getPosition());
    // set the pitch to the character's gaze entity
    Quaternionf rotation = new Quaternionf().rotationX(TeraMath.DEG_TO_RAD * state.getPitch());
    EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(entity);
    if (!gazeEntity.equals(entity)) {
        // Only set the gaze entity rotation if it is not the same as the main entity.
        // The character is assumed to only rotate side to side, introducing pitch makes things act strangely
        LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
        gazeLocation.setLocalRotation(rotation);
        gazeEntity.saveComponent(gazeLocation);
    }
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 43 with LocationComponent

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

the class VisualCharacterSystem method createAndAttachVisualEntity.

private EntityRef createAndAttachVisualEntity(EntityBuilder entityBuilder, EntityRef characterEntity) {
    entityBuilder.setPersistent(false);
    entityBuilder.setOwner(characterEntity);
    entityBuilder.addOrSaveComponent(new LocationComponent());
    EntityRef visualCharacterEntity = entityBuilder.build();
    Location.attachChild(characterEntity, visualCharacterEntity, new Vector3f(), new Quaternionf());
    return visualCharacterEntity;
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 44 with LocationComponent

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

the class ActivationPredicted method getInstigatorLocation.

public Vector3f getInstigatorLocation() {
    LocationComponent loc = instigator.getComponent(LocationComponent.class);
    if (loc != null) {
        Vector3f result = loc.getWorldPosition(new Vector3f());
        if (result.isFinite()) {
            return result;
        }
        result.set(0, 0, 0);
        return result;
    }
    return new Vector3f();
}
Also used : Vector3f(org.joml.Vector3f) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 45 with LocationComponent

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

the class PlayerSystem method setSpawnLocationOnRespawnRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
    ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
    EntityRef character = clientComponent.character;
    EntityRef clientInfo = clientComponent.clientInfo;
    Vector3fc spawnPosition;
    if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
        spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
    } else {
        spawnPosition = worldGenerator.getSpawnPosition(entity);
    }
    LocationComponent loc = character.getComponent(LocationComponent.class);
    loc.setWorldPosition(spawnPosition);
    // reset rotation
    loc.setLocalRotation(new Quaternionf());
    character.saveComponent(loc);
}
Also used : Vector3fc(org.joml.Vector3fc) Quaternionf(org.joml.Quaternionf) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

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