Modernize client code (#6250)
[oweals/minetest.git] / src / content_sao.cpp
index c6c00768e0cdc3e80c04dcf9fecf14a87342c29c..674ab580c389cea7490a9999e0cebbec866dc123 100644 (file)
@@ -91,6 +91,9 @@ public:
        }
 
        bool getCollisionBox(aabb3f *toset) const { return false; }
+
+       virtual bool getSelectionBox(aabb3f *toset) const { return false; }
+
        bool collideWithObjects() const { return false; }
 
 private:
@@ -579,8 +582,10 @@ int LuaEntitySAO::punch(v3f dir,
                }
        }
 
-       if (getHP() == 0)
+       if (getHP() == 0) {
                m_removed = true;
+               m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
+       }
 
 
 
@@ -746,6 +751,18 @@ bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const
        return false;
 }
 
+bool LuaEntitySAO::getSelectionBox(aabb3f *toset) const
+{
+       if (!m_prop.is_visible) {
+               return false;
+       }
+
+       toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
+       toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
+
+       return true;
+}
+
 bool LuaEntitySAO::collideWithObjects() const
 {
        return m_prop.collideWithObjects;
@@ -769,7 +786,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
        m_prop.hp_max = PLAYER_MAX_HP;
        m_prop.physical = false;
        m_prop.weight = 75;
-       m_prop.collisionbox = aabb3f(-0.3f, -1.0f, -0.3f, 0.3f, 0.75f, 0.3f);
+       m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f);
        // start of default appearance, this should be overwritten by LUA
        m_prop.visual = "upright_sprite";
        m_prop.visual_size = v2f(1, 2);
@@ -782,6 +799,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
        // end of default appearance
        m_prop.is_visible = true;
        m_prop.makes_footstep_sound = true;
+       m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
        m_hp = PLAYER_MAX_HP;
 }
 
@@ -841,7 +859,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
        os << serializeString(m_player->getName()); // name
        writeU8(os, 1); // is_player
        writeS16(os, getId()); //id
-       writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
+       writeV3F1000(os, m_base_position);
        writeF1000(os, m_yaw);
        writeS16(os, getHP());
 
@@ -994,7 +1012,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
                if(isAttached()) // Just in case we ever do send attachment position too
                        pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
                else
-                       pos = m_base_position + v3f(0,BS*1,0);
+                       pos = m_base_position;
                std::string str = gob_cmd_update_position(
                        pos,
                        v3f(0,0,0),
@@ -1399,9 +1417,22 @@ bool PlayerSAO::checkMovementCheat()
 
 bool PlayerSAO::getCollisionBox(aabb3f *toset) const
 {
-       *toset = aabb3f(-0.3f * BS, 0.0f, -0.3f * BS, 0.3f * BS, 1.75f * BS, 0.3f * BS);
+       //update collision box
+       toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
+       toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;
 
        toset->MinEdge += m_base_position;
        toset->MaxEdge += m_base_position;
        return true;
 }
+
+bool PlayerSAO::getSelectionBox(aabb3f *toset) const
+{
+       if (!m_prop.is_visible) {
+               return false;
+       }
+
+       getCollisionBox(toset);
+
+       return true;
+}