1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-02-06 05:40:21 +01:00

call do_punch after damage calculated

This commit is contained in:
tenplus1 2025-02-01 13:57:27 +00:00
parent f09b6d1730
commit 4b825b3e86

43
api.lua
View File

@ -18,7 +18,7 @@ end
-- Global table -- Global table
mobs = { mobs = {
mod = "redo", version = "20250120", mod = "redo", version = "20250201",
spawning_mobs = {}, translate = S, spawning_mobs = {}, translate = S,
node_snow = has(minetest.registered_aliases["mapgen_snow"]) node_snow = has(minetest.registered_aliases["mapgen_snow"])
or has("mcl_core:snow") or has("default:snow") or "air", or has("mcl_core:snow") or has("default:snow") or "air",
@ -2496,12 +2496,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
-- mob health check -- mob health check
if self.health <= 0 then return true end if self.health <= 0 then return true end
-- custom punch function (if false returned, do not continue and return true)
if self.do_punch and self:do_punch(
hitter, tflp, tool_capabilities, dir, damage) == false then
return true
end
-- error checking when mod profiling is enabled -- error checking when mod profiling is enabled
if not tool_capabilities then if not tool_capabilities then
minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled") minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled")
@ -2541,15 +2535,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
local weapon = hitter:get_wielded_item() local weapon = hitter:get_wielded_item()
local weapon_def = weapon:get_definition() or {} local weapon_def = weapon:get_definition() or {}
--- check for ehchantments when using mineclonia/voxelibre
local enchants = {}
if use_mc2 then
enchants = minetest.deserialize(
weapon:get_meta():get_string("mcl_enchanting:enchantments")) or {}
end
-- calculate mob damage -- calculate mob damage
local damage = 0 local damage = 0
local armor = self.object:get_armor_groups() or {} local armor = self.object:get_armor_groups() or {}
@ -2593,6 +2578,27 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
end end
end end
--- check for ehchantments when using mineclonia/voxelibre
local enchants = {}
if use_mc2 then
-- get enchants
enchants = minetest.deserialize(
weapon:get_meta():get_string("mcl_enchanting:enchantments")) or {}
-- check for damage increasing enchantments
if enchants.sharpness then
damage = damage + (0.5 * enchants.sharpness) + 0.5
end
end
-- custom punch function (if false returned, do not continue and return true)
if self.do_punch and self:do_punch(
hitter, tflp, tool_capabilities, dir, damage) == false then
return true
end
--print("Mob Damage is", damage) --print("Mob Damage is", damage)
-- healing -- healing
@ -2633,11 +2639,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
hitter:set_wielded_item(weapon) hitter:set_wielded_item(weapon)
-- check for damage increasing enchantments
if use_mc2 and enchants.sharpness then
damage = damage + (0.5 * enchants.sharpness) + 0.5
end
-- only play hit sound and show blood effects if damage is 1 or over -- only play hit sound and show blood effects if damage is 1 or over
if damage >= 1 then if damage >= 1 then