add 'damage_group' and 'damage_texture_modifier' settings to mob definition

This commit is contained in:
TenPlus1 2021-05-15 09:33:35 +01:00
parent f58841ab3e
commit ec44aa91c4
2 changed files with 20 additions and 24 deletions

42
api.lua
View File

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20210504", version = "20210515",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
@ -2652,9 +2652,11 @@ function mob_class:do_states(dtime)
self.attack = attached self.attack = attached
end end
local dgroup = self.damage_group or "fleshy"
self.attack:punch(self.object, 1.0, { self.attack:punch(self.object, 1.0, {
full_punch_interval = 1.0, full_punch_interval = 1.0,
damage_groups = {fleshy = self.damage} damage_groups = {[dgroup] = self.damage}
}, nil) }, nil)
end end
end end
@ -2915,22 +2917,17 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
-- 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
local snd
-- weapon sounds -- weapon sounds
if weapon_def.sounds then if weapon_def.sounds then
snd = weapon_def.sounds[random(#weapon_def.sounds)]
local s = random(0, #weapon_def.sounds)
minetest.sound_play(weapon_def.sounds[s], {
object = self.object,
max_hear_distance = 8
}, true)
else else
minetest.sound_play("default_punch", { snd = "default_punch"
object = self.object,
max_hear_distance = 5
}, true)
end end
minetest.sound_play(snd, {object = self.object, max_hear_distance = 8}, true)
-- blood_particles -- blood_particles
if not disable_blood and self.blood_amount > 0 then if not disable_blood and self.blood_amount > 0 then
@ -2938,8 +2935,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
local blood = self.blood_texture local blood = self.blood_texture
local amount = self.blood_amount local amount = self.blood_amount
pos.y = pos.y + (-self.collisionbox[2] pos.y = pos.y + (-self.collisionbox[2] + self.collisionbox[5]) * .5
+ self.collisionbox[5]) * .5
-- lots of damage = more blood :) -- lots of damage = more blood :)
if damage > 10 then if damage > 10 then
@ -2952,7 +2948,6 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
end end
effect(pos, amount, blood, 1, 2, 1.75, nil, nil, true) effect(pos, amount, blood, 1, 2, 1.75, nil, nil, true)
end end
-- do damage -- do damage
@ -2962,8 +2957,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
local hot = tool_capabilities and tool_capabilities.damage_groups local hot = tool_capabilities and tool_capabilities.damage_groups
and tool_capabilities.damage_groups.fire and tool_capabilities.damage_groups.fire
if self:check_for_death({type = "punch", if self:check_for_death({type = "punch", puncher = hitter, hot = hot}) then
puncher = hitter, hot = hot}) then
return true return true
end end
@ -2983,8 +2977,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
end -- END if damage end -- END if damage
-- knock back effect (only on full punch) -- knock back effect (only on full punch)
if self.knock_back if self.knock_back and tflp >= punch_interval then
and tflp >= punch_interval then
local v = self.object:get_velocity() local v = self.object:get_velocity()
@ -3594,6 +3587,8 @@ minetest.register_entity(name, setmetatable({
walk_velocity = def.walk_velocity, walk_velocity = def.walk_velocity,
run_velocity = def.run_velocity, run_velocity = def.run_velocity,
damage = max(0, (def.damage or 0) * difficulty), damage = max(0, (def.damage or 0) * difficulty),
damage_group = def.damage_group,
damage_texture_modifier = def.damage_texture_modifier,
light_damage = def.light_damage, light_damage = def.light_damage,
light_damage_min = def.light_damage_min, light_damage_min = def.light_damage_min,
light_damage_max = def.light_damage_max, light_damage_max = def.light_damage_max,
@ -4289,7 +4284,7 @@ function mobs:boom(self, pos, radius)
radius = radius, radius = radius,
damage_radius = radius, damage_radius = radius,
sound = self.sounds and self.sounds.explode, sound = self.sounds and self.sounds.explode,
explode_center = true, explode_center = true
}) })
else else
mobs:safe_boom(self, pos, radius) mobs:safe_boom(self, pos, radius)
@ -4828,14 +4823,13 @@ function mobs:alias_mob(old_name, new_name)
-- entity -- entity
minetest.register_entity(":" .. old_name, { minetest.register_entity(":" .. old_name, {
physical = false, physical = false, static_save = false,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
if minetest.registered_entities[new_name] then if minetest.registered_entities[new_name] then
minetest.add_entity(self.object:get_pos(), minetest.add_entity(self.object:get_pos(), new_name, staticdata)
new_name, staticdata)
end end
remove_mob(self) remove_mob(self)

View File

@ -56,6 +56,8 @@ functions needed for the mob to work properly which contains the following:
'view_range' how many nodes in distance the mob can see a player. 'view_range' how many nodes in distance the mob can see a player.
'damage' how many health points the mob does to a player or another 'damage' how many health points the mob does to a player or another
mob when melee attacking. mob when melee attacking.
'damage_group' group in which damage is dealt, dedaults to "fleshy".
'damage_texture_modifier' applies texture modifier on hit e.g "^[brighten"
'knock_back' when true has mobs falling backwards when hit, the greater 'knock_back' when true has mobs falling backwards when hit, the greater
the damage the more they move back. the damage the more they move back.
'fear_height' is how high a cliff or edge has to be before the mob stops 'fear_height' is how high a cliff or edge has to be before the mob stops