Allow on_hit to override builtin damage

This commit is contained in:
stujones11 2019-03-22 20:46:47 +00:00
parent 4a9bf8fc6e
commit 2f5d046472
2 changed files with 7 additions and 4 deletions

View file

@ -150,6 +150,7 @@ Used by `shooter.register_weapon`
}, },
on_hit = function(pointed_thing, spec, dir) on_hit = function(pointed_thing, spec, dir)
-- May be used for arbitary shot effects like knock-back, etc. -- May be used for arbitary shot effects like knock-back, etc.
-- Return `true` to override built-in damage effects
end, end,
spec = { spec = {
-- Weapon specifications -- Weapon specifications

View file

@ -206,6 +206,12 @@ shooter.is_valid_object = function(object)
end end
local function process_hit(pointed_thing, spec, dir) local function process_hit(pointed_thing, spec, dir)
local def = minetest.registered_items[spec.name] or {}
if type(def.on_hit) == "function" then
if def.on_hit(pointed_thing, spec, dir) == true then
return
end
end
if pointed_thing.type == "node" and config.allow_nodes == true then if pointed_thing.type == "node" and config.allow_nodes == true then
local pos = minetest.get_pointed_thing_position(pointed_thing, false) local pos = minetest.get_pointed_thing_position(pointed_thing, false)
shooter.punch_node(pos, spec) shooter.punch_node(pos, spec)
@ -223,10 +229,6 @@ local function process_hit(pointed_thing, spec, dir)
end end
end end
end end
local def = minetest.registered_items[spec.name] or {}
if type(def.on_hit) == "function" then
return def.on_hit(pointed_thing, spec, dir)
end
end end
local function process_round(round) local function process_round(round)