+ /*
+ Add minerals
+ */
+
+ {
+ PseudoRandom mineralrandom(blockseed);
+
+ /*
+ Add meseblocks
+ */
+ for(s16 i=0; i<approx_ground_depth/4; i++)
+ {
+ if(mineralrandom.next()%50 == 0)
+ {
+ s16 x = mineralrandom.range(node_min.X+1, node_max.X-1);
+ s16 y = mineralrandom.range(node_min.Y+1, node_max.Y-1);
+ s16 z = mineralrandom.range(node_min.Z+1, node_max.Z-1);
+ for(u16 i=0; i<27; i++)
+ {
+ v3s16 p = v3s16(x,y,z) + g_27dirs[i];
+ u32 vi = vmanip.m_area.index(p);
+ if(vmanip.m_data[vi].getContent() == c_stone)
+ if(mineralrandom.next()%8 == 0)
+ vmanip.m_data[vi] = MapNode(c_mese);
+ }
+
+ }
+ }
+ /*
+ Add others
+ */
+ {
+ u16 a = mineralrandom.range(0,15);
+ a = a*a*a;
+ u16 amount = 20 * a/1000;
+ for(s16 i=0; i<amount; i++)
+ {
+ s16 x = mineralrandom.range(node_min.X+1, node_max.X-1);
+ s16 y = mineralrandom.range(node_min.Y+1, node_max.Y-1);
+ s16 z = mineralrandom.range(node_min.Z+1, node_max.Z-1);
+
+ u8 base_content = c_stone;
+ MapNode new_content(CONTENT_IGNORE);
+ u32 sparseness = 6;
+
+ if(noisebuf_ground_crumbleness.get(x,y+5,z) < -0.1)
+ {
+ new_content = MapNode(c_stone_with_coal);
+ }
+ else
+ {
+ if(noisebuf_ground_wetness.get(x,y+5,z) > 0.0)
+ new_content = MapNode(c_stone_with_iron);
+ /*if(noisebuf_ground_wetness.get(x,y,z) > 0.0)
+ vmanip.m_data[i] = MapNode(c_dirt);
+ else
+ vmanip.m_data[i] = MapNode(c_sand);*/
+ }
+ /*else if(noisebuf_ground_crumbleness.get(x,y,z) > 0.1)
+ {
+ }*/
+
+ if(new_content.getContent() != CONTENT_IGNORE)
+ {
+ for(u16 i=0; i<27; i++)
+ {
+ v3s16 p = v3s16(x,y,z) + g_27dirs[i];
+ u32 vi = vmanip.m_area.index(p);
+ if(vmanip.m_data[vi].getContent() == base_content)
+ {
+ if(mineralrandom.next()%sparseness == 0)
+ vmanip.m_data[vi] = new_content;
+ }
+ }
+ }
+ }
+ }
+ /*
+ Add coal
+ */
+ //for(s16 i=0; i < MYMAX(0, 50 - abs(node_min.Y+8 - (-30))); i++)
+ //for(s16 i=0; i<50; i++)
+ u16 coal_amount = 30;
+ u16 coal_rareness = 60 / coal_amount;
+ if(coal_rareness == 0)
+ coal_rareness = 1;
+ if(mineralrandom.next()%coal_rareness == 0)
+ {
+ u16 a = mineralrandom.next() % 16;
+ u16 amount = coal_amount * a*a*a / 1000;
+ for(s16 i=0; i<amount; i++)
+ {
+ s16 x = mineralrandom.range(node_min.X+1, node_max.X-1);
+ s16 y = mineralrandom.range(node_min.Y+1, node_max.Y-1);
+ s16 z = mineralrandom.range(node_min.Z+1, node_max.Z-1);
+ for(u16 i=0; i<27; i++)
+ {
+ v3s16 p = v3s16(x,y,z) + g_27dirs[i];
+ u32 vi = vmanip.m_area.index(p);
+ if(vmanip.m_data[vi].getContent() == c_stone)
+ if(mineralrandom.next()%8 == 0)
+ vmanip.m_data[vi] = MapNode(c_stone_with_coal);
+ }
+ }
+ }
+ /*
+ Add iron
+ */
+ u16 iron_amount = 8;
+ u16 iron_rareness = 60 / iron_amount;
+ if(iron_rareness == 0)
+ iron_rareness = 1;
+ if(mineralrandom.next()%iron_rareness == 0)
+ {
+ u16 a = mineralrandom.next() % 16;
+ u16 amount = iron_amount * a*a*a / 1000;
+ for(s16 i=0; i<amount; i++)
+ {
+ s16 x = mineralrandom.range(node_min.X+1, node_max.X-1);
+ s16 y = mineralrandom.range(node_min.Y+1, node_max.Y-1);
+ s16 z = mineralrandom.range(node_min.Z+1, node_max.Z-1);
+ for(u16 i=0; i<27; i++)
+ {
+ v3s16 p = v3s16(x,y,z) + g_27dirs[i];
+ u32 vi = vmanip.m_area.index(p);
+ if(vmanip.m_data[vi].getContent() == c_stone)
+ if(mineralrandom.next()%8 == 0)
+ vmanip.m_data[vi] = MapNode(c_stone_with_iron);
+ }
+ }
+ }
+ }
+#endif
+
+ /*
+ Calculate lighting
+ */
+ {
+ ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update",
+ SPT_AVG);
+ //VoxelArea a(node_min, node_max);
+ VoxelArea a(node_min-v3s16(1,0,1)*MAP_BLOCKSIZE,
+ node_max+v3s16(1,0,1)*MAP_BLOCKSIZE);
+ /*VoxelArea a(node_min-v3s16(1,0,1)*MAP_BLOCKSIZE/2,
+ node_max+v3s16(1,0,1)*MAP_BLOCKSIZE/2);*/
+ enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT};
+ for(int i=0; i<2; i++)
+ {
+ enum LightBank bank = banks[i];
+
+ core::map<v3s16, bool> light_sources;
+ core::map<v3s16, u8> unlight_from;
+
+ voxalgo::clearLightAndCollectSources(vmanip, a, bank, ndef,
+ light_sources, unlight_from);
+
+ bool inexistent_top_provides_sunlight = !block_is_underground;
+ voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
+ vmanip, a, inexistent_top_provides_sunlight,
+ light_sources, ndef);
+ // TODO: Do stuff according to bottom_sunlight_valid
+
+ vmanip.unspreadLight(bank, unlight_from, light_sources, ndef);
+
+ vmanip.spreadLight(bank, light_sources, ndef);
+ }
+ }