1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-01-23 16:00:16 +01:00

Add basic mineclonia enchantments (sharpness, fire_aspect, knockback)

This commit is contained in:
tenplus1 2024-08-09 09:15:06 +01:00
parent 57d6859b93
commit 3e24677649

31
api.lua
View File

@ -21,7 +21,7 @@ end
-- Global -- Global
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20240804", version = "20240809",
translate = S, translate = S,
invis = minetest.global_exists("invisibility") and invisibility or {}, invis = minetest.global_exists("invisibility") and invisibility or {},
node_snow = has(minetest.registered_aliases["mapgen_snow"]) node_snow = has(minetest.registered_aliases["mapgen_snow"])
@ -2872,6 +2872,15 @@ 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 {}
@ -2965,6 +2974,14 @@ 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 then
if enchants.sharpness then
damage = damage + (0.5 * enchants.sharpness) + 0.5
end
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
@ -3031,6 +3048,11 @@ 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
-- check for any fire enchants also
if enchants.flame or enchants.fire_aspect then
hot = true
end
if self:check_for_death({type = "punch", puncher = hitter, hot = hot}) then if self:check_for_death({type = "punch", puncher = hitter, hot = hot}) then
return true return true
end end
@ -3058,6 +3080,11 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
-- use tool knockback value or default -- use tool knockback value or default
kb = tool_capabilities.damage_groups["knockback"] or kb kb = tool_capabilities.damage_groups["knockback"] or kb
-- check for knockback enchantment
if use_mc2 and enchants.knockback then
kb = kb + (3 * enchants.knockback)
end
self.object:set_velocity({x = dir.x * kb, y = up, z = dir.z * kb}) self.object:set_velocity({x = dir.x * kb, y = up, z = dir.z * kb})
-- turn mob on knockback and play run/walk animation -- turn mob on knockback and play run/walk animation
@ -3788,6 +3815,8 @@ minetest.register_entity(":" .. name, setmetatable({
on_grown = def.on_grown, on_grown = def.on_grown,
on_sound = def.on_sound, on_sound = def.on_sound,
is_mob = true, _hittable_by_projectile = true, -- mineclone thing
on_activate = function(self, staticdata, dtime) on_activate = function(self, staticdata, dtime)
return self:mob_activate(staticdata, def, dtime) return self:mob_activate(staticdata, def, dtime)
end, end,