- v3s16 blockpos = data->blockpos;
-
- /*dstream<<"makeBlock(): ("<<blockpos.X<<","<<blockpos.Y<<","
- <<blockpos.Z<<")"<<std::endl;*/
-
- ManualMapVoxelManipulator &vmanip = *(data->vmanip);
- v3s16 blockpos_min = blockpos - v3s16(1,1,1);
- v3s16 blockpos_max = blockpos + v3s16(1,1,1);
- // Area of center block
- v3s16 node_min = blockpos*MAP_BLOCKSIZE;
- v3s16 node_max = (blockpos+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);
- // Full allocated area
- v3s16 full_node_min = (blockpos-1)*MAP_BLOCKSIZE;
- v3s16 full_node_max = (blockpos+2)*MAP_BLOCKSIZE-v3s16(1,1,1);
- // Area of a block
- double block_area_nodes = MAP_BLOCKSIZE*MAP_BLOCKSIZE;
-
- v2s16 p2d_center(node_min.X+MAP_BLOCKSIZE/2, node_min.Z+MAP_BLOCKSIZE/2);
-
- /*
- Get average ground level from noise
- */
-
- s16 approx_groundlevel = (s16)get_sector_average_ground_level(
- data->seed, v2s16(blockpos.X, blockpos.Z));
- //dstream<<"approx_groundlevel="<<approx_groundlevel<<std::endl;
-
- s16 approx_ground_depth = approx_groundlevel - (node_min.Y+MAP_BLOCKSIZE/2);
-
- s16 minimum_groundlevel = (s16)get_sector_minimum_ground_level(
- data->seed, v2s16(blockpos.X, blockpos.Z));
- // Minimum amount of ground above the top of the central block
- s16 minimum_ground_depth = minimum_groundlevel - node_max.Y;
-
- s16 maximum_groundlevel = (s16)get_sector_maximum_ground_level(
- data->seed, v2s16(blockpos.X, blockpos.Z), 1);
- // Maximum amount of ground above the bottom of the central block
- s16 maximum_ground_depth = maximum_groundlevel - node_min.Y;
-
- #if 0
- /*
- Special case for high air or water: Just fill with air and water.
- */
- if(maximum_ground_depth < -20)
- {
- for(s16 x=node_min.X; x<=node_max.X; x++)
- for(s16 z=node_min.Z; z<=node_max.Z; z++)
- {
- // Node position
- v2s16 p2d(x,z);
- {
- // Use fast index incrementing
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, node_min.Y, p2d.Y));
- for(s16 y=node_min.Y; y<=node_max.Y; y++)
- {
- // Only modify places that have no content
- if(vmanip.m_data[i].getContent() == CONTENT_IGNORE)
- {
- if(y <= WATER_LEVEL)
- vmanip.m_data[i] = MapNode(CONTENT_WATERSOURCE);
- else
- vmanip.m_data[i] = MapNode(CONTENT_AIR);
- }
-
- data->vmanip->m_area.add_y(em, i, 1);
- }
- }
- }
-
- // We're done
- return;
- }
- #endif
-
- /*
- If block is deep underground, this is set to true and ground
- density noise is not generated, for speed optimization.
- */
- bool all_is_ground_except_caves = (minimum_ground_depth > 40);
-
- /*
- Create a block-specific seed
- */
- u32 blockseed = (u32)(data->seed%0x100000000ULL) + full_node_min.Z*38134234
- + full_node_min.Y*42123 + full_node_min.X*23;
-
- /*
- Make some 3D noise
- */
-
- //NoiseBuffer noisebuf1;
- //NoiseBuffer noisebuf2;
- NoiseBuffer noisebuf_cave;
- NoiseBuffer noisebuf_ground;
- NoiseBuffer noisebuf_ground_crumbleness;
- NoiseBuffer noisebuf_ground_wetness;
- {
- v3f minpos_f(node_min.X, node_min.Y, node_min.Z);
- v3f maxpos_f(node_max.X, node_max.Y, node_max.Z);
-
- //TimeTaker timer("noisebuf.create");
-
- /*
- Cave noise
- */
-#if 1
- noisebuf_cave.create(get_cave_noise1_params(data->seed),
- minpos_f.X, minpos_f.Y, minpos_f.Z,
- maxpos_f.X, maxpos_f.Y, maxpos_f.Z,
- 2, 2, 2);
- noisebuf_cave.multiply(get_cave_noise2_params(data->seed));
-#endif
-
- /*
- Ground noise
- */
-
- // Sample length
- v3f sl = v3f(4.0, 4.0, 4.0);
-
- /*
- Density noise
- */
- if(all_is_ground_except_caves == false)
- //noisebuf_ground.create(data->seed+983240, 6, 0.60, false,
- noisebuf_ground.create(get_ground_noise1_params(data->seed),
- minpos_f.X, minpos_f.Y, minpos_f.Z,
- maxpos_f.X, maxpos_f.Y, maxpos_f.Z,
- sl.X, sl.Y, sl.Z);
-
- /*
- Ground property noise
- */
- sl = v3f(2.5, 2.5, 2.5);
- noisebuf_ground_crumbleness.create(
- get_ground_crumbleness_params(data->seed),
- minpos_f.X, minpos_f.Y, minpos_f.Z,
- maxpos_f.X, maxpos_f.Y+5, maxpos_f.Z,
- sl.X, sl.Y, sl.Z);
- noisebuf_ground_wetness.create(
- get_ground_wetness_params(data->seed),
- minpos_f.X, minpos_f.Y, minpos_f.Z,
- maxpos_f.X, maxpos_f.Y+5, maxpos_f.Z,
- sl.X, sl.Y, sl.Z);
- }
-
- /*
- Make base ground level
- */
-
- for(s16 x=node_min.X; x<=node_max.X; x++)
- for(s16 z=node_min.Z; z<=node_max.Z; z++)
- {
- // Node position
- v2s16 p2d(x,z);
- {
- // Use fast index incrementing
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, node_min.Y, p2d.Y));
- for(s16 y=node_min.Y; y<=node_max.Y; y++)
- {
- // Only modify places that have no content
- if(vmanip.m_data[i].getContent() == CONTENT_IGNORE)
- {
- // First priority: make air and water.
- // This avoids caves inside water.
- if(all_is_ground_except_caves == false
- && val_is_ground(noisebuf_ground.get(x,y,z),
- v3s16(x,y,z), data->seed) == false)
- {
- if(y <= WATER_LEVEL)
- vmanip.m_data[i] = MapNode(CONTENT_WATERSOURCE);
- else
- vmanip.m_data[i] = MapNode(CONTENT_AIR);
- }
- else if(noisebuf_cave.get(x,y,z) > CAVE_NOISE_THRESHOLD)
- vmanip.m_data[i] = MapNode(CONTENT_AIR);
- else
- vmanip.m_data[i] = MapNode(CONTENT_STONE);
- }
-
- data->vmanip->m_area.add_y(em, i, 1);
- }
- }
- }