@@ -2142,6 +2142,62 @@ end -- END mobs:register_mob function
21422142
21432143mobs .spawning_mobs = {}
21442144
2145+ function mobs :spawn_special (name , nodes , neighbors , interval , chance , active_object_count ) -- MFF to special mobs
2146+ mobs .spawning_mobs [name ] = true
2147+ -- chance override in minetest.conf for registered mob
2148+ local new_chance = tonumber (minetest .setting_get (name .. " _chance" ))
2149+ if new_chance ~= nil then
2150+ if new_chance == 0 then
2151+ return
2152+ end
2153+ chance = new_chance
2154+ end
2155+
2156+ minetest .register_abm ({
2157+ nodenames = nodes ,
2158+ neighbors = neighbors ,
2159+ interval = interval ,
2160+ chance = chance ,
2161+ action = function (pos , node , _ , active_object_count_wider )
2162+ -- do not spawn if too many active entities in area
2163+ local count = 0
2164+ local objs = minetest .get_objects_inside_radius (pos , 60 )
2165+ for k , obj in pairs (objs ) do
2166+ if obj :get_luaentity () ~= nil and obj :get_luaentity ().name == name then
2167+ count = count + 1
2168+ end
2169+ end
2170+ if count > active_object_count then
2171+ return
2172+ end
2173+ -- spawn above node
2174+ pos .y = pos .y + 1
2175+ -- only spawn away from player
2176+ local objs = minetest .get_objects_inside_radius (pos , 10 )
2177+ for _ ,oir in pairs (objs ) do
2178+ if oir :is_player () then
2179+ return
2180+ end
2181+ end
2182+
2183+ -- are we spawning inside solid nodes?
2184+ if minetest .registered_nodes [node_ok (pos ).name ].walkable == true then
2185+ return
2186+ end
2187+
2188+ pos .y = pos .y + 1
2189+ if minetest .registered_nodes [node_ok (pos ).name ].walkable == true then
2190+ return
2191+ end
2192+
2193+ -- spawn mob half block higher than ground
2194+ pos .y = pos .y - 0.5
2195+ minetest .add_entity (pos , name )
2196+ end
2197+ })
2198+ end
2199+
2200+
21452201function mobs :spawn_specific (name , nodes , neighbors , min_light , max_light ,
21462202 interval , chance , active_object_count , min_height , max_height , spawn_in_area , day_toggle ) -- MFF crabman "spawn_in_area"
21472203
0 commit comments