Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit 62fbe19

Browse files
committed
new special spawning,spawn only if there are no others of the same type(limited with max), fix issue #524
1 parent 03bd2fa commit 62fbe19

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

mods/mobs/api.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,62 @@ end -- END mobs:register_mob function
21422142

21432143
mobs.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+
21452201
function 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

mods/mobs/mese_dragon.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ minetest.register_node("mobs:mese_dragon_spawner", {
118118
})
119119
})
120120

121-
--(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, spawn_in_area)
122-
-- spawn on mobs:mese_dragon_spawner between 1 and 20 light, interval 300, 1 chance, 1 mese_dragon_spawner in area up to 31000 in height
123-
mobs:spawn_specific("mobs:mese_dragon", {"mobs:mese_dragon_spawner"}, {"air"}, 1, 20, 300, 1, 100, -31000, 31000, true)
121+
--(name, nodes, neighbors, interval, chance, active_object_count)
122+
-- spawn on mobs:mese_dragon_spawner, interval 300, 1 chance, 1 mese_dragon_spawner
123+
mobs:spawn_special("mobs:mese_dragon", {"mobs:mese_dragon_spawner"}, {"air"}, 300, 1, 1)
124124
mobs:register_egg("mobs:mese_dragon", "Mese Dragon", "mobs_mese_dragon_inv.png", 1)

mods/mobs/pumpkins.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ minetest.register_node("mobs:pumpboom_spawner", {
133133
mobs:spawn_specific("mobs:pumpking", {"mobs:pumpking_spawner"}, {"air"}, 1, 20, 300, 1, 100, -31000, 31000, true)
134134
mobs:register_egg("mobs:pumpking", "Pumpking", "mobs_pumpking_inv.png", 1)
135135

136-
-- spawn on mobs:pumpboom_spawner between 1 and 20 light, 4 interval, 1 chance, 100 pumpboom in area up to 31000 in height
137-
mobs:spawn_specific("mobs:pumpboom", {"mobs:pumpboom_spawner"}, {"air"}, 1, 20, 10, 4, 100, -31000, 31000, true)
136+
-- spawn on mobs:pumpboom_spawner, 4 interval, 1 chance, 30 pumpboom in area
137+
mobs:spawn_special("mobs:pumpboom", {"mobs:pumpboom_spawner"}, {"air"}, 10, 4, 30)
138138
mobs:register_egg("mobs:pumpboom", "Pumpboom", "mobs_pumpboom_inv.png", 1)

0 commit comments

Comments
 (0)