Fix chest not working after walked away and came back
authorPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 22:04:22 +0000 (01:04 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 22:04:22 +0000 (01:04 +0300)
src/map.cpp
src/map.h

index 2d661a52213d002023e96619f3cdc771dc54b069..63c6ad57c9035db8198c5bfd9a026c38ff195ce7 100644 (file)
@@ -35,6 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "log.h"
 
+#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
+
 /*
        SQLite format specification:
        - Initially only replaces sectors/ and sectors2/
@@ -1819,9 +1821,14 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p)
        v3s16 blockpos = getNodeBlockPos(p);
        v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
        MapBlock *block = getBlockNoCreateNoEx(blockpos);
-       if(block == NULL)
+       if(!block){
+               infostream<<"Map::getNodeMetadata(): Need to emerge "
+                               <<PP(blockpos)<<std::endl;
+               block = emergeBlock(blockpos, false);
+       }
+       if(!block)
        {
-               infostream<<"WARNING: Map::setNodeMetadata(): Block not found"
+               infostream<<"WARNING: Map::getNodeMetadata(): Block not found"
                                <<std::endl;
                return NULL;
        }
@@ -1834,7 +1841,12 @@ void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
        v3s16 blockpos = getNodeBlockPos(p);
        v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
        MapBlock *block = getBlockNoCreateNoEx(blockpos);
-       if(block == NULL)
+       if(!block){
+               infostream<<"Map::setNodeMetadata(): Need to emerge "
+                               <<PP(blockpos)<<std::endl;
+               block = emergeBlock(blockpos, false);
+       }
+       if(!block)
        {
                infostream<<"WARNING: Map::setNodeMetadata(): Block not found"
                                <<std::endl;
index b58ba047be1a0aace8b92162ec6bb35f239f5d4f..64a69cfd4cba866f2f4af72415d1c0149705930e 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -157,6 +157,10 @@ public:
        // Returns NULL if not found
        MapBlock * getBlockNoCreateNoEx(v3s16 p);
        
+       /* Server overrides */
+       virtual MapBlock * emergeBlock(v3s16 p, bool allow_generate=true)
+       { return getBlockNoCreateNoEx(p); }
+
        // Returns InvalidPositionException if not found
        bool isNodeUnderground(v3s16 p);