/usr/share/games/minetest/mods/mobf/mobf/api.lua is in minetest-mod-mobf-core 2.5.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | -------------------------------------------------------------------------------
-- Mob Framework Mod by Sapier
--
-- You may copy, use, modify or do nearly anything except removing this
-- copyright notice.
-- And of course you are NOT allow to pretend you have written it.
--
--! @file api.lua
--! @brief api functions to be used by other mods
--! @copyright Sapier
--! @author Sapier
--! @date 2012-12-27
--
-- Contact sapier a t gmx net
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- @function mobf_register_on_death_callback(callback)
--
--! @brief get version of mob framework
--! @ingroup framework_mob
--
--! @param callback callback to register
--! @return true/false
-------------------------------------------------------------------------------
function mobf_register_on_death_callback(callback)
return fighting.register_on_death_callback(callback)
end
-------------------------------------------------------------------------------
-- @function mobf_get_mob_definition(mobname)
--
--! @brief get COPY of mob definition
--! @ingroup framework_mob
--
--! @return mobf version
-------------------------------------------------------------------------------
function mobf_get_mob_definition(mobname)
if mobf_rtd.registred_mob_data[mobname] ~= nil then
local copy = minetest.serialize(mobf_rtd.registred_mob_data[mobname])
return minetest.deserialize(copy)
end
return nil
end
-------------------------------------------------------------------------------
-- @function mobf_get_version()
--
--! @brief get version of mob framework
--! @ingroup framework_mob
--
--! @return mobf version
-------------------------------------------------------------------------------
function mobf_get_version()
return mobf_version
end
------------------------------------------------------------------------------
-- @function mobf_add_mob(mob)
--
--! @brief register a mob within mob framework
--! @ingroup framework_mob
--
--! @param mob a mob declaration
-------------------------------------------------------------------------------
function mobf_add_mob(mob)
if not mobf.check_definition(mob) then
minetest.log(LOGLEVEL_ERROR,"MOBF: mob definition is invalid!")
return
end
--check if mob is blacklisted
--mobs from the blacklist are pre-registered at startup
if mobf_contains(mobf_rtd.registred_mob,mob.modname.. ":"..mob.name) then
mobf.blacklisthandling(mob)
return false
end
--if a random drop is specified for this mob register it
if mob.random_drop ~= nil then
random_drop.register(mob.random_drop)
end
--create default entity
minetest.log(LOGLEVEL_INFO,"MOBF: adding: " .. mob.name)
mob_state.prepare_states(mob)
mobf.register_entity(":" .. mob.modname .. ":"..mob.name,
graphics.graphics_by_statename(mob,"default"), mob)
--add compatibility entity to replace old __default entities by new ones
minetest.log(LOGLEVEL_INFO,"MOBF: registering compatibility entity: >" ..
":" .. mob.modname .. ":"..mob.name .. "__default" .. "<")
minetest.register_entity(":" .. mob.modname .. ":"..mob.name .. "__default",
{
replacement_name = mob.modname .. ":"..mob.name,
on_activate = function(self,staticdata)
local pos = self.object:getpos()
if pos ~= nil then
local newobject = minetest.add_entity(pos,self.replacement_name)
local spawned_entity = mobf_find_entity(newobject)
if spawned_entity ~= nil then
spawned_entity.dynamic_data.initialized = false
if (staticdata ~= "") then
spawned_entity.dynamic_data.last_static_data = staticdata
end
end
end
self.object:remove()
end,
})
mobf.register_mob_item(mob.name,mob.modname,mob.generic.description, mob.generic.itemimage)
--check if a movement pattern was specified
if mobf_rtd.movement_patterns[mob.movement.pattern] == nil then
minetest.log(LOGLEVEL_WARNING,"MOBF: no movement pattern specified!")
end
if mob.spawning ~= nil then
minetest.log(LOGLEVEL_WARNING,"MOBF: \"" .. mob.name ..
"\" is still using mob internal spawning," ..
" this is DEPRECATED and going to be removed soon!")
spawning.register_mob(mob)
end
--register factions required by mob
mobf_factions.setupmob(mob.factions)
if mob.generic.stepheight == nil then
mob.generic.stepheight = 0
end
--register mob name to internal data structures
table.insert(mobf_rtd.registred_mob,mob.modname.. ":"..mob.name)
mobf_rtd.registred_mob_data[mob.modname.. ":"..mob.name] = mob;
return true
end
------------------------------------------------------------------------------
-- @function mobf_is_known_mob(name)
--
--! @brief check if mob of name is known
--! @ingroup framework_mob
--
--! @param name name to check if it's a mob
--! @return true/false
-------------------------------------------------------------------------------
function mobf_is_known_mob(name)
for i,val in ipairs(mobf_rtd.registred_mob) do
if name == val then
return true
end
end
return false
end
------------------------------------------------------------------------------
-- @function mobf_register_environment(name,environment)
--
--! @brief register an environment to mob framework
--! @ingroup framework_mob
--
--! @param name of environment
--! @param environment specification
--! @return true/false
-------------------------------------------------------------------------------
function mobf_register_environment(name,environment)
return environment.register(name,environment)
end
------------------------------------------------------------------------------
-- @function mobf_environment_by_name(name)
--
--! @brief get environment by name
--! @ingroup framework_mob
--
--! @param name of environment
--! @return environment definition
-------------------------------------------------------------------------------
function mobf_environment_by_name(name)
if environment_list[name] ~= nil then
return minetest.deserialize(minetest.serialize(environment_list[name]))
else
return nil
end
end
------------------------------------------------------------------------------
-- @function mobf_probab_movgen_register_pattern(pattern)
--
--! @brief register an movement pattern for probabilistic movement gen
--! @ingroup framework_mob
--
--! @param pattern to register (see pattern specification)
--! @return true/false
-------------------------------------------------------------------------------
function mobf_probab_movgen_register_pattern(pattern)
return movement_gen.register_pattern(pattern)
end
------------------------------------------------------------------------------
-- @function mobf_spawner_register(name,spawndef)
--
--! @brief register a spawndef to adv_spawning
--! @ingroup framework_mob
--
--! @param name of spawner
--! @param mobname name of mob to register spawner for
--! @param spawndef defintion of spawner
--! @return true/false
-------------------------------------------------------------------------------
function mobf_spawner_register(name,mobname,spawndef)
--check if spawning is enabled
if minetest.world_setting_get("mobf_disable_animal_spawning") then
return false
end
--check if mob is blacklisted
if mobf_contains(mobf_rtd.registred_mob,mobname) then
minetest.log(LOGLEVEL_NOTICE,"MOBF: " .. mobname .. " is blacklisted, not adding spawner")
return false
end
local customcheck = spawndef.custom_check
spawndef.custom_check = function(pos,spawndef)
local entities_around = spawndef.entities_around
if entities_around ~= nil then
for i=1,#entities_around,1 do
--only do this check if relevant area is larger then activity range
if entities_around[i].distance > adv_spawning.active_range then
local count = spawning.count_deactivated_mobs(
mobname,
pos,
entities_around[i].distance)
local entity_active =
minetest.get_objects_inside_radius(pos,
entities_around[i].distance)
for j=1,#entity_active,1 do
local entity = entity_active[j]:get_luaentity()
if entity ~= nil then
if entity.name == entities_around[i].entityname then
count = count +1
end
if count + count > entities_around[i].threshold then
break
end
end
end
if entities_around[i].type == "MIN" and
count < entities_around[i].threshold then
dbg_mobf.mobf_core_lvl3(
"MOBF: MIN around not met: already: " .. count ..
" relevant entities around")
return false, "not enough entities around, only: " .. count .. " < " .. entities_around[i].threshold
end
if entities_around[i].type == "MAX" and
count > entities_around[i].threshold then
dbg_mobf.mobf_core_lvl3(
"MOBF: MAX around not met: already: " .. count ..
" relevant entities around")
return false, "too many entities around, " .. count .. " > " .. entities_around[i].threshold
end
end
end
end
if type(customcheck) == "function" and not customcheck(pos,spawndef) then
return false, "customcheck failed"
end
return true, "entities around and customcheck ok"
end
--register
adv_spawning.register(name,spawndef)
end
|