mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-25 18:20:20 +01:00
added support for raymoo's cmi mod
This commit is contained in:
parent
54b88e25b2
commit
a58299479e
91
api.lua
91
api.lua
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
-- Mobs Api (16th June 2017)
|
-- Mobs Api (18th June 2017)
|
||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
mobs.version = "20170616"
|
mobs.version = "20170618"
|
||||||
|
|
||||||
|
|
||||||
-- Intllib
|
-- Intllib
|
||||||
@ -23,6 +23,9 @@ end
|
|||||||
mobs.intllib = S
|
mobs.intllib = S
|
||||||
|
|
||||||
|
|
||||||
|
-- CMI support check
|
||||||
|
local use_cmi = minetest.global_exists("cmi")
|
||||||
|
|
||||||
-- Invisibility mod check
|
-- Invisibility mod check
|
||||||
mobs.invis = {}
|
mobs.invis = {}
|
||||||
if rawget(_G, "invisibility") then
|
if rawget(_G, "invisibility") then
|
||||||
@ -370,7 +373,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- check if mob is dead or only hurt
|
-- check if mob is dead or only hurt
|
||||||
local check_for_death = function(self, cause)
|
local check_for_death = function(self, cause, cmi_cause)
|
||||||
|
|
||||||
-- has health actually changed?
|
-- has health actually changed?
|
||||||
if self.health == self.old_health and self.health > 0 then
|
if self.health == self.old_health and self.health > 0 then
|
||||||
@ -419,6 +422,11 @@ local check_for_death = function(self, cause)
|
|||||||
if self.on_die then
|
if self.on_die then
|
||||||
|
|
||||||
self.on_die(self, pos)
|
self.on_die(self, pos)
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
cmi.notify_die(self.object, cmi_cause)
|
||||||
|
end
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -439,9 +447,19 @@ local check_for_death = function(self, cause)
|
|||||||
set_animation(self, "die")
|
set_animation(self, "die")
|
||||||
|
|
||||||
minetest.after(2, function(self)
|
minetest.after(2, function(self)
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
cmi.notify_die(self.object, cmi_cause)
|
||||||
|
end
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end, self)
|
end, self)
|
||||||
else
|
else
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
cmi.notify_die(self.object, cmi_cause)
|
||||||
|
end
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -499,15 +517,11 @@ local node_ok = function(pos, fallback)
|
|||||||
|
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
|
||||||
if not node then
|
if node and minetest.registered_nodes[node.name] then
|
||||||
return minetest.registered_nodes[fallback]
|
|
||||||
end
|
|
||||||
|
|
||||||
if minetest.registered_nodes[node.name] then
|
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
return minetest.registered_nodes[fallback]
|
return {name = fallback}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -549,7 +563,7 @@ local do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png")
|
effect(pos, 5, "tnt_smoke.png")
|
||||||
|
|
||||||
if check_for_death(self, "light") then return end
|
if check_for_death(self, "light", {type = "light"}) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- what is mob standing in?
|
-- what is mob standing in?
|
||||||
@ -577,7 +591,8 @@ local do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
|
effect(pos, 5, "bubble.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
if check_for_death(self, "water") then return end
|
if check_for_death(self, "water", {type = "environment",
|
||||||
|
pos = pos, node = self.standing_in}) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lava or fire
|
-- lava or fire
|
||||||
@ -592,7 +607,8 @@ local do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
||||||
|
|
||||||
if check_for_death(self, "lava") then return end
|
if check_for_death(self, "lava", {type = "environment",
|
||||||
|
pos = pos, node = self.standing_in}) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- damage_per_second node check
|
-- damage_per_second node check
|
||||||
@ -602,7 +618,8 @@ local do_env_damage = function(self)
|
|||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png")
|
effect(pos, 5, "tnt_smoke.png")
|
||||||
|
|
||||||
if check_for_death(self, "dps") then return end
|
if check_for_death(self, "dps", {type = "environment",
|
||||||
|
pos = pos, node = self.standing_in}) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- suffocation inside solid node
|
--- suffocation inside solid node
|
||||||
@ -613,10 +630,11 @@ local do_env_damage = function(self)
|
|||||||
|
|
||||||
self.health = self.health - self.suffocation
|
self.health = self.health - self.suffocation
|
||||||
|
|
||||||
if check_for_death(self, "suffocation") then return end
|
if check_for_death(self, "suffocation", {type = "environment",
|
||||||
|
pos = pos, node = self.standing_in}) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
check_for_death(self, "")
|
check_for_death(self, "", {type = "unknown"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1957,7 +1975,7 @@ local falling = function(self, pos)
|
|||||||
|
|
||||||
effect(pos, 5, "tnt_smoke.png", 1, 2, 2, nil)
|
effect(pos, 5, "tnt_smoke.png", 1, 2, 2, nil)
|
||||||
|
|
||||||
if check_for_death(self, "fall") then
|
if check_for_death(self, "fall", {type = "fall"}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2004,6 +2022,10 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
tflp = 0.2
|
tflp = 0.2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
damage = cmi.calculate_damage(self.object, hitter, tflp, tool_capabilities, dir)
|
||||||
|
else
|
||||||
|
|
||||||
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
|
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
|
||||||
|
|
||||||
tmp = tflp / (tool_capabilities.full_punch_interval or 1.4)
|
tmp = tflp / (tool_capabilities.full_punch_interval or 1.4)
|
||||||
@ -2017,6 +2039,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
damage = damage + (tool_capabilities.damage_groups[group] or 0)
|
damage = damage + (tool_capabilities.damage_groups[group] or 0)
|
||||||
* tmp * ((armor[group] or 0) / 100.0)
|
* tmp * ((armor[group] or 0) / 100.0)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- check for tool immunity or special damage
|
-- check for tool immunity or special damage
|
||||||
for n = 1, #self.immune_to do
|
for n = 1, #self.immune_to do
|
||||||
@ -2036,6 +2059,13 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
|
|
||||||
-- print ("Mob Damage is", damage)
|
-- print ("Mob Damage is", damage)
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
|
||||||
|
local cancel = cmi.notify_punch(self.object, hitter, tflp, tool_capabilities, dir, damage)
|
||||||
|
|
||||||
|
if cancel then return end
|
||||||
|
end
|
||||||
|
|
||||||
-- add weapon wear
|
-- add weapon wear
|
||||||
if tool_capabilities then
|
if tool_capabilities then
|
||||||
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
||||||
@ -2083,11 +2113,13 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
|
|
||||||
-- exit here if dead, special item check
|
-- exit here if dead, special item check
|
||||||
if weapon:get_name() == "mobs:pick_lava" then
|
if weapon:get_name() == "mobs:pick_lava" then
|
||||||
if check_for_death(self, "lava") then
|
if check_for_death(self, "lava", {type = "punch",
|
||||||
|
puncher = hitter}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if check_for_death(self, "hit") then
|
if check_for_death(self, "hit", {type = "punch",
|
||||||
|
puncher = hitter}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2220,6 +2252,10 @@ local mob_staticdata = function(self)
|
|||||||
self.rotate = math.rad(90)
|
self.rotate = math.rad(90)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
self.serialized_cmi_components = cmi.serialize_components(self.cmi_components)
|
||||||
|
end
|
||||||
|
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
for _,stat in pairs(self) do
|
||||||
@ -2228,7 +2264,8 @@ local mob_staticdata = function(self)
|
|||||||
|
|
||||||
if t ~= "function"
|
if t ~= "function"
|
||||||
and t ~= "nil"
|
and t ~= "nil"
|
||||||
and t ~= "userdata" then
|
and t ~= "userdata"
|
||||||
|
and _ ~= "cmi_components" then
|
||||||
tmp[_] = self[_]
|
tmp[_] = self[_]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2239,7 +2276,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- activate mob and reload settings
|
-- activate mob and reload settings
|
||||||
local mob_activate = function(self, staticdata, def)
|
local mob_activate = function(self, staticdata, def, dtime)
|
||||||
|
|
||||||
-- remove monsters in peaceful mode, or when no data
|
-- remove monsters in peaceful mode, or when no data
|
||||||
if (self.type == "monster" and peaceful_only) then
|
if (self.type == "monster" and peaceful_only) then
|
||||||
@ -2339,12 +2376,21 @@ local mob_activate = function(self, staticdata, def)
|
|||||||
self.object:set_properties(self)
|
self.object:set_properties(self)
|
||||||
set_yaw(self.object, (random(0, 360) - 180) / 180 * pi)
|
set_yaw(self.object, (random(0, 360) - 180) / 180 * pi)
|
||||||
update_tag(self)
|
update_tag(self)
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
self.cmi_components = cmi.activate_components(self.serialized_cmi_components)
|
||||||
|
cmi.notify_activate(self.object, dtime)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- main mob function
|
-- main mob function
|
||||||
local mob_step = function(self, dtime)
|
local mob_step = function(self, dtime)
|
||||||
|
|
||||||
|
if use_cmi then
|
||||||
|
cmi.notify_step(self.object, dtime)
|
||||||
|
end
|
||||||
|
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local yaw = 0
|
local yaw = 0
|
||||||
|
|
||||||
@ -2565,6 +2611,7 @@ minetest.register_entity(name, {
|
|||||||
attack_animals = def.attack_animals or false,
|
attack_animals = def.attack_animals or false,
|
||||||
specific_attack = def.specific_attack,
|
specific_attack = def.specific_attack,
|
||||||
owner_loyal = def.owner_loyal,
|
owner_loyal = def.owner_loyal,
|
||||||
|
cmi_is_mob = true,
|
||||||
|
|
||||||
on_blast = def.on_blast or do_tnt,
|
on_blast = def.on_blast or do_tnt,
|
||||||
|
|
||||||
@ -2572,8 +2619,8 @@ minetest.register_entity(name, {
|
|||||||
|
|
||||||
on_punch = mob_punch,
|
on_punch = mob_punch,
|
||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata, dtime)
|
||||||
return mob_activate(self, staticdata, def)
|
return mob_activate(self, staticdata, def, dtime)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
|
@ -2,3 +2,4 @@ default
|
|||||||
invisibility?
|
invisibility?
|
||||||
intllib?
|
intllib?
|
||||||
lucky_block?
|
lucky_block?
|
||||||
|
cmi?
|
||||||
|
@ -22,6 +22,7 @@ Lucky Blocks: 9
|
|||||||
|
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
- 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448
|
||||||
- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked
|
- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked
|
||||||
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack
|
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack
|
||||||
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
|
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
|
||||||
|
Loading…
Reference in New Issue
Block a user