Search in sources :

Example 76 with Vector2i

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();
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BaseVector2i(org.terasology.math.geom.BaseVector2i) Vector3i(org.terasology.math.geom.Vector3i) Vector2i(org.terasology.math.geom.Vector2i) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Aggregations

Vector2i (org.terasology.math.geom.Vector2i)76 UIWidget (org.terasology.rendering.nui.UIWidget)17 Rect2i (org.terasology.math.geom.Rect2i)14 BaseVector2i (org.terasology.math.geom.BaseVector2i)13 LayoutHint (org.terasology.rendering.nui.LayoutHint)13 List (java.util.List)9 Test (org.junit.Test)9 Vector2f (org.terasology.math.geom.Vector2f)6 Canvas (org.terasology.rendering.nui.Canvas)5 SubRegion (org.terasology.rendering.nui.SubRegion)5 UIStyle (org.terasology.rendering.nui.skin.UIStyle)5 UILabel (org.terasology.rendering.nui.widgets.UILabel)5 Before (org.junit.Before)4 Font (org.terasology.rendering.assets.font.Font)4 Color (org.terasology.rendering.nui.Color)4 Border (org.terasology.math.Border)3 Vector3f (org.terasology.math.geom.Vector3f)3 Mesh (org.terasology.rendering.assets.mesh.Mesh)3 HorizontalAlign (org.terasology.rendering.nui.HorizontalAlign)3 Sets (com.google.common.collect.Sets)2