Search in sources :

Example 11 with Vector3i

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

the class PlayerSystem method respawnPlayer.

private void respawnPlayer(EntityRef clientEntity) {
    ClientComponent client = clientEntity.getComponent(ClientComponent.class);
    EntityRef playerCharacter = client.character;
    LocationComponent location = clientEntity.getComponent(LocationComponent.class);
    PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
    Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
    location.setWorldPosition(spawnPosition);
    clientEntity.saveComponent(location);
    playerCharacter.addComponent(new AliveCharacterComponent());
    playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
    logger.debug("Re-spawing player at: {}", spawnPosition);
    Client clientListener = networkSystem.getOwner(clientEntity);
    Vector3i distance = clientListener.getViewDistance().getChunkDistance();
    updateRelevanceEntity(clientEntity, distance);
    playerCharacter.send(new OnPlayerRespawnedEvent());
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) OnPlayerRespawnedEvent(org.terasology.logic.players.event.OnPlayerRespawnedEvent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent)

Example 12 with Vector3i

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

the class AbstractSpawner method findSpawnPosition.

/**
 * Tries to find a suitable spawning point based on {@link SurfaceHeightFacet} and {@link SeaLevelFacet}.
 * @param searchRadius the radius within a suitable spawning point will be searched
 * @param world the facet-based world
 * @param pos the desired 2D position in that world
 * @return a 3D position above the surface and sea level or <code>null</code> if none was found
 * @throws IllegalStateException if no SurfaceHeightFacet can be created.
 */
protected Vector3f findSpawnPosition(World world, Vector2i pos, int searchRadius) {
    Vector3i ext = new Vector3i(searchRadius, 1, searchRadius);
    Vector3i desiredPos = new Vector3i(pos.getX(), 1, pos.getY());
    // try and find somewhere in this region a spot to land
    Region3i spawnArea = Region3i.createFromCenterExtents(desiredPos, ext);
    Region worldRegion = world.getWorldData(spawnArea);
    // check if generation uses sea level and surface height facets
    SurfaceHeightFacet surfaceHeightFacet = worldRegion.getFacet(SurfaceHeightFacet.class);
    if (surfaceHeightFacet == null) {
        throw new IllegalStateException("surface height facet not found");
    }
    SeaLevelFacet seaLevelFacet = worldRegion.getFacet(SeaLevelFacet.class);
    int seaLevel = (seaLevelFacet != null) ? seaLevelFacet.getSeaLevel() : 0;
    int spiralRad = searchRadius / 2 - 1;
    SpiralIterable spiral = SpiralIterable.clockwise(pos).maxRadius(spiralRad).scale(2).build();
    for (BaseVector2i test : spiral) {
        float val = surfaceHeightFacet.getWorld(test.getX(), test.getY());
        int height = TeraMath.floorToInt(val);
        if (height >= seaLevel) {
            return new Vector3f(test.getX(), height, test.getY());
        }
    }
    // nothing above sea level found
    float y = surfaceHeightFacet.getWorld(pos.getX(), pos.getY());
    return new Vector3f(pos.getX(), y, pos.getY());
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region(org.terasology.world.generation.Region) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) SpiralIterable(org.terasology.math.geom.SpiralIterable) Region3i(org.terasology.math.Region3i)

Example 13 with Vector3i

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

the class ChunkMath method calcChunkPos.

public static Vector3i[] calcChunkPos(Region3i region, Vector3i chunkPower) {
    int minX = calcChunkPosX(region.minX(), chunkPower.x);
    int minY = calcChunkPosY(region.minY(), chunkPower.y);
    int minZ = calcChunkPosZ(region.minZ(), chunkPower.z);
    int maxX = calcChunkPosX(region.maxX(), chunkPower.x);
    int maxY = calcChunkPosY(region.maxY(), chunkPower.y);
    int maxZ = calcChunkPosZ(region.maxZ(), chunkPower.z);
    int size = (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1);
    Vector3i[] result = new Vector3i[size];
    int index = 0;
    for (int x = minX; x <= maxX; x++) {
        for (int y = minY; y <= maxY; y++) {
            for (int z = minZ; z <= maxZ; z++) {
                result[index++] = new Vector3i(x, y, z);
            }
        }
    }
    return result;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 14 with Vector3i

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

the class ChunkMath method getEdgeRegion.

/**
 * Produces a region containing the region touching the side of the given region, both in and outside the region.
 *
 * @param region
 * @param side
 * @return
 */
public static Region3i getEdgeRegion(Region3i region, Side side) {
    Vector3i sideDir = side.getVector3i();
    Vector3i min = region.min();
    Vector3i max = region.max();
    Vector3i edgeMin = new Vector3i(min);
    Vector3i edgeMax = new Vector3i(max);
    if (sideDir.x < 0) {
        edgeMin.x = min.x;
        edgeMax.x = min.x;
    } else if (sideDir.x > 0) {
        edgeMin.x = max.x;
        edgeMax.x = max.x;
    } else if (sideDir.y < 0) {
        edgeMin.y = min.y;
        edgeMax.y = min.y;
    } else if (sideDir.y > 0) {
        edgeMin.y = max.y;
        edgeMax.y = max.y;
    } else if (sideDir.z < 0) {
        edgeMin.z = min.z;
        edgeMax.z = min.z;
    } else if (sideDir.z > 0) {
        edgeMin.z = max.z;
        edgeMax.z = max.z;
    }
    return Region3i.createFromMinMax(edgeMin, edgeMax);
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 15 with Vector3i

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

the class Region3i method createEncompassing.

public static Region3i createEncompassing(Region3i a, Region3i b) {
    if (a.isEmpty()) {
        return b;
    }
    if (b.isEmpty()) {
        return a;
    }
    Vector3i min = a.min();
    min.min(b.min());
    Vector3i max = a.max();
    max.max(b.max());
    return createFromMinMax(min, max);
}
Also used : BaseVector3i(org.terasology.math.geom.BaseVector3i) Vector3i(org.terasology.math.geom.Vector3i)

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