- INodeDefManager *nodemgr = m_gamedef->ndef();
-
- // Whether the sunlight at the top of the bottom block is valid
- bool block_below_is_valid = true;
-
- v3s16 pos_relative = getPosRelative();
-
- for(s16 x=0; x<MAP_BLOCKSIZE; x++)
- {
- for(s16 z=0; z<MAP_BLOCKSIZE; z++)
- {
-#if 1
- bool no_sunlight = false;
- //bool no_top_block = false;
-
- // Check if node above block has sunlight
-
- bool is_valid_position;
- MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z),
- &is_valid_position);
- if (is_valid_position)
- {
- if(n.getContent() == CONTENT_IGNORE)
- {
- // Trust heuristics
- no_sunlight = is_underground;
- }
- else if(n.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) != LIGHT_SUN)
- {
- no_sunlight = true;
- }
- }
- else
- {
- //no_top_block = true;
-
- // NOTE: This makes over-ground roofed places sunlighted
- // Assume sunlight, unless is_underground==true
- if(is_underground)
- {
- no_sunlight = true;
- }
- else
- {
- MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
- if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
- {
- no_sunlight = true;
- }
- }
- // NOTE: As of now, this just would make everything dark.
- // No sunlight here
- //no_sunlight = true;
- }
-#endif
-#if 0 // Doesn't work; nothing gets light.
- bool no_sunlight = true;
- bool no_top_block = false;
- // Check if node above block has sunlight
- try{
- MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z));
- if(n.getLight(LIGHTBANK_DAY) == LIGHT_SUN)
- {
- no_sunlight = false;
- }
- }
- catch(InvalidPositionException &e)
- {
- no_top_block = true;
- }
-#endif
-
- /*std::cout<<"("<<x<<","<<z<<"): "
- <<"no_top_block="<<no_top_block
- <<", is_underground="<<is_underground
- <<", no_sunlight="<<no_sunlight
- <<std::endl;*/
-
- s16 y = MAP_BLOCKSIZE-1;
-
- // This makes difference to diminishing in water.
- bool stopped_to_solid_object = false;
-
- u8 current_light = no_sunlight ? 0 : LIGHT_SUN;
-
- for(; y >= 0; y--)
- {
- v3s16 pos(x, y, z);
- MapNode &n = getNodeRef(pos);
-
- if(current_light == 0)
- {
- // Do nothing
- }
- else if(current_light == LIGHT_SUN && nodemgr->get(n).sunlight_propagates)
- {
- // Do nothing: Sunlight is continued
- }
- else if(nodemgr->get(n).light_propagates == false)
- {
- // A solid object is on the way.
- stopped_to_solid_object = true;
-
- // Light stops.
- current_light = 0;
- }
- else
- {
- // Diminish light
- current_light = diminish_light(current_light);
- }
-
- u8 old_light = n.getLight(LIGHTBANK_DAY, nodemgr);
-
- if(current_light > old_light || remove_light)
- {
- n.setLight(LIGHTBANK_DAY, current_light, nodemgr);
- }
-
- if(diminish_light(current_light) != 0)
- {
- light_sources.insert(pos_relative + pos);
- }
-
- if(current_light == 0 && stopped_to_solid_object)
- {
- if(black_air_left)
- {
- *black_air_left = true;
- }
- }
- }
-
- // Whether or not the block below should see LIGHT_SUN
- bool sunlight_should_go_down = (current_light == LIGHT_SUN);