]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/player/player_interaction.lua
Optimize some locals
[Crafter.git] / mods / player / player_interaction.lua
index f8ccbb586136c76d55c6552d24cdbe6d65893284..029987102704581389c8bfbad93a85f64d4a794a 100644 (file)
@@ -1,3 +1,5 @@
+local minetest,armor_class,math = minetest,armor_class,math
+
 --hurt sound and disable fall damage group handling
 minetest.register_on_player_hpchange(function(player, hp_change, reason)
        if reason.type == "fall" then
@@ -25,33 +27,33 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
 
                        if new_stack == "" then                                 
                                        minetest.sound_play("armor_break",{to_player=player:get_player_name(),gain=1,pitch=math.random(80,100)/100})
-                                       recalculate_armor(player)
-                                       set_armor_gui(player)
+                                       armor_class.recalculate_armor(player)
+                                       armor_class.set_armor_gui(player)
                                        --do particles too
-                               else
+                               elseif minetest.get_item_group(new_stack,"boots") > 0 then 
+                                       local pos = player:get_pos()
+                                       minetest.add_particlespawner({
+                                               amount = 30,
+                                               time = 0.00001,
+                                               minpos = {x=pos.x-0.5, y=pos.y+0.1, z=pos.z-0.5},
+                                               maxpos = {x=pos.x+0.5, y=pos.y+0.1, z=pos.z+0.5},
+                                               minvel = vector.new(-0.5,1,-0.5),
+                                               maxvel = vector.new(0.5 ,2 ,0.5),
+                                               minacc = {x=0, y=-9.81, z=1},
+                                               maxacc = {x=0, y=-9.81, z=1},
+                                               minexptime = 0.5,
+                                               maxexptime = 1.5,
+                                               minsize = 0,
+                                               maxsize = 0,
+                                               --attached = player,
+                                               collisiondetection = true,
+                                               collision_removal = true,
+                                               vertical = false,
+                                               node = {name= name.."particletexture"},
+                                               --texture = "eat_particles_1.png"
+                                       })
                                        minetest.sound_play("armor_fall_damage", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})   
                                end
-                               local pos = player:get_pos()
-                               minetest.add_particlespawner({
-                                       amount = 30,
-                                       time = 0.00001,
-                                       minpos = {x=pos.x-0.5, y=pos.y+0.1, z=pos.z-0.5},
-                                       maxpos = {x=pos.x+0.5, y=pos.y+0.1, z=pos.z+0.5},
-                                       minvel = vector.new(-0.5,1,-0.5),
-                                       maxvel = vector.new(0.5 ,2 ,0.5),
-                                       minacc = {x=0, y=-9.81, z=1},
-                                       maxacc = {x=0, y=-9.81, z=1},
-                                       minexptime = 0.5,
-                                       maxexptime = 1.5,
-                                       minsize = 0,
-                                       maxsize = 0,
-                                       --attached = player,
-                                       collisiondetection = true,
-                                       collision_removal = true,
-                                       vertical = false,
-                                       node = {name= name.."particletexture"},
-                                       --texture = "eat_particles_1.png"
-                               })
 
                                fall_damage = fall_damage + absorption
 
@@ -134,7 +136,7 @@ minetest.register_on_dieplayer(function(player, reason)
        end
 
 
-       recalculate_armor(player)
+       armor_class.recalculate_armor(player)
 end)
 
 
@@ -274,11 +276,11 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
                        dir.y = 7
                end
 
-               local hp_modifier = math.ceil(calculate_armor_absorbtion(player)/3)
+               local hp_modifier = math.ceil(armor_class.calculate_armor_absorbtion(player)/3)
                --print("hp_modifier:",hp_modifier)
-               damage_armor(player,math.abs(hurt))
+               armor_class.damage_armor(player,math.abs(hurt))
 
-               print("hurt:",hurt,"|","hp_modifier:",hp_modifier)
+               --print("hurt:",hurt,"|","hp_modifier:",hp_modifier)
                local modify_output = (hurt == 0)
                
                hurt = hurt - hp_modifier