1
0
Fork 0

Add tool wear for punching mobs

This commit is contained in:
Wuzzy 2020-02-19 16:47:57 +01:00
parent e4fb7ae533
commit 589b750d0a
1 changed files with 20 additions and 7 deletions

View File

@ -2623,14 +2623,25 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
punch_interval = tool_capabilities.full_punch_interval or 1.4
end
-- add weapon wear
-- add weapon wear manually
-- Required because we have custom health handling ("health" property)
if minetest.settings:get_bool("creative_mode") ~= true
and weapon:get_definition()
and weapon:get_definition().tool_capabilities then
weapon:add_wear(floor((punch_interval / 75) * 9000))
and tool_capabilities then
if tool_capabilities.punch_attack_uses then
-- Without this delay, the wear does not work. Quite hacky ...
minetest.after(0, function(name)
local player = minetest.get_player_by_name(name)
if not player then return end
local weapon = hitter:get_wielded_item(player)
local def = weapon:get_definition()
if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then
local wear = floor(65535/tool_capabilities.punch_attack_uses)
weapon:add_wear(wear)
hitter:set_wielded_item(weapon)
end
end, hitter:get_player_name())
end
end
local die = false
@ -2921,7 +2932,9 @@ local mob_activate = function(self, staticdata, def, dtime)
self.path.following = false -- currently following path?
self.path.stuck_timer = 0 -- if stuck for too long search for path
-- mob defaults
-- Armor groups
-- immortal=1 because we use custom health
-- handling (using "health" property)
local armor
if type(self.armor) == "table" then
armor = table.copy(self.armor)