]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/map.cpp
Translated using Weblate (Korean)
[dragonfireclient.git] / src / map.cpp
index 14a237c0a822688694206de7349db885a7c4ea06..9974ff363a7aa5f520e9df961a45ffecd58a0e0e 100644 (file)
@@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "mapsector.h"
 #include "mapblock.h"
-#include "main.h"
 #include "filesys.h"
 #include "voxel.h"
 #include "porting.h"
@@ -1437,7 +1436,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
 
                                // Save if modified
                                if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading) {
-                                       modprofiler.add(block->getModifiedReason(), 1);
+                                       modprofiler.add(block->getModifiedReasonString(), 1);
                                        if (!saveBlock(block))
                                                continue;
                                        saved_blocks_count++;
@@ -1891,6 +1890,47 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
        }
 }
 
+std::vector<v3s16> Map::findNodesWithMetadata(v3s16 p1, v3s16 p2)
+{
+       std::vector<v3s16> positions_with_meta;
+
+       sortBoxVerticies(p1, p2);
+       v3s16 bpmin = getNodeBlockPos(p1);
+       v3s16 bpmax = getNodeBlockPos(p2);
+
+       VoxelArea area(p1, p2);
+
+       for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
+       for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
+       for (s16 x = bpmin.X; x <= bpmax.X; x++) {
+               v3s16 blockpos(x, y, z);
+
+               MapBlock *block = getBlockNoCreateNoEx(blockpos);
+               if (!block) {
+                       verbosestream << "Map::getNodeMetadata(): Need to emerge "
+                               << PP(blockpos) << std::endl;
+                       block = emergeBlock(blockpos, false);
+               }
+               if (!block) {
+                       infostream << "WARNING: Map::getNodeMetadata(): Block not found"
+                               << std::endl;
+                       continue;
+               }
+
+               v3s16 p_base = blockpos * MAP_BLOCKSIZE;
+               std::vector<v3s16> keys = block->m_node_metadata.getAllKeys();
+               for (size_t i = 0; i != keys.size(); i++) {
+                       v3s16 p(keys[i] + p_base);
+                       if (!area.contains(p))
+                               continue;
+
+                       positions_with_meta.push_back(p);
+               }
+       }
+
+       return positions_with_meta;
+}
+
 NodeMetadata *Map::getNodeMetadata(v3s16 p)
 {
        v3s16 blockpos = getNodeBlockPos(p);
@@ -2372,7 +2412,7 @@ void ServerMap::finishBlockMake(BlockMakeData *data,
                        Set block as modified
                */
                block->raiseModified(MOD_STATE_WRITE_NEEDED,
-                               "finishBlockMake expireDayNightDiff");
+                       MOD_REASON_EXPIRE_DAYNIGHTDIFF);
        }
 
        /*
@@ -2941,7 +2981,7 @@ void ServerMap::save(ModifiedState save_level)
                                        save_started = true;
                                }
 
-                               modprofiler.add(block->getModifiedReason(), 1);
+                               modprofiler.add(block->getModifiedReasonString(), 1);
 
                                saveBlock(block);
                                block_count++;
@@ -3005,26 +3045,20 @@ void ServerMap::saveMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
 
-       /*infostream<<"ServerMap::saveMapMeta(): "
-                       <<"seed="<<m_seed
-                       <<std::endl;*/
-
        createDirs(m_savedir);
 
-       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
-       std::ostringstream ss(std::ios_base::binary);
-
-       Settings params;
+       std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
+       std::ostringstream oss(std::ios_base::binary);
+       Settings conf;
 
-       m_emerge->saveParamsToSettings(&params);
-       params.writeLines(ss);
+       m_emerge->params.save(conf);
+       conf.writeLines(oss);
 
-       ss<<"[end_of_params]\n";
+       oss << "[end_of_params]\n";
 
-       if(!fs::safeWriteToFile(fullpath, ss.str()))
-       {
-               infostream<<"ERROR: ServerMap::saveMapMeta(): "
-                               <<"could not write "<<fullpath<<std::endl;
+       if(!fs::safeWriteToFile(fullpath, oss.str())) {
+               errorstream << "ServerMap::saveMapMeta(): "
+                               << "could not write " << fullpath << std::endl;
                throw FileNotGoodException("Cannot save chunk metadata");
        }
 
@@ -3035,24 +3069,22 @@ void ServerMap::loadMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
 
-       Settings params;
-       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
+       Settings conf;
+       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
 
-       if (fs::PathExists(fullpath)) {
-               std::ifstream is(fullpath.c_str(), std::ios_base::binary);
-               if (!is.good()) {
-                       errorstream << "ServerMap::loadMapMeta(): "
-                               "could not open " << fullpath << std::endl;
-                       throw FileNotGoodException("Cannot open map metadata");
-               }
+       std::ifstream is(fullpath.c_str(), std::ios_base::binary);
+       if (!is.good()) {
+               errorstream << "ServerMap::loadMapMeta(): "
+                       "could not open " << fullpath << std::endl;
+               throw FileNotGoodException("Cannot open map metadata");
+       }
 
-               if (!params.parseConfigLines(is, "[end_of_params]")) {
-                       throw SerializationError("ServerMap::loadMapMeta(): "
+       if (!conf.parseConfigLines(is, "[end_of_params]")) {
+               throw SerializationError("ServerMap::loadMapMeta(): "
                                "[end_of_params] not found!");
-               }
        }
 
-       m_emerge->loadParamsFromSettings(&params);
+       m_emerge->params.load(conf);
 
        verbosestream << "ServerMap::loadMapMeta(): seed="
                << m_emerge->params.seed << std::endl;