Package org.terasology.world.chunks

Examples of org.terasology.world.chunks.Chunk


    @Override
    public void setValueAt(Vector3i pos, byte value) {
        setValueAt(getChunk(pos), TeraMath.calcBlockPos(pos.x, pos.y, pos.z), value);
        for (Vector3i affectedChunkPos : TeraMath.getChunkRegionAroundWorldPos(pos, 1)) {
            Chunk dirtiedChunk = chunkProvider.getChunk(affectedChunkPos);
            if (dirtiedChunk != null) {
                dirtiedChunk.setDirty(true);
            }
        }
    }
View Full Code Here


                + 3 * (TeraMath.calcChunkPosZ(blockPos.z, ChunkConstants.POWER_Z) - topLeft.z));
    }

    @Override
    public byte getValueAt(Vector3i pos) {
        Chunk chunk = chunks[chunkIndexOf(pos)];
        if (chunk != null) {
            return rules.getValue(chunk, TeraMath.calcBlockPos(pos));
        }
        return UNAVAILABLE;
    }
View Full Code Here

        return UNAVAILABLE;
    }

    @Override
    public void setValueAt(Vector3i pos, byte value) {
        Chunk chunk = chunks[chunkIndexOf(pos)];
        if (chunk != null) {
            rules.setValue(chunk, TeraMath.calcBlockPos(pos), value);
        }
    }
View Full Code Here

    }

    @Override
    public Block getBlockAt(Vector3i pos) {
        int index = chunkIndexOf(pos);
        Chunk chunk = chunks[index];
        if (chunk != null) {
            return chunk.getBlock(TeraMath.calcBlockPos(pos));
        }
        return null;
    }
View Full Code Here

        Chunk[] localChunks = new Chunk[27];
        int index = 0;
        for (int z = -1; z < 2; ++z) {
            for (int y = -1; y < 2; ++y) {
                for (int x = -1; x < 2; ++x) {
                    Chunk localChunk = chunkProvider.getChunk(chunk.getPosition().x + x, chunk.getPosition().y + y, chunk.getPosition().z + z);
                    if (localChunk != null) {
                        localChunks[index] = localChunk;
                    }
                    index++;
                }
View Full Code Here

    }

    private ChunkViewCore createWorldView(Region3i region, Vector3i offset) {
        Chunk[] chunks = new Chunk[region.sizeX() * region.sizeY() * region.sizeZ()];
        for (Vector3i chunkPos : region) {
            Chunk chunk = nearCache.get(chunkPos);
            if (chunk == null || !chunk.isReady()) {
                return null;
            }
            chunkPos.sub(region.minX(), region.minY(), region.minZ());
            int index = TeraMath.calculate3DArrayIndex(chunkPos, region.size());
            chunks[index] = chunk;
View Full Code Here

            regions.put(entity, region);
        } finally {
            regionLock.writeLock().unlock();
        }
        for (Vector3i pos : region.getCurrentRegion()) {
            Chunk chunk = getChunk(pos);
            if (chunk != null) {
                region.chunkReady(chunk);
            } else {
                createOrLoadChunk(pos);
            }
View Full Code Here

    @Override
    public void completeUpdate() {
        ReadyChunkInfo readyChunkInfo = lightMerger.completeMerge();
        if (readyChunkInfo != null) {
            Chunk chunk = readyChunkInfo.getChunk();
            chunk.lock();
            try {
                chunk.markReady();
                if (!readyChunkInfo.isNewChunk()) {
                    PerformanceMonitor.startActivity("Generating Block Entities");
                    generateBlockEntities(chunk);
                    PerformanceMonitor.endActivity();
                }
                if (readyChunkInfo.getChunkStore() != null) {
                    readyChunkInfo.getChunkStore().restoreEntities();
                }

                if (!readyChunkInfo.isNewChunk()) {
                    PerformanceMonitor.startActivity("Sending OnAddedBlocks");
                    readyChunkInfo.getBlockPositionMapppings().forEachEntry(new TShortObjectProcedure<TIntList>() {
                        @Override
                        public boolean execute(short id, TIntList positions) {
                            if (positions.size() > 0) {
                                blockManager.getBlock(id).getEntity().send(new OnAddedBlocks(positions, registry));
                            }
                            return true;
                        }
                    });
                    PerformanceMonitor.endActivity();
                }

                PerformanceMonitor.startActivity("Sending OnActivateBlocks");
                readyChunkInfo.getBlockPositionMapppings().forEachEntry(new TShortObjectProcedure<TIntList>() {
                    @Override
                    public boolean execute(short id, TIntList positions) {
                        if (positions.size() > 0) {
                            blockManager.getBlock(id).getEntity().send(new OnActivatedBlocks(positions, registry));
                        }
                        return true;
                    }
                });
                PerformanceMonitor.endActivity();

                if (!readyChunkInfo.isNewChunk()) {
                    worldEntity.send(new OnChunkGenerated(readyChunkInfo.getPos()));
                }
                worldEntity.send(new OnChunkLoaded(readyChunkInfo.getPos()));
                for (ChunkRelevanceRegion region : regions.values()) {
                    region.chunkReady(chunk);
                }
            } finally {
                chunk.unlock();
            }
        }
    }
View Full Code Here

                }
            }
            if (!keep) {
                // TODO: need some way to not dispose chunks being edited or processed (or do so safely)
                // Note: Above won't matter if all changes are on the main thread
                Chunk chunk = nearCache.get(pos);
                if (chunk.isLocked()) {
                    continue;
                }
                chunk.lock();
                try {
                    if (!chunk.isReady()) {
                        // Chunk hasn't been finished or changed, so just drop it.
                        iterator.remove();
                        Iterator<ReadyChunkInfo> infoIterator = sortedReadyChunks.iterator();
                        while (infoIterator.hasNext()) {
                            ReadyChunkInfo next = infoIterator.next();
                            if (next.getPos().equals(chunk.getPosition())) {
                                infoIterator.remove();
                                break;
                            }
                        }
                        continue;
                    }
                    worldEntity.send(new BeforeChunkUnload(pos));
                    for (ChunkRelevanceRegion region : regions.values()) {
                        region.chunkUnloaded(pos);
                    }
                    storageManager.deactivateChunk(chunk);
                    chunk.dispose();

                    try {
                        unloadRequestTaskMaster.put(new ChunkUnloadRequest(chunk, this));
                    } catch (InterruptedException e) {
                        logger.error("Failed to enqueue unload request for {}", chunk.getPosition(), e);
                    }
                    iterator.remove();
                    if (++unloaded >= UNLOAD_PER_FRAME) {
                        break;
                    }
                } finally {
                    chunk.unlock();
                }
            }
        }
        PerformanceMonitor.endActivity();
    }
View Full Code Here

    private void updateRelevance() {
        for (ChunkRelevanceRegion chunkRelevanceRegion : regions.values()) {
            chunkRelevanceRegion.update();
            if (chunkRelevanceRegion.isDirty()) {
                for (Vector3i pos : chunkRelevanceRegion.getNeededChunks()) {
                    Chunk chunk = nearCache.get(pos);
                    if (chunk != null && chunk.isReady()) {
                        chunkRelevanceRegion.chunkReady(chunk);
                    } else if (chunk == null) {
                        createOrLoadChunk(pos);
                    }
                }
View Full Code Here

TOP

Related Classes of org.terasology.world.chunks.Chunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.