mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-19 09:31:07 +01:00
Add tool wear for punching mobs
This commit is contained in:
parent
e4fb7ae533
commit
589b750d0a
1 changed files with 20 additions and 7 deletions
|
@ -2623,13 +2623,24 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
||||||
end
|
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
|
if minetest.settings:get_bool("creative_mode") ~= true
|
||||||
and weapon:get_definition()
|
and tool_capabilities then
|
||||||
and weapon:get_definition().tool_capabilities then
|
if tool_capabilities.punch_attack_uses then
|
||||||
|
-- Without this delay, the wear does not work. Quite hacky ...
|
||||||
weapon:add_wear(floor((punch_interval / 75) * 9000))
|
minetest.after(0, function(name)
|
||||||
hitter:set_wielded_item(weapon)
|
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
|
end
|
||||||
|
|
||||||
local die = false
|
local die = false
|
||||||
|
@ -2921,7 +2932,9 @@ local mob_activate = function(self, staticdata, def, dtime)
|
||||||
self.path.following = false -- currently following path?
|
self.path.following = false -- currently following path?
|
||||||
self.path.stuck_timer = 0 -- if stuck for too long search for 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
|
local armor
|
||||||
if type(self.armor) == "table" then
|
if type(self.armor) == "table" then
|
||||||
armor = table.copy(self.armor)
|
armor = table.copy(self.armor)
|
||||||
|
|
Loading…
Reference in a new issue