public void generateChunk(BlockPos pos, bool redraw) { var chunkPos = pos.ChunkPos(); if (_chunks.ContainsKey(chunkPos)) { return; } var chunk = new Chunk(chunkPos); var data = new ChunkData(chunk, new ChunkModel()); _chunks.TryAdd(chunkPos, data); for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { var X = (x + chunkPos.x) / 1.25f; var Y = (z + chunkPos.z) / 1.25f; int peakY = 32 + (int)Math.Abs(MathHelper.Clamp(0.35f + noise.GetPerlinFractal(X, Y), 0, 1) * 30); for (int y = peakY; y >= 0; y--) { var p = new BlockPos(x, y, z); if (y == peakY) { chunk.setBlock(p, EnumBlock.GRASS, 0); } else if (y > 0 && peakY - y > 0 && peakY - y < 3) // for 2 blocks { chunk.setBlock(p, EnumBlock.DIRT, 0); } else if (y == 0) { chunk.setBlock(p, EnumBlock.BEDROCK, 0); } else { var f = 0.35f + noise.GetNoise(X * 32 - y * 16, Y * 32 + x * 16); chunk.setBlock(p, f >= 0.75f ? EnumBlock.RARE : EnumBlock.STONE, 0); } } } } if (redraw) { updateModelForChunk(chunkPos); } markNeighbourChunksForUpdate(chunk, chunk.chunkPos); data.chunkGenerated = true; /* var sides = (EnumFacing[]) Enum.GetValues(typeof(EnumFacing)); * * for (var index = 0; index < sides.Length - 2; index++) * { * var side = sides[index]; * * var vec = new BlockPos().offset(side).vector; * var offset = new BlockPos(vec * 16); * * var c = getChunkFromPos(offset + chunkPos); * * if (c != null) * updateModelForChunk(c.chunkPos); * }*/ }
public bool doesChunkHaveModel(BlockPos pos) { return(_chunks[pos.ChunkPos()].modelGenerated); }
public bool isBlockAbove(BlockPos pos) { var chunk = getChunkFromPos(pos); return(chunk.isBlockAbove(this, pos - chunk.chunkPos)); }