public ChunkData(Vector2Int position) { this.position = position * World.ChunkSize; blockDatas = new BlockData[World.ChunkSize, World.HeightInBlocks, World.ChunkSize]; for (int x = 0; x < blockDatas.GetLength(0); x++) { for (int y = 0; y < blockDatas.GetLength(1); y++) { for (int z = 0; z < blockDatas.GetLength(2); z++) { blockDatas[x, y, z] = World.GenerateBlock(new Vector3Int((position.x * World.ChunkSize) + x, y, (position.y * World.ChunkSize) + z)); } } } }
/// <summary> /// Returns the passed BlockType array with the passed PlanetStratum layered onto it. /// </summary> /// <param name="noise">Noise used to calculate stratum blocks</param> /// <param name="stratum">PlanetStratum to generate blocks from</param> /// <param name="planet">BlockType array to layer onto</param> /// <param name="padding">How much padding on outsides to leave</param> /// <returns>BlockType Array with PlanetStratum layer added</returns> static BlockData[,,] LayerStratumOnPlanet(FastNoise noise, PlanetStratum stratum, BlockData[,,] planet, int padding) { BlockData[,,] layeredPlanet = planet; int planetSize = planet.GetLength(0); int innerBound = padding + stratum.size; int outerBound = planetSize - innerBound; for (int x = padding; x < planetSize - padding; x++) { for (int y = padding; y < planetSize - padding; y++) { for (int z = padding; z < planetSize - padding; z++) { if (planet[x, y, z] == null) { BlockData data = CalculateBlockFromPlanetStratum(noise, stratum, x, y, z); layeredPlanet[x, y, z] = data; } } } } return(layeredPlanet); }
public void GenerateBlocks() { for (int i = 0; i < chunkData.GetLength(0); i++) { for (int k = 0; k < chunkData.GetLength(2); k++) { //int localHeight = PerlinHeight(i, k, this, height); int localHeight = ImprovedPerlinHeight(i + offsetX, k + offsetY, this, 16); for (int j = 0; j < localHeight; j++) { int chance = Random.Range(1, 2); if (chance == 1) { chunkData[i, j, k] = new Block_Generic(); } else { chunkData[i, j, k] = new Block_Torch(); } } } } }
public void RecalculateBlockNavigation(int bx, int by, int bz, BlockData[,,] blocks, RVector3 chunkOffset) { var block = blocks[bx, by, bz]; if (block.BlockType == 0 && block.ObjectDataData == null) { var position = new RVector3(bx + chunkOffset.x, by + chunkOffset.y, bz + chunkOffset.z); var blockOnBottomIsAir = by == 0 || blocks[bx, by - 1, bz].BlockType == 0 && blocks[bx, by - 1, bz].ObjectDataData == null; var blockOnTopIsAir = by == (blocks.GetLength(2) - 1) || blocks[bx, by + 1, bz].BlockType == 0; if (!blockOnBottomIsAir && blockOnTopIsAir) { SetNavigablePoint(position); } } }