Search in sources :

Example 46 with Vector3i

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

the class LocalChunkProvider method createWorldView.

private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
    Chunk[] chunks = new Chunk[region.sizeX() * region.sizeY() * region.sizeZ()];
    for (Vector3i chunkPos : region) {
        Chunk chunk = chunkCache.get(chunkPos);
        if (chunk == null) {
            return null;
        }
        chunkPos.sub(region.minX(), region.minY(), region.minZ());
        int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
        chunks[index] = chunk;
    }
    return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ManagedChunk(org.terasology.world.chunks.ManagedChunk)

Example 47 with Vector3i

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

the class LocalChunkProvider method addRelevanceEntity.

@Override
public void addRelevanceEntity(EntityRef entity, Vector3i distance, ChunkRegionListener listener) {
    if (!entity.exists()) {
        return;
    }
    regionLock.readLock().lock();
    try {
        ChunkRelevanceRegion region = regions.get(entity);
        if (region != null) {
            region.setRelevanceDistance(distance);
            return;
        }
    } finally {
        regionLock.readLock().unlock();
    }
    ChunkRelevanceRegion region = new ChunkRelevanceRegion(entity, distance);
    if (listener != null) {
        region.setListener(listener);
    }
    regionLock.writeLock().lock();
    try {
        regions.put(entity, region);
    } finally {
        regionLock.writeLock().unlock();
    }
    for (Vector3i pos : region.getCurrentRegion()) {
        Chunk chunk = getChunk(pos);
        if (chunk != null) {
            region.checkIfChunkIsRelevant(chunk);
        } else {
            createOrLoadChunk(pos);
        }
    }
}
Also used : ChunkRelevanceRegion(org.terasology.world.chunks.internal.ChunkRelevanceRegion) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk) ManagedChunk(org.terasology.world.chunks.ManagedChunk)

Example 48 with Vector3i

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

the class RemoteChunkProvider method createWorldView.

private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
    Chunk[] chunks = new Chunk[region.size().x * region.size().y * region.size().z];
    for (Vector3i chunkPos : region) {
        Chunk chunk = chunkCache.get(chunkPos);
        if (chunk == null || !chunk.isReady()) {
            return null;
        }
        chunkPos.sub(region.min());
        int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
        chunks[index] = chunk;
    }
    return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
Also used : ChunkViewCoreImpl(org.terasology.world.internal.ChunkViewCoreImpl) Vector3i(org.terasology.math.geom.Vector3i) Chunk(org.terasology.world.chunks.Chunk)

Example 49 with Vector3i

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

the class SparseBooleanFieldFacet3D method getWorld.

@Override
public boolean getWorld(int x, int y, int z) {
    checkWorldCoords(x, y, z);
    Vector3i rel = worldToRelative(x, y, z);
    Boolean boxed = relData.get(rel);
    return (boxed != null) ? boxed : defValue;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 50 with Vector3i

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

the class SparseBooleanFieldFacet3D method setWorld.

@Override
public void setWorld(int x, int y, int z, boolean value) {
    checkWorldCoords(x, y, z);
    Vector3i rel = worldToRelative(x, y, z);
    if (value != defValue) {
        relData.put(rel, value);
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 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