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;
}
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);
}
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;
}
}
}
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";
}
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;
}
Aggregations