Search in sources :

Example 26 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class KinematicCharacterMover method step.

@Override
public CharacterStateEvent step(CharacterStateEvent initial, CharacterMoveInputEvent input, EntityRef entity) {
    CharacterMovementComponent characterMovementComponent = entity.getComponent(CharacterMovementComponent.class);
    CharacterStateEvent result = new CharacterStateEvent(initial);
    result.setSequenceNumber(input.getSequenceNumber());
    if (worldProvider.isBlockRelevant(initial.getPosition())) {
        updatePosition(characterMovementComponent, result, input, entity);
        if (input.isFirstRun()) {
            checkBlockEntry(entity, new Vector3i(initial.getPosition(), RoundingMode.HALF_UP), new Vector3i(result.getPosition(), RoundingMode.HALF_UP), characterMovementComponent.height);
        }
        if (result.getMode() != MovementMode.GHOSTING && result.getMode() != MovementMode.NONE) {
            checkMode(characterMovementComponent, result, initial, entity, input.isFirstRun(), input.isCrouching());
        }
    }
    result.setTime(initial.getTime() + input.getDeltaMs());
    updateRotation(characterMovementComponent, result, input);
    result.setPitch(input.getPitch());
    result.setYaw(input.getYaw());
    input.runComplete();
    return result;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 27 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class KinematicCharacterMover method checkMode.

/**
 * Checks whether a character should change movement mode (from being underwater or in a ladder). A higher and lower point of the
 * character is tested for being in water, only if both points are in water does the character count as swimming.
 * <br><br>
 * Sends the OnEnterLiquidEvent and OnLeaveLiquidEvent events.
 *
 * @param movementComp The movement component of the character.
 * @param state        The current state of the character.
 */
private void checkMode(final CharacterMovementComponent movementComp, final CharacterStateEvent state, final CharacterStateEvent oldState, EntityRef entity, boolean firstRun, boolean isCrouching) {
    // If we are ghosting or we can't move, the mode cannot be changed.
    if (!state.getMode().respondToEnvironment) {
        return;
    }
    Vector3f worldPos = state.getPosition();
    Vector3f top = new Vector3f(worldPos);
    Vector3f bottom = new Vector3f(worldPos);
    top.y += 0.5f * movementComp.height;
    bottom.y -= 0.5f * movementComp.height;
    final boolean topUnderwater = worldProvider.getBlock(top).isLiquid();
    final boolean bottomUnderwater = worldProvider.getBlock(bottom).isLiquid();
    final boolean newSwimming = !topUnderwater && bottomUnderwater;
    final boolean newDiving = topUnderwater && bottomUnderwater;
    boolean newClimbing = false;
    if (isClimbingAllowed(newSwimming, newDiving)) {
        Vector3i finalDir;
        finalDir = findClimbable(movementComp, worldPos, newSwimming, newDiving);
        if (finalDir != null) {
            newClimbing = true;
            state.setClimbDirection(finalDir);
        }
    }
    updateMode(state, newSwimming, newDiving, newClimbing, isCrouching);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i)

Example 28 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class KinematicCharacterMover method climb.

private void climb(final CharacterStateEvent state, CharacterMoveInputEvent input, Vector3f desiredVelocity) {
    if (state.getClimbDirection() == null) {
        return;
    }
    Vector3f tmp;
    Vector3i climbDir3i = state.getClimbDirection();
    Vector3f climbDir3f = climbDir3i.toVector3f();
    Quat4f rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0);
    tmp = new Vector3f(0.0f, 0.0f, -1.0f);
    rotation.rotate(tmp, tmp);
    float angleToClimbDirection = tmp.angle(climbDir3f);
    boolean clearMovementToDirection = !state.isGrounded();
    boolean jumpOrCrouchActive = desiredVelocity.y != 0;
    // facing the ladder or looking down or up
    if (angleToClimbDirection < Math.PI / 4.0 || Math.abs(input.getPitch()) > 60f) {
        if (jumpOrCrouchActive) {
            desiredVelocity.x = 0;
            desiredVelocity.z = 0;
            clearMovementToDirection = false;
        } else {
            float pitchAmount = state.isGrounded() ? 45f : 90f;
            float pitch = input.getPitch() > 30f ? pitchAmount : -pitchAmount;
            rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), TeraMath.DEG_TO_RAD * pitch, 0);
            rotation.rotate(desiredVelocity, desiredVelocity);
        }
    // looking sidewards from ladder
    } else if (angleToClimbDirection < Math.PI * 3.0 / 4.0) {
        float rollAmount = state.isGrounded() ? 45f : 90f;
        tmp = new Vector3f();
        rotation.rotate(climbDir3f, tmp);
        float leftOrRight = tmp.x;
        float plusOrMinus = (leftOrRight < 0f ? -1.0f : 1.0f) * (climbDir3i.x != 0 ? -1.0f : 1.0f);
        if (jumpOrCrouchActive) {
            rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0);
        } else {
            rotation = new Quat4f(TeraMath.DEG_TO_RAD * input.getYaw(), 0f, TeraMath.DEG_TO_RAD * rollAmount * plusOrMinus);
        }
        rotation.rotate(desiredVelocity, desiredVelocity);
    // facing away from ladder
    } else {
        rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0);
        rotation.rotate(desiredVelocity, desiredVelocity);
        clearMovementToDirection = false;
    }
    // clear out movement towards or away from the ladder
    if (clearMovementToDirection) {
        if (climbDir3i.x != 0) {
            desiredVelocity.x = 0f;
        }
        if (climbDir3i.z != 0) {
            desiredVelocity.z = 0f;
        }
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Quat4f(org.terasology.math.geom.Quat4f)

Example 29 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class ServerCommands method reloadChunk.

@Command(shortDescription = "Invalidates the specified chunk and recreates it (requires storage manager disabled)", runOnServer = true)
public String reloadChunk(@CommandParam("x") int x, @CommandParam("y") int y, @CommandParam("z") int z) {
    Vector3i pos = new Vector3i(x, y, z);
    if (config.getSystem().isWriteSaveGamesEnabled()) {
        return "Writing save games is enabled! Invalidating chunk has no effect";
    }
    boolean success = chunkProvider.reloadChunk(pos);
    return success ? "Cleared chunk " + pos + " from cache and triggered reload" : "Chunk " + pos + " did not exist in the cache";
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 30 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class ChunkMonitorDisplay method recomputeRenderY.

private void recomputeRenderY() {
    int min = 0;
    int max = 0;
    int y = renderY;
    for (ChunkMonitorEntry chunk : chunks) {
        final Vector3i pos = chunk.getPosition();
        if (pos.y < min) {
            min = pos.y;
        }
        if (pos.y > max) {
            max = pos.y;
        }
    }
    if (y < min) {
        y = min;
    }
    if (y > max) {
        y = max;
    }
    minRenderY = min;
    maxRenderY = max;
    renderY = y;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) ChunkMonitorEntry(org.terasology.monitoring.chunk.ChunkMonitorEntry) Point(java.awt.Point)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)249 Test (org.junit.Test)94 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6