private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null) { Dictionary <Vec3i, int> ores = new Dictionary <Vec3i, int>(); for (int cY = 0; cY < chunks.Length; cY++) { IServerChunk chunk = chunks[cY]; if (chunk.Blocks == null) { continue; } for (int x = 0; x < chunksize; x++) { for (int y = 0; y < chunksize; y++) { for (int z = 0; z < chunksize; z++) { int block = chunk.Blocks[(y * chunksize + z) * chunksize + x]; if (surfaceBlocks.ContainsKey(block) && !ores.ContainsKey(new Vec3i(x, y, z))) { ores.Add(new Vec3i(x, y, z), block); } } } } foreach (var val in ores) { Vec3i vec = val.Key; int ore = val.Value; if (surfaceBlocks.TryGetValue(ore, out int surface)) { for (int y = vec.Y; y < chunksize; y++) { rnd.InitPositionSeed(chunkX * vec.X, chunkZ * vec.Z); if (y < 1 || rnd.NextDouble() > 0.1) { continue; } int dX = rnd.NextInt(chunksize), dZ = rnd.NextInt(chunksize); int block = chunk.Blocks[(y * chunksize + dZ) * chunksize + dX]; int dBlock = chunk.Blocks[((y - 1) * chunksize + dZ) * chunksize + dX]; if (bA.GetBlock(dBlock).Fertility > 4 && bA.GetBlock(block).IsReplacableBy(bA.GetBlock(ore)) && !bA.GetBlock(block).IsLiquid()) { chunk.Blocks[(y * chunksize + dZ) * chunksize + dX] = surface; bA.ScheduleBlockUpdate(new BlockPos(dX, y, dZ)); } } } } } }
private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null) { ushort[] heightMap = chunks[0].MapChunk.RainHeightMap; int regionChunkSize = Api.WorldManager.RegionSize / chunksize; int rdx = chunkX % regionChunkSize; int rdz = chunkZ % regionChunkSize; for (int x = 0; x < chunksize; x++) { for (int z = 0; z < chunksize; z++) { double noise = sNoise.Noise(chunkX * chunksize + x, chunkZ * chunksize + z); int y = heightMap[z * chunksize + x]; int chunkY = y / chunksize; int lY = y % chunksize; int index3d = (chunksize * lY + z) * chunksize + x; int bID = chunks[chunkY].Blocks[index3d]; if (bID == 0 || bA.GetBlock(bID).LiquidCode != null) { continue; } int tY = heightMap[z * chunksize + x] + 1; int tChunkY = tY / chunksize; int tlY = tY % chunksize; int tIndex3d = (chunksize * tlY + z) * chunksize + x; int rockID = chunks[0].MapChunk.TopRockIdMap[z * chunksize + x]; string rock = bA.GetBlock(rockID).Variant["rock"]; rand.InitPositionSeed(rdx + x, rdz + z); var deposits = Deposits.Shuffle(rand); for (int i = 0; i < Deposits.Length; i++) { double dnoise = sNoise.Noise(rdx + x + i + 4987, rdz + z + i + 15654); if (dnoise > 0.9) { continue; } DepositVariant variant = Deposits[i]; if (!variant.WithOreMap) { continue; } float factor = variant.GetOreMapFactor(chunkX, chunkZ); factor *= (float)genProperties.GlobalMult; if (factor > 0 && factor > noise) { int?placed = bA.GetBlock(new AssetLocation(variant.Attributes.Token["placeblock"]["code"].ToString().Replace("{rock}", rock).Replace("*", "poor")))?.Id; if (placed == null || !surfaceBlocks.ContainsKey((int)placed)) { continue; } chunks[tChunkY].Blocks[tIndex3d] = surfaceBlocks[(int)placed]; chunks[tChunkY].MarkModified(); break; } } } } }