mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-07-22 10:00:28 +02:00
Compare commits
9 Commits
ca34cc2274
...
83f0b901a4
Author | SHA1 | Date | |
---|---|---|---|
83f0b901a4 | |||
e4ac59609a | |||
7ac8506dda | |||
90df44aeaf | |||
25ab9591e4 | |||
8e6fa64f2d | |||
ce7c4c1449 | |||
08dcdf382a | |||
d2a4150dcb |
118
api.lua
118
api.lua
@ -28,7 +28,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20220514",
|
version = "20220804",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -106,8 +106,8 @@ local stuck_timeout = 3 -- how long before stuck mod starts searching
|
|||||||
local stuck_path_timeout = 5 -- how long will mob follow path before giving up
|
local stuck_path_timeout = 5 -- how long will mob follow path before giving up
|
||||||
|
|
||||||
-- default nodes
|
-- default nodes
|
||||||
local node_fire = "fire:basic_flame"
|
--local node_fire = "fire:basic_flame"
|
||||||
local node_permanent_flame = "fire:permanent_flame"
|
--local node_permanent_flame = "fire:permanent_flame"
|
||||||
local node_ice = "default:ice"
|
local node_ice = "default:ice"
|
||||||
local node_snowblock = "default:snowblock"
|
local node_snowblock = "default:snowblock"
|
||||||
local node_snow = "default:snow"
|
local node_snow = "default:snow"
|
||||||
@ -421,8 +421,7 @@ function mob_class:set_animation(anim, force)
|
|||||||
self.object:set_animation({
|
self.object:set_animation({
|
||||||
x = self.animation[anim .. "_start"],
|
x = self.animation[anim .. "_start"],
|
||||||
y = self.animation[anim .. "_end"]},
|
y = self.animation[anim .. "_end"]},
|
||||||
self.animation[anim .. "_speed"] or
|
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
|
||||||
self.animation.speed_normal or 15,
|
|
||||||
0, self.animation[anim .. "_loop"] ~= false)
|
0, self.animation[anim .. "_loop"] ~= false)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -751,7 +750,7 @@ local HORNY_AGAIN_TIME = 60 * 5 -- 5 minutes
|
|||||||
local CHILD_GROW_TIME = 60 * 20 -- 20 minutes
|
local CHILD_GROW_TIME = 60 * 20 -- 20 minutes
|
||||||
|
|
||||||
|
|
||||||
-- update nametag colour
|
-- update nametag and infotext
|
||||||
function mob_class:update_tag()
|
function mob_class:update_tag()
|
||||||
|
|
||||||
local col = "#00FF00"
|
local col = "#00FF00"
|
||||||
@ -785,8 +784,16 @@ function mob_class:update_tag()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.protected then
|
||||||
|
if self.protected == 2 then
|
||||||
|
text = text .. "\nProtection: Level 2"
|
||||||
|
else
|
||||||
|
text = text .. "\nProtection: Level 1"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.infotext = "Health: " .. self.health .. " / " .. self.hp_max
|
self.infotext = "Health: " .. self.health .. " / " .. self.hp_max
|
||||||
.. (self.owner == "" and "" or "\n" .. "Owner: " .. self.owner)
|
.. (self.owner == "" and "" or "\nOwner: " .. self.owner)
|
||||||
.. text
|
.. text
|
||||||
|
|
||||||
-- set changes
|
-- set changes
|
||||||
@ -999,15 +1006,13 @@ end
|
|||||||
-- get node but use fallback for nil or unknown
|
-- get node but use fallback for nil or unknown
|
||||||
local node_ok = function(pos, fallback)
|
local node_ok = function(pos, fallback)
|
||||||
|
|
||||||
fallback = fallback or mobs.fallback_node
|
|
||||||
|
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
|
||||||
if node and minetest.registered_nodes[node.name] then
|
if node and minetest.registered_nodes[node.name] then
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
return minetest.registered_nodes[fallback]
|
return minetest.registered_nodes[(fallback or mobs.fallback_node)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1067,7 +1072,7 @@ function mob_class:is_at_cliff()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local bnode = node_ok(blocker)
|
local bnode = node_ok(blocker, "air")
|
||||||
|
|
||||||
-- will we drop onto dangerous node?
|
-- will we drop onto dangerous node?
|
||||||
if is_node_dangerous(self, bnode.name) then
|
if is_node_dangerous(self, bnode.name) then
|
||||||
@ -1257,15 +1262,9 @@ function mob_class:do_jump()
|
|||||||
-- set y_pos to base of mob
|
-- set y_pos to base of mob
|
||||||
pos.y = pos.y + self.collisionbox[2]
|
pos.y = pos.y + self.collisionbox[2]
|
||||||
|
|
||||||
-- what is in front of mob?
|
-- what is in front of mob and above?
|
||||||
local nod = node_ok({
|
local nod = node_ok({x = pos.x + dir_x, y = pos.y + 0.5, z = pos.z + dir_z})
|
||||||
x = pos.x + dir_x, y = pos.y + 0.5, z = pos.z + dir_z
|
local nodt = node_ok({x = pos.x + dir_x, y = pos.y + 1.5, z = pos.z + dir_z})
|
||||||
})
|
|
||||||
|
|
||||||
-- what is above and in front?
|
|
||||||
local nodt = node_ok({
|
|
||||||
x = pos.x + dir_x, y = pos.y + 1.5, z = pos.z + dir_z
|
|
||||||
})
|
|
||||||
|
|
||||||
local blocked = minetest.registered_nodes[nodt.name].walkable
|
local blocked = minetest.registered_nodes[nodt.name].walkable
|
||||||
|
|
||||||
@ -1273,6 +1272,7 @@ function mob_class:do_jump()
|
|||||||
if nod.name:find("fence") or nod.name:find("gate") or nod.name:find("wall") then
|
if nod.name:find("fence") or nod.name:find("gate") or nod.name:find("wall") then
|
||||||
self.facing_fence = true
|
self.facing_fence = true
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
print("on: " .. self.standing_on
|
print("on: " .. self.standing_on
|
||||||
.. ", front: " .. nod.name
|
.. ", front: " .. nod.name
|
||||||
@ -1281,6 +1281,13 @@ print("on: " .. self.standing_on
|
|||||||
.. ", fence: " .. (self.facing_fence and "yes" or "no")
|
.. ", fence: " .. (self.facing_fence and "yes" or "no")
|
||||||
)
|
)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
-- if mob can leap then remove blockages and let them try
|
||||||
|
if self.can_leap == true then
|
||||||
|
blocked = false
|
||||||
|
self.facing_fence = false
|
||||||
|
end
|
||||||
|
|
||||||
-- jump if standing on solid node (not snow) and not blocked
|
-- jump if standing on solid node (not snow) and not blocked
|
||||||
if (self.walk_chance == 0 or minetest.registered_items[nod.name].walkable)
|
if (self.walk_chance == 0 or minetest.registered_items[nod.name].walkable)
|
||||||
and not blocked and not self.facing_fence and nod.name ~= node_snow then
|
and not blocked and not self.facing_fence and nod.name ~= node_snow then
|
||||||
@ -1451,8 +1458,7 @@ function mob_class:breed()
|
|||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8,
|
effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8, "heart.png", 3, 4, 1, 0.1)
|
||||||
"heart.png", 3, 4, 1, 0.1)
|
|
||||||
|
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 3)
|
local objs = minetest.get_objects_inside_radius(pos, 3)
|
||||||
local ent
|
local ent
|
||||||
@ -1473,6 +1479,7 @@ function mob_class:breed()
|
|||||||
local selfname = self.name:split(":")
|
local selfname = self.name:split(":")
|
||||||
|
|
||||||
if entname[1] == selfname[1] then
|
if entname[1] == selfname[1] then
|
||||||
|
|
||||||
entname = entname[2]:split("_")
|
entname = entname[2]:split("_")
|
||||||
selfname = selfname[2]:split("_")
|
selfname = selfname[2]:split("_")
|
||||||
|
|
||||||
@ -1560,7 +1567,7 @@ function mob_class:breed()
|
|||||||
self.base_selbox[4] * .5,
|
self.base_selbox[4] * .5,
|
||||||
self.base_selbox[5] * .5,
|
self.base_selbox[5] * .5,
|
||||||
self.base_selbox[6] * .5
|
self.base_selbox[6] * .5
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
-- tamed and owned by parents' owner
|
-- tamed and owned by parents' owner
|
||||||
ent2.child = true
|
ent2.child = true
|
||||||
@ -1636,13 +1643,10 @@ end
|
|||||||
function mob_class:day_docile()
|
function mob_class:day_docile()
|
||||||
|
|
||||||
if self.docile_by_day == false then
|
if self.docile_by_day == false then
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
elseif self.docile_by_day == true
|
elseif self.docile_by_day == true
|
||||||
and self.time_of_day > 0.2
|
and self.time_of_day > 0.2
|
||||||
and self.time_of_day < 0.8 then
|
and self.time_of_day < 0.8 then
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2637,7 +2641,7 @@ function mob_class:do_states(dtime)
|
|||||||
yaw = yaw_to_pos(self, p)
|
yaw = yaw_to_pos(self, p)
|
||||||
|
|
||||||
-- move towards enemy if beyond mob reach
|
-- move towards enemy if beyond mob reach
|
||||||
if dist > self.reach then
|
if dist > (self.reach + (self.reach_ext or 0)) then
|
||||||
|
|
||||||
-- path finding by rnd
|
-- path finding by rnd
|
||||||
if self.pathfinding -- only if mob has pathfinding enabled
|
if self.pathfinding -- only if mob has pathfinding enabled
|
||||||
@ -2649,8 +2653,13 @@ function mob_class:do_states(dtime)
|
|||||||
-- distance padding to stop spinning mob
|
-- distance padding to stop spinning mob
|
||||||
local pad = abs(p.x - s.x) + abs(p.z - s.z)
|
local pad = abs(p.x - s.x) + abs(p.z - s.z)
|
||||||
|
|
||||||
|
self.reach_ext = 0 -- extended ready off by default
|
||||||
|
|
||||||
if self.at_cliff or pad < 0.2 then
|
if self.at_cliff or pad < 0.2 then
|
||||||
|
|
||||||
|
-- when on top of player extend reach slightly so player can
|
||||||
|
-- still be attacked.
|
||||||
|
self.reach_ext = 0.8
|
||||||
self:set_velocity(0)
|
self:set_velocity(0)
|
||||||
self:set_animation("stand")
|
self:set_animation("stand")
|
||||||
else
|
else
|
||||||
@ -3279,7 +3288,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
if type(self.armor) == "table" then
|
if type(self.armor) == "table" then
|
||||||
armor = table_copy(self.armor)
|
armor = table_copy(self.armor)
|
||||||
else
|
else
|
||||||
armor = {fleshy = self.armor} -- immortal = 1
|
armor = {fleshy = self.armor, immortal = 1}
|
||||||
end
|
end
|
||||||
self.object:set_armor_groups(armor)
|
self.object:set_armor_groups(armor)
|
||||||
|
|
||||||
@ -3412,8 +3421,7 @@ function mob_class:on_step(dtime, moveresult)
|
|||||||
|
|
||||||
-- if standing inside solid block then jump to escape
|
-- if standing inside solid block then jump to escape
|
||||||
if minetest.registered_nodes[self.standing_in].walkable
|
if minetest.registered_nodes[self.standing_in].walkable
|
||||||
and minetest.registered_nodes[self.standing_in].drawtype
|
and minetest.registered_nodes[self.standing_in].drawtype == "normal" then
|
||||||
== "normal" then
|
|
||||||
|
|
||||||
self.object:set_velocity({
|
self.object:set_velocity({
|
||||||
x = 0,
|
x = 0,
|
||||||
@ -3587,6 +3595,7 @@ minetest.register_entity(name, setmetatable({
|
|||||||
on_flop = def.on_flop,
|
on_flop = def.on_flop,
|
||||||
do_custom = def.do_custom,
|
do_custom = def.do_custom,
|
||||||
jump_height = def.jump_height,
|
jump_height = def.jump_height,
|
||||||
|
can_leap = def.can_leap,
|
||||||
drawtype = def.drawtype, -- DEPRECATED, use rotate instead
|
drawtype = def.drawtype, -- DEPRECATED, use rotate instead
|
||||||
rotate = rad(def.rotate or 0), -- 0=front 90=side 180=back 270=side2
|
rotate = rad(def.rotate or 0), -- 0=front 90=side 180=back 270=side2
|
||||||
glow = def.glow,
|
glow = def.glow,
|
||||||
@ -3671,6 +3680,7 @@ minetest.register_entity(name, setmetatable({
|
|||||||
stay_near = def.stay_near,
|
stay_near = def.stay_near,
|
||||||
randomly_turn = def.randomly_turn ~= false,
|
randomly_turn = def.randomly_turn ~= false,
|
||||||
ignore_invisibility = def.ignore_invisibility,
|
ignore_invisibility = def.ignore_invisibility,
|
||||||
|
messages = def.messages,
|
||||||
|
|
||||||
on_spawn = def.on_spawn,
|
on_spawn = def.on_spawn,
|
||||||
|
|
||||||
@ -3857,7 +3867,7 @@ function mobs:add_mob(pos, def)
|
|||||||
ent.base_selbox[4] * .5,
|
ent.base_selbox[4] * .5,
|
||||||
ent.base_selbox[5] * .5,
|
ent.base_selbox[5] * .5,
|
||||||
ent.base_selbox[6] * .5
|
ent.base_selbox[6] * .5
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ent.child = true
|
ent.child = true
|
||||||
@ -4659,8 +4669,7 @@ function mobs:protect(self, clicker)
|
|||||||
|
|
||||||
pos.y = pos.y + self.collisionbox[2] + 0.5
|
pos.y = pos.y + self.collisionbox[2] + 0.5
|
||||||
|
|
||||||
effect(self.object:get_pos(), 25, "mobs_protect_particle.png",
|
effect(self.object:get_pos(), 25, "mobs_protect_particle.png", 0.5, 4, 2, 15)
|
||||||
0.5, 4, 2, 15)
|
|
||||||
|
|
||||||
self:mob_sound("mobs_spell")
|
self:mob_sound("mobs_spell")
|
||||||
|
|
||||||
@ -4839,7 +4848,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- compatibility function for old entities to new modpack entities
|
-- compatibility function for old mobs entities to new mobs_redo modpack
|
||||||
function mobs:alias_mob(old_name, new_name)
|
function mobs:alias_mob(old_name, new_name)
|
||||||
|
|
||||||
-- check old_name entity doesnt already exist
|
-- check old_name entity doesnt already exist
|
||||||
@ -4870,3 +4879,44 @@ function mobs:alias_mob(old_name, new_name)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- admin command to remove untamed mobs around players
|
||||||
|
minetest.register_chatcommand("clear_mobs", {
|
||||||
|
params = "<text>",
|
||||||
|
description = "Remove untamed mobs from around players.",
|
||||||
|
privs = {server = true},
|
||||||
|
|
||||||
|
func = function (name, param)
|
||||||
|
|
||||||
|
local count = 0
|
||||||
|
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
|
||||||
|
if player then
|
||||||
|
|
||||||
|
local pos = player:get_pos()
|
||||||
|
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 28)
|
||||||
|
|
||||||
|
for _, obj in pairs(objs) do
|
||||||
|
|
||||||
|
if obj then
|
||||||
|
|
||||||
|
local ent = obj:get_luaentity()
|
||||||
|
|
||||||
|
-- only remove mobs redo mobs that are not tamed
|
||||||
|
if ent and ent._cmi_is_mob and ent.tamed ~= true then
|
||||||
|
|
||||||
|
remove_mob(ent, true)
|
||||||
|
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.chat_send_player(name, S("@1 mobs removed.", count))
|
||||||
|
end
|
||||||
|
})
|
||||||
|
5
api.txt
5
api.txt
@ -42,6 +42,8 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
randomly turn while walking or standing.
|
randomly turn while walking or standing.
|
||||||
'jump' when true allows your mob to jump updwards.
|
'jump' when true allows your mob to jump updwards.
|
||||||
'jump_height' holds the height your mob can jump, 0 to disable jumping.
|
'jump_height' holds the height your mob can jump, 0 to disable jumping.
|
||||||
|
'can_leap' when true obstacles like fences or pits wont stop a mob
|
||||||
|
from trying to jump out.
|
||||||
'stepheight' height of a block that your mob can easily walk up onto,
|
'stepheight' height of a block that your mob can easily walk up onto,
|
||||||
defaults to 1.1.
|
defaults to 1.1.
|
||||||
'fly' when true allows your mob to fly around instead of walking.
|
'fly' when true allows your mob to fly around instead of walking.
|
||||||
@ -223,6 +225,9 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
'fly_start' when a mob is flying.
|
'fly_start' when a mob is flying.
|
||||||
'fly_end'
|
'fly_end'
|
||||||
'fly_speed'
|
'fly_speed'
|
||||||
|
'jump_start' when a mob is jumping
|
||||||
|
'jump_end'
|
||||||
|
'jump_speed'
|
||||||
'punch_start' when a mob melee attacks.
|
'punch_start' when a mob melee attacks.
|
||||||
'punch_end'
|
'punch_end'
|
||||||
'punch_speed'
|
'punch_speed'
|
||||||
|
Reference in New Issue
Block a user