]> git.lizzy.rs Git - minetest.git/blobdiff - src/map.cpp
+ papyrus
[minetest.git] / src / map.cpp
index cd2ba9154eadac0202782697b47cf2ff5052ce92..fc674d263642bf05e2627cd6f5e13e2cedbf5e9e 100644 (file)
@@ -607,13 +607,13 @@ s16 Map::propagateSunlight(v3s16 start,
                }
                else
                {
-                       // Turn mud into grass
+                       /*// Turn mud into grass
                        if(n.d == CONTENT_MUD)
                        {
                                n.d = CONTENT_GRASS;
                                block->setNode(relpos, n);
                                modified_blocks.insert(blockpos, block);
-                       }
+                       }*/
 
                        // Sunlight goes no further
                        break;
@@ -838,9 +838,6 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
 }
 
 /*
-       This is called after changing a node from transparent to opaque.
-       The lighting value of the node should be left as-is after changing
-       other values. This sets the lighting value to 0.
 */
 void Map::addNodeAndUpdate(v3s16 p, MapNode n,
                core::map<v3s16, MapBlock*> &modified_blocks)
@@ -877,12 +874,12 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        catch(InvalidPositionException &e)
        {
        }
-       
+
+#if 1
        /*
-               If the new node doesn't propagate sunlight and there is
-               grass below, change it to mud
+               If the new node is solid and there is grass below, change it to mud
        */
-       if(content_features(n.d).sunlight_propagates == false)
+       if(content_features(n.d).walkable == true)
        {
                try{
                        MapNode bottomnode = getNode(bottompos);
@@ -898,7 +895,9 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
                {
                }
        }
+#endif
 
+#if 0
        /*
                If the new node is mud and it is under sunlight, change it
                to grass
@@ -907,6 +906,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        {
                n.d = CONTENT_GRASS;
        }
+#endif
 
        /*
                Remove all light that has come out of this node
@@ -2045,6 +2045,34 @@ void make_tree(VoxelManipulator &vmanip, v3s16 p0)
        }
 }
 
+void make_papyrus(VoxelManipulator &vmanip, v3s16 p0)
+{
+       MapNode papyrusnode(CONTENT_PAPYRUS);
+
+       s16 trunk_h = myrand_range(2, 3);
+       v3s16 p1 = p0;
+       for(s16 ii=0; ii<trunk_h; ii++)
+       {
+               if(vmanip.m_area.contains(p1))
+                       vmanip.m_data[vmanip.m_area.index(p1)] = papyrusnode;
+               p1.Y++;
+       }
+}
+
+void make_cactus(VoxelManipulator &vmanip, v3s16 p0)
+{
+       MapNode cactusnode(CONTENT_CACTUS);
+
+       s16 trunk_h = 3;
+       v3s16 p1 = p0;
+       for(s16 ii=0; ii<trunk_h; ii++)
+       {
+               if(vmanip.m_area.contains(p1))
+                       vmanip.m_data[vmanip.m_area.index(p1)] = cactusnode;
+               p1.Y++;
+       }
+}
+
 /*
        Noise functions. Make sure seed is mangled differently in each one.
 */
@@ -3127,6 +3155,13 @@ void makeChunk(ChunkMakeData *data)
                if(have_sand == false)
                        continue;
 
+               // Determine whether to have clay in the sand here
+               double claynoise = noise2d_perlin(
+                               0.5+(float)p2d.X/500, 0.5+(float)p2d.Y/500,
+                               data->seed+4321, 6, 0.95);
+
+               bool have_clay = have_sand && (claynoise > 1.25);
+
                // Find ground level
                s16 surface_y = find_ground_level_clever(data->vmanip, p2d);
                
@@ -3143,7 +3178,10 @@ void makeChunk(ChunkMakeData *data)
                                MapNode *n = &data->vmanip.m_data[i];
                                if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS)
                                {
-                                       n->d = CONTENT_SAND;
+                                       if(have_clay && (surface_y == WATER_LEVEL))
+                                               n->d = CONTENT_CLAY;
+                                       else
+                                               n->d = CONTENT_SAND;
                                }
                                else
                                {
@@ -3201,24 +3239,39 @@ void makeChunk(ChunkMakeData *data)
                                s16 z = myrand_range(p2d_min.Y, p2d_max.Y);
                                s16 y = find_ground_level(data->vmanip, v2s16(x,z));
                                // Don't make a tree under water level
-                               if(y < WATER_LEVEL)
+                               if(y < WATER_LEVEL - 1)
                                        continue;
                                // Don't make a tree so high that it doesn't fit
                                if(y > y_nodes_max - 6)
                                        continue;
                                v3s16 p(x,y,z);
-                               /*
-                                       Trees grow only on mud and grass
-                               */
                                {
                                        u32 i = data->vmanip.m_area.index(v3s16(p));
                                        MapNode *n = &data->vmanip.m_data[i];
-                                       if(n->d != CONTENT_MUD && n->d != CONTENT_GRASS)
+                                       if(n->d != CONTENT_MUD && n->d != CONTENT_GRASS && n->d != CONTENT_SAND)
                                                continue;
+                                       // Papyrus grows only on mud and in water
+                                       if(n->d == CONTENT_MUD && y == WATER_LEVEL - 1)
+                                       {
+                                               p.Y++;
+                                               make_papyrus(data->vmanip, p);
+                                       }
+                                       // Don't make a tree under water level
+                                       if(y < WATER_LEVEL)
+                                               continue;
+                                       // Trees grow only on mud and grass
+                                       if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS)
+                                       {
+                                               p.Y++;
+                                               make_tree(data->vmanip, p);
+                                       }
+                                       // Cactii grow only on sand
+                                       else if(n->d == CONTENT_SAND)
+                                       {
+                                               p.Y++;
+                                               make_cactus(data->vmanip, p);
+                                       }
                                }
-                               p.Y++;
-                               // Make a tree
-                               make_tree(data->vmanip, p);
                        }
                }
                /*u32 tree_max = relative_area / 60;
@@ -3586,7 +3639,18 @@ void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
                        sectorpos_base - v2s16(1,1) * max_spread_amount_sectors;
        s16 sectorpos_bigbase_size =
                        sectorpos_base_size + 2 * max_spread_amount_sectors;
-                       
+       
+       // Check limits
+       const s16 limit = MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+       if(sectorpos_bigbase.X < -limit
+       || sectorpos_bigbase.X + sectorpos_bigbase_size >= limit
+       || sectorpos_bigbase.Y < -limit
+       || sectorpos_bigbase.Y + sectorpos_bigbase_size >= limit)
+       {
+               data.no_op = true;
+               return;
+       }
+
        data.seed = m_seed;
        data.chunkpos = chunkpos;
        data.y_blocks_min = y_blocks_min;
@@ -5452,25 +5516,13 @@ void ServerMap::saveBlock(MapBlock *block)
        */
        o.write((char*)&version, 1);
        
+       // Write basic data
        block->serialize(o, version);
-
-       /*
-               Versions up from 9 have block objects.
-       */
-       if(version >= 9)
-       {
-               block->serializeObjects(o, version);
-       }
        
-       /*
-               Versions up from 15 have static objects.
-       */
-       if(version >= 15)
-       {
-               block->m_static_objects.serialize(o);
-       }
-       
-       // We just wrote it to the disk
+       // Write extra data stored on disk
+       block->serializeDiskExtra(o, version);
+
+       // We just wrote it to the disk so clear modified flag
        block->resetChangedFlag();
 }
 
@@ -5515,33 +5567,20 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
                        created_new = true;
                }
                
-               // deserialize block data
+               // Read basic data
                block->deSerialize(is, version);
-               
-               /*
-                       Versions up from 9 have block objects.
-               */
-               if(version >= 9)
-               {
-                       block->updateObjects(is, version, NULL, 0);
-               }
 
-               /*
-                       Versions up from 15 have static objects.
-               */
-               if(version >= 15)
-               {
-                       block->m_static_objects.deSerialize(is);
-               }
+               // Read extra data stored on disk
+               block->deSerializeDiskExtra(is, version);
                
+               // If it's a new block, insert it to the map
                if(created_new)
                        sector->insertBlock(block);
                
                /*
-                       Convert old formats to new and save
+                       Save blocks loaded in old format in new format
                */
 
-               // Save old format blocks in new format
                if(version < SER_FMT_VER_HIGHEST || save_after_load)
                {
                        saveBlock(block);