public ChunkRegionRender(ChunkRegion chunkRegion) { _chunkRegion = chunkRegion; _renders = new ConcurrentDictionary <string, BlockRender>(); _deleted = false; }
public Chunk(ChunkRegion region, Vector3i position) { _region = region; _position = position; _blocks = new Block[ChunkLength, ChunkLength, ChunkLength]; _taskManager = new WorldTaskManager(); _modified = true; _natural = false; }
public Chunk CreateChunk(Vector3i position) { var regionPosition = position >> 2; var region = GetChunkRegion(regionPosition); if (region == null) { region = new ChunkRegion(this, regionPosition); region.LoadIfDeleted(); _chunkRegions[regionPosition] = region; } else { region.LoadIfDeleted(); } var chunk = region.GetChunkFromChunkPosition(position); if (chunk != null) { return(chunk); } var chunkPositionInRegion = position - (regionPosition << 2); if (region.TryLoadSavedChunk(chunkPositionInRegion, out chunk)) { _unloadedChunkGenerationManager.OnChunkLoad(chunk); return(chunk); } chunk = new Chunk(region, position) { Natural = true }; region.SetChunk(chunk, chunkPositionInRegion); _worldGenerator.GenerateChunkData(chunk); _unloadedChunkGenerationManager.FlushToAllChunks(); return(chunk); }
public Block SetBlock(BlockSnapshot snapshot, Vector3i position, Func <Block, bool> canBeReplaced) { var regionPosition = position >> 6; var chunkPosition = position >> 4; var region = GetChunkRegion(regionPosition); if (region == null) { region = new ChunkRegion(this, regionPosition); region.LoadIfDeleted(); _chunkRegions[regionPosition] = region; } var chunk = region.GetChunkFromChunkPosition(chunkPosition); if (chunk != null) { return(chunk.SetBlockFromWorldPosition(snapshot, position, canBeReplaced)); } _unloadedChunkGenerationManager.AddBlock(position, snapshot, true); return(null); }