]> git.lizzy.rs Git - minetest.git/blobdiff - src/tool.cpp
Disable word wrap in vertical texts in main menu
[minetest.git] / src / tool.cpp
index da7ee73dc5124fc2d05e810c05eaa1bea57ec34a..40bcdc69a59616825d1607a925544164e691897d 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "utility.h"
 #include "itemdef.h" // For itemgroup_get()
 #include "log.h"
+#include "inventory.h"
 
 void ToolCapabilities::serialize(std::ostream &os) const
 {
@@ -74,12 +75,12 @@ DigParams getDigParams(const ItemGroupList &groups,
        //infostream<<"getDigParams"<<std::endl;
        /* Check group dig_immediate */
        switch(itemgroup_get(groups, "dig_immediate")){
-       case 1:
-               //infostream<<"dig_immediate=1"<<std::endl;
-               return DigParams(true, 0.0, 0);
        case 2:
                //infostream<<"dig_immediate=2"<<std::endl;
-               return DigParams(true, 1.0, 0);
+               return DigParams(true, 0.5, 0);
+       case 3:
+               //infostream<<"dig_immediate=3"<<std::endl;
+               return DigParams(true, 0.0, 0);
        default:
                break;
        }
@@ -153,3 +154,36 @@ HitParams getHitParams(const ItemGroupList &groups,
        return getHitParams(groups, tp, 1000000);
 }
 
+PunchDamageResult getPunchDamage(
+               const ItemGroupList &armor_groups,
+               const ToolCapabilities *toolcap,
+               const ItemStack *punchitem,
+               float time_from_last_punch
+){
+       bool do_hit = true;
+       {
+               if(do_hit && punchitem){
+                       if(itemgroup_get(armor_groups, "punch_operable") &&
+                                       (toolcap == NULL || punchitem->name == ""))
+                               do_hit = false;
+               }
+               if(do_hit){
+                       if(itemgroup_get(armor_groups, "immortal"))
+                               do_hit = false;
+               }
+       }
+       
+       PunchDamageResult result;
+       if(do_hit)
+       {
+               HitParams hitparams = getHitParams(armor_groups, toolcap,
+                               time_from_last_punch);
+               result.did_punch = true;
+               result.wear = hitparams.wear;
+               result.damage = hitparams.hp;
+       }
+
+       return result;
+}
+
+