Fixed/extended/modified ban stuff to be good for inclusion
[oweals/minetest.git] / src / mapblockobject.cpp
index 985a01dc160ad4d813b60b21bfffedfc96b86771..071a14b0cdb3b497d586f057fb6a1503377b0f20 100644 (file)
@@ -1,11 +1,31 @@
 /*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+// This file contains the DEPRECATED MapBlockObject system
+
 #include "mapblockobject.h"
 #include "mapblock.h"
-// Only for ::getNodeBox, TODO: Get rid of this
+// For object wrapping
 #include "map.h"
+#include "inventory.h"
+#include "utility.h"
+#include "mapblock.h"
 
 /*
        MapBlockObject
@@ -18,7 +38,7 @@ v3f MapBlockObject::getAbsolutePos()
                return m_pos;
        
        // getPosRelative gets nodepos relative to map origin
-       v3f blockpos = intToFloat(m_block->getPosRelative());
+       v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
        return blockpos + m_pos;
 }
 
@@ -31,11 +51,30 @@ void MapBlockObject::setBlockChanged()
 /*
        MovingObject
 */
-void MovingObject::move(float dtime, v3f acceleration)
+
+v3f MovingObject::getAbsoluteShowPos()
 {
-       //m_pos += dtime * 3.0;
+       if(m_block == NULL)
+               return m_pos;
+       
+       // getPosRelative gets nodepos relative to map origin
+       v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
+       return blockpos + m_showpos;
+}
 
-       v3s16 oldpos_i = floatToInt(m_pos);
+void MovingObject::move(float dtime, v3f acceleration)
+{
+       DSTACKF("%s: typeid=%i, pos=(%f,%f,%f), speed=(%f,%f,%f)"
+                       ", dtime=%f, acc=(%f,%f,%f)",
+                       __FUNCTION_NAME,
+                       getTypeId(),
+                       m_pos.X, m_pos.Y, m_pos.Z,
+                       m_speed.X, m_speed.Y, m_speed.Z,
+                       dtime,
+                       acceleration.X, acceleration.Y, acceleration.Z
+                       );
+       
+       v3s16 oldpos_i = floatToInt(m_pos, BS);
        
        if(m_block->isValidPosition(oldpos_i) == false)
        {
@@ -50,6 +89,16 @@ void MovingObject::move(float dtime, v3f acceleration)
                m_pos += m_speed * dtime;
                return;
        }
+       
+       // Set insane speed to zero
+       // Otherwise there will be divides by zero and other silly stuff
+       if(m_speed.getLength() > 1000.0*BS)
+               m_speed = v3f(0,0,0);
+               
+       // Limit speed to a reasonable value
+       float speed_limit = 20.0*BS;
+       if(m_speed.getLength() > speed_limit)
+               m_speed = m_speed * (speed_limit / m_speed.getLength());
 
        v3f position = m_pos;
        v3f oldpos = position;
@@ -64,7 +113,7 @@ void MovingObject::move(float dtime, v3f acceleration)
        float speedlength = m_speed.getLength();
        f32 dtime_max_increment;
        if(fabs(speedlength) > 0.001)
-               dtime_max_increment = 0.1*BS / speedlength;
+               dtime_max_increment = 0.05*BS / speedlength;
        else
                dtime_max_increment = 0.5;
        
@@ -91,7 +140,7 @@ void MovingObject::move(float dtime, v3f acceleration)
                        Collision detection
                */
                
-               v3s16 pos_i = floatToInt(position);
+               v3s16 pos_i = floatToInt(position, BS);
                
                // The loop length is limited to the object moving a distance
                f32 d = (float)BS * 0.15;
@@ -112,20 +161,19 @@ void MovingObject::move(float dtime, v3f acceleration)
                for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
                {
                        try{
-                               if(m_block->getNodeParent(v3s16(x,y,z)).d == MATERIAL_AIR){
+                               MapNode n = m_block->getNodeParent(v3s16(x,y,z));
+                               if(content_features(n).walkable == false)
                                        continue;
-                               }
                        }
                        catch(InvalidPositionException &e)
                        {
-                               // Doing nothing here will block the player from
+                               // Doing nothing here will block the object from
                                // walking over map borders
                        }
 
-                       core::aabbox3d<f32> nodebox = Map::getNodeBox(
-                                       v3s16(x,y,z));
+                       core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
                        
-                       // See if the player is touching ground
+                       // See if the object is touching ground
                        if(
                                        fabs(nodebox.MaxEdge.Y-objectbox.MinEdge.Y) < d
                                        && nodebox.MaxEdge.X-d > objectbox.MinEdge.X
@@ -194,6 +242,217 @@ void MovingObject::move(float dtime, v3f acceleration)
        m_pos = position;
 }
 
+void MovingObject::simpleMove(float dtime)
+{
+       m_pos_animation_time_counter += dtime;
+       m_pos_animation_counter += dtime;
+       v3f movevector = m_pos - m_oldpos;
+       f32 moveratio;
+       if(m_pos_animation_time < 0.001)
+               moveratio = 1.0;
+       else
+               moveratio = m_pos_animation_counter / m_pos_animation_time;
+       if(moveratio > 1.5)
+               moveratio = 1.5;
+       m_showpos = m_oldpos + movevector * moveratio;
+}
+
+#ifndef SERVER
+/*
+       RatObject
+*/
+void RatObject::addToScene(scene::ISceneManager *smgr)
+{
+       if(m_node != NULL)
+               return;
+       
+       video::IVideoDriver* driver = smgr->getVideoDriver();
+       
+       scene::SMesh *mesh = new scene::SMesh();
+       scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+       video::SColor c(255,255,255,255);
+       video::S3DVertex vertices[4] =
+       {
+               video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
+               video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
+               video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
+               video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
+       };
+       u16 indices[] = {0,1,2,2,3,0};
+       buf->append(vertices, 4, indices, 6);
+       // Set material
+       buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+       buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+       buf->getMaterial().setTexture
+                       (0, driver->getTexture(getTexturePath("rat.png").c_str()));
+       buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+       buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+       buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+       // Add to mesh
+       mesh->addMeshBuffer(buf);
+       buf->drop();
+       m_node = smgr->addMeshSceneNode(mesh, NULL);
+       mesh->drop();
+       updateNodePos();
+}
+#endif
+
+/*
+       ItemObject
+*/
+#ifndef SERVER
+void ItemObject::addToScene(scene::ISceneManager *smgr)
+{
+       if(m_node != NULL)
+               return;
+       
+       //video::IVideoDriver* driver = smgr->getVideoDriver();
+       
+       // Get image of item for showing
+       video::ITexture *texture = getItemImage();
+
+       /*
+               Create a mesh
+       */
+
+       scene::SMesh *mesh = new scene::SMesh();
+       {
+       scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+       video::SColor c(255,255,255,255);
+       video::S3DVertex vertices[4] =
+       {
+               /*video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c, 0,1),
+               video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 1,1),
+               video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c, 1,0),
+               video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 0,0),*/
+               video::S3DVertex(BS/3,-BS/2,0, 0,0,0, c, 0,1),
+               video::S3DVertex(-BS/3,-BS/2,0, 0,0,0, c, 1,1),
+               video::S3DVertex(-BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 1,0),
+               video::S3DVertex(BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 0,0),
+       };
+       u16 indices[] = {0,1,2,2,3,0};
+       buf->append(vertices, 4, indices, 6);
+       // Set material
+       buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+       buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+       buf->getMaterial().setTexture(0, texture);
+       buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+       buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+       buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+       // Add to mesh
+       mesh->addMeshBuffer(buf);
+       buf->drop();
+       }
+       m_node = smgr->addMeshSceneNode(mesh, NULL);
+       // Set it to use the materials of the meshbuffers directly.
+       // This is needed for changing the texture in the future
+       ((scene::IMeshSceneNode*)m_node)->setReadOnlyMaterials(true);
+       mesh->drop();
+
+       updateSceneNode();
+}
+
+video::ITexture * ItemObject::getItemImage()
+{
+       /*
+               Create an inventory item to see what is its image
+       */
+       video::ITexture *texture = NULL;
+       InventoryItem *item = createInventoryItem();
+       if(item)
+               texture = item->getImage();
+       if(item)
+               delete item;
+       return texture;
+}
+
+#endif
+
+InventoryItem * ItemObject::createInventoryItem()
+{
+       try{
+               std::istringstream is(m_itemstring, std::ios_base::binary);
+               InventoryItem *item = InventoryItem::deSerialize(is);
+               dstream<<__FUNCTION_NAME<<": m_itemstring=\""
+                               <<m_itemstring<<"\" -> item="<<item
+                               <<std::endl;
+               return item;
+       }
+       catch(SerializationError &e)
+       {
+               dstream<<__FUNCTION_NAME<<": serialization error: "
+                               <<"m_itemstring=\""<<m_itemstring<<"\""<<std::endl;
+               return NULL;
+       }
+}
+
+/*
+       PlayerObject
+*/
+#ifndef SERVER
+void PlayerObject::addToScene(scene::ISceneManager *smgr)
+{
+       if(m_node != NULL)
+               return;
+       
+       video::IVideoDriver* driver = smgr->getVideoDriver();
+
+       // Attach a simple mesh to the player for showing an image
+       scene::SMesh *mesh = new scene::SMesh();
+       { // Front
+       scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+       video::SColor c(255,255,255,255);
+       video::S3DVertex vertices[4] =
+       {
+               video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+               video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+               video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+               video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+       };
+       u16 indices[] = {0,1,2,2,3,0};
+       buf->append(vertices, 4, indices, 6);
+       // Set material
+       buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+       //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+       buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player.png").c_str()));
+       buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+       buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+       //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+       buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+       // Add to mesh
+       mesh->addMeshBuffer(buf);
+       buf->drop();
+       }
+       { // Back
+       scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+       video::SColor c(255,255,255,255);
+       video::S3DVertex vertices[4] =
+       {
+               video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+               video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+               video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+               video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+       };
+       u16 indices[] = {0,1,2,2,3,0};
+       buf->append(vertices, 4, indices, 6);
+       // Set material
+       buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+       //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
+       buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player_back.png").c_str()));
+       buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+       buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+       buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+       // Add to mesh
+       mesh->addMeshBuffer(buf);
+       buf->drop();
+       }
+       
+       m_node = smgr->addMeshSceneNode(mesh, NULL);
+       mesh->drop();
+       updateNodePos();
+}
+#endif
+
 /*
        MapBlockObjectList
 */
@@ -232,7 +491,7 @@ void MapBlockObjectList::serialize(std::ostream &os, u8 version)
 }
 
 void MapBlockObjectList::update(std::istream &is, u8 version,
-               scene::ISceneManager *smgr)
+               scene::ISceneManager *smgr, u32 daynight_ratio)
 {
        JMutexAutoLock lock(m_mutex);
 
@@ -306,17 +565,7 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                                        " id="<<id
                                        <<std::endl;*/
 
-                       if(type_id == MAPBLOCKOBJECT_TYPE_TEST)
-                       {
-                               // The constructors of objects shouldn't need
-                               // any more parameters than this.
-                               obj = new TestObject(m_block, id, pos);
-                       }
-                       else if(type_id == MAPBLOCKOBJECT_TYPE_TEST2)
-                       {
-                               obj = new Test2Object(m_block, id, pos);
-                       }
-                       else if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
+                       if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
                        {
                                obj = new SignObject(m_block, id, pos);
                        }
@@ -324,13 +573,20 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                        {
                                obj = new RatObject(m_block, id, pos);
                        }
+                       else if(type_id == MAPBLOCKOBJECT_TYPE_ITEM)
+                       {
+                               obj = new ItemObject(m_block, id, pos);
+                       }
                        else
                        {
+                               // This is fatal because we cannot know the length
+                               // of the object's data
                                throw SerializationError
                                ("MapBlockObjectList::update(): Unknown MapBlockObject type");
                        }
 
                        if(smgr != NULL)
+                               //obj->addToScene(smgr, daynight_ratio);
                                obj->addToScene(smgr);
 
                        n->setValue(obj);
@@ -339,6 +595,11 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                {
                        obj = n->getValue();
                        obj->updatePos(pos);
+                       /*if(daynight_ratio != m_last_update_daynight_ratio)
+                       {
+                               obj->removeFromScene();
+                               obj->addToScene(smgr, daynight_ratio);
+                       }*/
                }
 
                // Now there is an object in obj.
@@ -346,6 +607,21 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                
                obj->update(is, version);
                
+               /*
+                       Update light on client
+               */
+               if(smgr != NULL)
+               {
+                       u8 light = LIGHT_MAX;
+                       try{
+                               v3s16 relpos_i = floatToInt(obj->m_pos, BS);
+                               MapNode n = m_block->getNodeParent(relpos_i);
+                               light = n.getLightBlend(daynight_ratio);
+                       }
+                       catch(InvalidPositionException &e) {}
+                       obj->updateLight(light);
+               }
+               
                // Remove from deletion list
                if(ids_to_delete.find(id) != NULL)
                        ids_to_delete.remove(id);
@@ -367,6 +643,8 @@ void MapBlockObjectList::update(std::istream &is, u8 version,
                delete obj;
                m_objects.remove(id);
        }
+
+       m_last_update_daynight_ratio = daynight_ratio;
 }
 
 s16 MapBlockObjectList::getFreeId() throw(ContainerFullException)
@@ -469,42 +747,65 @@ MapBlockObject * MapBlockObjectList::get(s16 id)
                return n->getValue();
 }
 
-void MapBlockObjectList::step(float dtime, bool server)
+void MapBlockObjectList::step(float dtime, bool server, u32 daynight_ratio)
 {
+       DSTACK(__FUNCTION_NAME);
+       
        JMutexAutoLock lock(m_mutex);
-
+       
        core::map<s16, bool> ids_to_delete;
 
-       for(core::map<s16, MapBlockObject*>::Iterator
-                       i = m_objects.getIterator();
-                       i.atEnd() == false; i++)
        {
-               MapBlockObject *obj = i.getNode()->getValue();
-               
-               if(server)
-               {
-                       bool to_delete = obj->serverStep(dtime);
+               DSTACKF("%s: stepping objects", __FUNCTION_NAME);
 
-                       if(to_delete)
-                               ids_to_delete.insert(obj->m_id, true);
-               }
-               else
+               for(core::map<s16, MapBlockObject*>::Iterator
+                               i = m_objects.getIterator();
+                               i.atEnd() == false; i++)
                {
-                       obj->clientStep(dtime);
+                       MapBlockObject *obj = i.getNode()->getValue();
+                       
+                       DSTACKF("%s: stepping object type %i", __FUNCTION_NAME,
+                                       obj->getTypeId());
+
+                       if(server)
+                       {
+                               // Update light
+                               u8 light = LIGHT_MAX;
+                               try{
+                                       v3s16 relpos_i = floatToInt(obj->m_pos, BS);
+                                       MapNode n = m_block->getNodeParent(relpos_i);
+                                       light = n.getLightBlend(daynight_ratio);
+                               }
+                               catch(InvalidPositionException &e) {}
+                               obj->updateLight(light);
+                               
+                               bool to_delete = obj->serverStep(dtime, daynight_ratio);
+
+                               if(to_delete)
+                                       ids_to_delete.insert(obj->m_id, true);
+                       }
+                       else
+                       {
+                               obj->clientStep(dtime);
+                       }
                }
        }
 
-       // Delete objects in delete queue
-       for(core::map<s16, bool>::Iterator
-                       i = ids_to_delete.getIterator();
-                       i.atEnd() == false; i++)
        {
-               s16 id = i.getNode()->getKey();
+               DSTACKF("%s: deleting objects", __FUNCTION_NAME);
 
-               MapBlockObject *obj = m_objects[id];
-               obj->removeFromScene();
-               delete obj;
-               m_objects.remove(id);
+               // Delete objects in delete queue
+               for(core::map<s16, bool>::Iterator
+                               i = ids_to_delete.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       s16 id = i.getNode()->getKey();
+
+                       MapBlockObject *obj = m_objects[id];
+                       obj->removeFromScene();
+                       delete obj;
+                       m_objects.remove(id);
+               }
        }
        
        /*
@@ -513,36 +814,42 @@ void MapBlockObjectList::step(float dtime, bool server)
 
        if(server == false)
                return;
-
-       for(core::map<s16, MapBlockObject*>::Iterator
-                       i = m_objects.getIterator();
-                       i.atEnd() == false; i++)
+       
        {
-               MapBlockObject *obj = i.getNode()->getValue();
+               DSTACKF("%s: object wrap loop", __FUNCTION_NAME);
 
-               v3s16 pos_i = floatToInt(obj->m_pos);
-
-               if(m_block->isValidPosition(pos_i))
+               for(core::map<s16, MapBlockObject*>::Iterator
+                               i = m_objects.getIterator();
+                               i.atEnd() == false; i++)
                {
-                       // No wrap
-                       continue;
-               }
+                       MapBlockObject *obj = i.getNode()->getValue();
 
-               bool impossible = wrapObject(obj);
+                       v3s16 pos_i = floatToInt(obj->m_pos, BS);
 
-               if(impossible)
-               {
-                       // No wrap
-                       continue;
-               }
+                       if(m_block->isValidPosition(pos_i))
+                       {
+                               // No wrap
+                               continue;
+                       }
+
+                       bool impossible = wrapObject(obj);
 
-               // Restart find
-               i = m_objects.getIterator();
+                       if(impossible)
+                       {
+                               // No wrap
+                               continue;
+                       }
+
+                       // Restart find
+                       i = m_objects.getIterator();
+               }
        }
 }
 
 bool MapBlockObjectList::wrapObject(MapBlockObject *object)
 {
+       DSTACK(__FUNCTION_NAME);
+       
        // No lock here; this is called so that the lock is already locked.
        //JMutexAutoLock lock(m_mutex);
 
@@ -550,21 +857,12 @@ bool MapBlockObjectList::wrapObject(MapBlockObject *object)
        assert(m_objects.find(object->m_id) != NULL);
        assert(m_objects[object->m_id] == object);
 
-       NodeContainer *parentcontainer = m_block->getParent();
-       // This will only work if the parent is the map
-       if(parentcontainer->nodeContainerId() != NODECONTAINER_ID_MAP)
-       {
-               dstream<<"WARNING: Wrapping object not possible: "
-                               "MapBlock's parent is not map"<<std::endl;
-               return true;
-       }
-       // OK, we have the map!
-       Map *map = (Map*)parentcontainer;
+       Map *map = m_block->getParent();
        
        // Calculate blockpos on map
        v3s16 oldblock_pos_i_on_map = m_block->getPosRelative();
        v3f pos_f_on_oldblock = object->m_pos;
-       v3s16 pos_i_on_oldblock = floatToInt(pos_f_on_oldblock);
+       v3s16 pos_i_on_oldblock = floatToInt(pos_f_on_oldblock, BS);
        v3s16 pos_i_on_map = pos_i_on_oldblock + oldblock_pos_i_on_map;
        v3s16 pos_blocks_on_map = getNodeBlockPos(pos_i_on_map);
 
@@ -598,9 +896,9 @@ bool MapBlockObjectList::wrapObject(MapBlockObject *object)
        }
        
        // Calculate position on new block
-       v3f oldblock_pos_f_on_map = intToFloat(oldblock_pos_i_on_map);
+       v3f oldblock_pos_f_on_map = intToFloat(oldblock_pos_i_on_map, BS);
        v3s16 newblock_pos_i_on_map = newblock->getPosRelative();
-       v3f newblock_pos_f_on_map = intToFloat(newblock_pos_i_on_map);
+       v3f newblock_pos_f_on_map = intToFloat(newblock_pos_i_on_map, BS);
        v3f pos_f_on_newblock = pos_f_on_oldblock
                        - newblock_pos_f_on_map + oldblock_pos_f_on_map;
 
@@ -627,7 +925,7 @@ void MapBlockObjectList::getObjects(v3f origin, f32 max_d,
        {
                MapBlockObject *obj = i.getNode()->getValue();
 
-               f32 d = (obj->m_pos - origin).getLength();
+               f32 d = (obj->getRelativeShowPos() - origin).getLength();
 
                if(d > max_d)
                        continue;