public NoiseGeneratorOctaves2(JavaRandom random, int i) { field_4233_b = i; field_4234_a = new NoiseGenerator2[i]; for (int j = 0; j < i; j++) { field_4234_a[j] = new NoiseGenerator2(random); } }
public void SetupLandscape() { Random random = new Random(); int W = (int)Dim * (int)Scale; int H = (int)Dim * (int)Scale; float[,] heightmap = new float[W, H]; // create heightmap from nosie for (int x = (int)WorldPosition.X; x < (int)WorldPosition.X + Dim * Scale; x += (int)Scale) { for (int z = (int)WorldPosition.Z; z < (int)WorldPosition.Z + Dim * Scale; z += (int)Scale) { Vector2 voxIndex = WorldToChunkXZ(x, z); int X = (int)voxIndex.X; int Z = (int)voxIndex.Y; float height = ((float)NoiseGenerator.Noise(Math.Abs(x), Math.Abs(z)) + 1f) * 0.5f + ((float)NoiseGenerator2.Noise(Math.Abs(x), Math.Abs(z)) + 1f) * 0.25f; heightmap[X, Z] = height; } } // find max noise value foreach (float h in heightmap) { if (h > max) { max = h; } } // normalize to 0 - 1 for (int x = (int)WorldPosition.X; x < (int)WorldPosition.X + Dim * Scale; x += (int)Scale) { for (int z = (int)WorldPosition.Z; z < (int)WorldPosition.Z + Dim * Scale; z += (int)Scale) { Vector2 voxIndex = WorldToChunkXZ(x, z); int X = (int)voxIndex.X; int Z = (int)voxIndex.Y; heightmap[X, Z] /= max; } } for (int x = (int)WorldPosition.X; x < (int)WorldPosition.X + Dim * Scale; x += (int)Scale) { for (int z = (int)WorldPosition.Z; z < (int)WorldPosition.Z + Dim * Scale; z += (int)Scale) { /* * float height = ((float)NoiseGenerator.Noise(Math.Abs(x), Math.Abs(z)) + 1f)*0.5f + * ((float)NoiseGenerator2.Noise(Math.Abs(x), Math.Abs(z)) + 1f)*0.15f; * if (height > 1.0) height /= 2.0f; */ Vector2 voxIndex = WorldToChunkXZ(x, z); int X = (int)voxIndex.X; int Z = (int)voxIndex.Y; float height = heightmap[X, Z]; height *= (float)Dim; for (int y = 0; y < (int)height; y++) { Blocks[(int)voxIndex.X, y, (int)voxIndex.Y].IsActive = true; if (y > 26 * height / 30) { Blocks[X, y, Z].BlockType = BlockType.GRASS; } else if (y <= 26 * height / 30 && y > 18 * height / 30) { Blocks[X, y, Z].BlockType = BlockType.DIRT; } else { Blocks[X, y, Z].BlockType = BlockType.STONE; } } } } Build(); }