]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_sao.cpp
Fix bug when craft input isn't replaced
[dragonfireclient.git] / src / content_sao.cpp
index 318dd367a25fc2c394d0fd7f6ebe8a70dd4fdd51..386b7e070d160fb4d083b452c67b48029d9eff70 100644 (file)
@@ -136,6 +136,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
        m_armor_groups_sent(false),
        m_animation_speed(0),
        m_animation_blend(0),
+       m_animation_loop(true),
        m_animation_sent(false),
        m_bone_position_sent(false),
        m_attachment_parent_id(0),
@@ -324,7 +325,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
 
        if(m_animation_sent == false){
                m_animation_sent = true;
-               std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
+               std::string str = gob_cmd_update_animation(
+                       m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop);
                // create message and add to list
                ActiveObjectMessage aom(getId(), true, str);
                m_messages_out.push(aom);
@@ -366,7 +368,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
                writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here
                os<<serializeLongString(getPropertyPacket()); // message 1
                os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
-               os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
+               os<<serializeLongString(gob_cmd_update_animation(
+                       m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
                for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
                        os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
                }
@@ -419,19 +422,19 @@ int LuaEntitySAO::punch(v3f dir,
                ServerActiveObject *puncher,
                float time_from_last_punch)
 {
-       if(!m_registered){
+       if (!m_registered){
                // Delete unknown LuaEntities when punched
                m_removed = true;
                return 0;
        }
 
        // It's best that attachments cannot be punched
-       if(isAttached())
+       if (isAttached())
                return 0;
 
        ItemStack *punchitem = NULL;
        ItemStack punchitem_static;
-       if(puncher){
+       if (puncher) {
                punchitem_static = puncher->getWieldedItem();
                punchitem = &punchitem_static;
        }
@@ -442,31 +445,26 @@ int LuaEntitySAO::punch(v3f dir,
                        punchitem,
                        time_from_last_punch);
 
-       if(result.did_punch)
-       {
+       if (result.did_punch) {
                setHP(getHP() - result.damage);
 
+               if (result.damage > 0) {
+                       std::string punchername = puncher ? puncher->getDescription() : "nil";
 
-               std::string punchername = "nil";
-
-               if ( puncher != 0 )
-                       punchername = puncher->getDescription();
-
-               actionstream<<getDescription()<<" punched by "
-                               <<punchername<<", damage "<<result.damage
-                               <<" hp, health now "<<getHP()<<" hp"<<std::endl;
-
-               {
-                       std::string str = gob_cmd_punched(result.damage, getHP());
-                       // create message and add to list
-                       ActiveObjectMessage aom(getId(), true, str);
-                       m_messages_out.push(aom);
+                       actionstream << getDescription() << " punched by "
+                                       << punchername << ", damage " << result.damage
+                                       << " hp, health now " << getHP() << " hp" << std::endl;
                }
 
-               if(getHP() == 0)
-                       m_removed = true;
+               std::string str = gob_cmd_punched(result.damage, getHP());
+               // create message and add to list
+               ActiveObjectMessage aom(getId(), true, str);
+               m_messages_out.push(aom);
        }
 
+       if (getHP() == 0)
+               m_removed = true;
+
        m_env->getScriptIface()->luaentity_Punch(m_id, puncher,
                        time_from_last_punch, toolcap, dir);
 
@@ -475,10 +473,10 @@ int LuaEntitySAO::punch(v3f dir,
 
 void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
 {
-       if(!m_registered)
+       if (!m_registered)
                return;
        // It's best that attachments cannot be clicked
-       if(isAttached())
+       if (isAttached())
                return;
        m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
 }
@@ -538,19 +536,21 @@ ItemGroupList LuaEntitySAO::getArmorGroups()
        return m_armor_groups;
 }
 
-void LuaEntitySAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
+void LuaEntitySAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop)
 {
        m_animation_range = frame_range;
        m_animation_speed = frame_speed;
        m_animation_blend = frame_blend;
+       m_animation_loop = frame_loop;
        m_animation_sent = false;
 }
 
-void LuaEntitySAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend)
+void LuaEntitySAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop)
 {
        *frame_range = m_animation_range;
        *frame_speed = m_animation_speed;
        *frame_blend = m_animation_blend;
+       *frame_loop = m_animation_loop;
 }
 
 void LuaEntitySAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)
@@ -738,6 +738,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
        m_is_singleplayer(is_singleplayer),
        m_animation_speed(0),
        m_animation_blend(0),
+       m_animation_loop(true),
        m_animation_sent(false),
        m_bone_position_sent(false),
        m_attachment_parent_id(0),
@@ -833,7 +834,8 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
                writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
                os<<serializeLongString(getPropertyPacket()); // message 1
                os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
-               os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
+               os<<serializeLongString(gob_cmd_update_animation(
+                       m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
                for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
                        os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
                }
@@ -972,7 +974,8 @@ void PlayerSAO::step(float dtime, bool send_recommended)
 
        if(m_animation_sent == false){
                m_animation_sent = true;
-               std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
+               std::string str = gob_cmd_update_animation(
+                       m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop);
                // create message and add to list
                ActiveObjectMessage aom(getId(), true, str);
                m_messages_out.push(aom);
@@ -1171,20 +1174,22 @@ ItemGroupList PlayerSAO::getArmorGroups()
        return m_armor_groups;
 }
 
-void PlayerSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
+void PlayerSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop)
 {
        // store these so they can be updated to clients
        m_animation_range = frame_range;
        m_animation_speed = frame_speed;
        m_animation_blend = frame_blend;
+       m_animation_loop = frame_loop;
        m_animation_sent = false;
 }
 
-void PlayerSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend)
+void PlayerSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop)
 {
        *frame_range = m_animation_range;
        *frame_speed = m_animation_speed;
        *frame_blend = m_animation_blend;
+       *frame_loop = m_animation_loop;
 }
 
 void PlayerSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)