use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.
the class PlayerFactory method findSpawnPos.
private Optional<Vector3f> findSpawnPos(Vector3f targetPos, float entityHeight) {
int targetBlockX = TeraMath.floorToInt(targetPos.x);
int targetBlockY = TeraMath.floorToInt(targetPos.y);
int targetBlockZ = TeraMath.floorToInt(targetPos.z);
Vector2i center = new Vector2i(targetBlockX, targetBlockZ);
for (BaseVector2i pos : SpiralIterable.clockwise(center).maxRadius(32).scale(2).build()) {
Vector3i testPos = new Vector3i(pos.getX(), targetBlockY, pos.getY());
Vector3i spawnPos = findOpenVerticalPosition(testPos, entityHeight);
if (spawnPos != null) {
return Optional.of(new Vector3f(spawnPos.getX(), spawnPos.getY() + entityHeight, spawnPos.getZ()));
}
}
return Optional.empty();
}
Aggregations