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