2022-08-12 22:17:42 -07:00
|
|
|
--------------
|
|
|
|
-- Spawning --
|
|
|
|
--------------
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
local function is_value_in_table(tbl, val)
|
|
|
|
for _, v in pairs(tbl) do
|
|
|
|
if v == val then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-10-22 01:27:58 -07:00
|
|
|
local common_spawn_chance = tonumber(minetest.settings:get("animalia_common_chance")) or 20000
|
|
|
|
|
|
|
|
local ambient_spawn_chance = tonumber(minetest.settings:get("animalia_ambient_chance")) or 6000
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
local pest_spawn_chance = tonumber(minetest.settings:get("animalia_pest_chance")) or 2000
|
2022-10-22 01:27:58 -07:00
|
|
|
|
|
|
|
local predator_spawn_chance = tonumber(minetest.settings:get("animalia_predator_chance")) or 30000
|
|
|
|
|
2022-08-12 22:17:42 -07:00
|
|
|
-- Get Biomes --
|
|
|
|
|
|
|
|
local chicken_biomes = {}
|
|
|
|
|
|
|
|
local frog_biomes = {}
|
|
|
|
|
|
|
|
local pig_biomes = {}
|
|
|
|
|
|
|
|
local function insert_all(tbl, tbl2)
|
|
|
|
for i = 1, #tbl2 do
|
|
|
|
table.insert(tbl, tbl2[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(function()
|
|
|
|
insert_all(chicken_biomes, animalia.registered_biome_groups["grassland"].biomes)
|
|
|
|
insert_all(chicken_biomes, animalia.registered_biome_groups["tropical"].biomes)
|
|
|
|
insert_all(pig_biomes, animalia.registered_biome_groups["temperate"].biomes)
|
|
|
|
insert_all(pig_biomes, animalia.registered_biome_groups["boreal"].biomes)
|
|
|
|
insert_all(frog_biomes, animalia.registered_biome_groups["swamp"].biomes)
|
|
|
|
insert_all(frog_biomes, animalia.registered_biome_groups["tropical"].biomes)
|
|
|
|
end)
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:chicken", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 3,
|
|
|
|
max_group = 5,
|
2022-10-21 15:53:00 -07:00
|
|
|
biomes = chicken_biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
creatura.register_abm_spawn("animalia:cat", {
|
|
|
|
chance = common_spawn_chance,
|
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
|
|
|
min_group = 1,
|
|
|
|
max_group = 2,
|
|
|
|
nodes = {"group:soil"},
|
|
|
|
neighbors = {"group:wood"}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:cow", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 3,
|
|
|
|
max_group = 4,
|
2022-10-21 15:53:00 -07:00
|
|
|
biomes = animalia.registered_biome_groups["grassland"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
|
|
|
neighbors = {"air", "group:grass", "group:flora"}
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:fox", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = predator_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-10-17 17:23:26 -07:00
|
|
|
min_group = 1,
|
|
|
|
max_group = 2,
|
2022-10-21 15:53:00 -07:00
|
|
|
biomes = animalia.registered_biome_groups["boreal"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:horse", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
|
|
|
min_group = 3,
|
|
|
|
max_group = 4,
|
|
|
|
biomes = animalia.registered_biome_groups["grassland"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
|
|
|
neighbors = {"air", "group:grass", "group:flora"}
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-17 17:23:26 -07:00
|
|
|
creatura.register_abm_spawn("animalia:rat", {
|
2023-03-15 14:27:40 -07:00
|
|
|
chance = pest_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
interval = 60,
|
2022-10-17 17:23:26 -07:00
|
|
|
min_height = -1,
|
|
|
|
max_height = 1024,
|
|
|
|
min_group = 1,
|
|
|
|
max_group = 3,
|
|
|
|
spawn_in_nodes = true,
|
|
|
|
nodes = {"group:crop"}
|
|
|
|
})
|
|
|
|
|
|
|
|
creatura.register_abm_spawn("animalia:owl", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = predator_spawn_chance,
|
2022-10-17 17:23:26 -07:00
|
|
|
interval = 60,
|
|
|
|
min_height = 3,
|
|
|
|
max_height = 1024,
|
|
|
|
min_group = 1,
|
|
|
|
max_group = 1,
|
|
|
|
spawn_cap = 1,
|
|
|
|
nodes = {"group:leaves"}
|
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:pig", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 2,
|
2022-10-21 15:53:00 -07:00
|
|
|
max_group = 3,
|
|
|
|
biomes = pig_biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:reindeer", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 6,
|
2022-10-21 15:53:00 -07:00
|
|
|
max_group = 8,
|
|
|
|
biomes = animalia.registered_biome_groups["boreal"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:sheep", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 3,
|
|
|
|
max_group = 6,
|
2022-10-21 15:53:00 -07:00
|
|
|
biomes = animalia.registered_biome_groups["grassland"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
|
|
|
neighbors = {"air", "group:grass", "group:flora"}
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:turkey", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = common_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_group = 3,
|
|
|
|
max_group = 4,
|
2022-10-21 15:53:00 -07:00
|
|
|
biomes = animalia.registered_biome_groups["boreal"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:wolf", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = predator_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = 0,
|
|
|
|
max_height = 1024,
|
|
|
|
min_group = 2,
|
|
|
|
max_group = 3,
|
|
|
|
biomes = animalia.registered_biome_groups["boreal"].biomes,
|
|
|
|
nodes = {"group:soil"},
|
2022-10-17 17:23:26 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Ambient Spawning
|
|
|
|
|
|
|
|
creatura.register_abm_spawn("animalia:bat", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = ambient_spawn_chance,
|
2022-10-17 17:23:26 -07:00
|
|
|
interval = 30,
|
2022-08-12 22:17:42 -07:00
|
|
|
min_light = 0,
|
2022-10-17 17:23:26 -07:00
|
|
|
min_height = -31000,
|
|
|
|
max_height = 1,
|
|
|
|
min_group = 3,
|
|
|
|
max_group = 5,
|
|
|
|
spawn_cap = 6,
|
|
|
|
nodes = {"group:stone"}
|
|
|
|
})
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
creatura.register_abm_spawn("animalia:song_bird", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = ambient_spawn_chance,
|
2022-10-17 17:23:26 -07:00
|
|
|
interval = 60,
|
|
|
|
min_light = 0,
|
|
|
|
min_height = 1,
|
|
|
|
max_height = 1024,
|
2022-11-05 21:07:25 -07:00
|
|
|
min_group = 6,
|
|
|
|
max_group = 12,
|
2023-03-15 14:27:40 -07:00
|
|
|
spawn_cap = 6,
|
|
|
|
nodes = {"group:leaves", "animalia:nest_song_bird"},
|
2022-11-05 21:07:25 -07:00
|
|
|
neighbors = {"group:leaves"}
|
2022-08-12 22:17:42 -07:00
|
|
|
})
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
creatura.register_on_spawn("animalia:song_bird", function(self, pos)
|
2022-10-17 17:23:26 -07:00
|
|
|
local nests = minetest.find_nodes_in_area_under_air(
|
2023-03-15 14:27:40 -07:00
|
|
|
{x = pos.x - 16, y = pos.y - 16, z = pos.z - 16},
|
|
|
|
{x = pos.x + 16, y = pos.y + 16, z = pos.z + 16},
|
2022-10-17 17:23:26 -07:00
|
|
|
"animalia:nest_song_bird"
|
|
|
|
)
|
2023-03-15 14:27:40 -07:00
|
|
|
if nests[1] then return end
|
2022-08-12 22:17:42 -07:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name == "air" then
|
|
|
|
minetest.set_node(pos, {name = "animalia:nest_song_bird"})
|
|
|
|
else
|
|
|
|
local nodes = minetest.find_nodes_in_area_under_air(
|
|
|
|
{x = pos.x - 3, y = pos.y - 3, z = pos.z - 3},
|
|
|
|
{x = pos.x + 3, y = pos.y + 7, z = pos.z + 3},
|
|
|
|
"group:leaves"
|
|
|
|
)
|
|
|
|
if nodes[1] then
|
|
|
|
pos = nodes[1]
|
|
|
|
minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "animalia:nest_song_bird"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-10-17 17:23:26 -07:00
|
|
|
creatura.register_abm_spawn("animalia:frog", {
|
2023-03-15 14:27:40 -07:00
|
|
|
chance = ambient_spawn_chance * 0.75,
|
2022-10-17 17:23:26 -07:00
|
|
|
interval = 60,
|
|
|
|
min_light = 0,
|
|
|
|
min_height = -1,
|
|
|
|
max_height = 8,
|
2023-03-15 14:27:40 -07:00
|
|
|
min_group = 1,
|
|
|
|
max_group = 2,
|
2022-10-17 17:23:26 -07:00
|
|
|
neighbors = {"group:water"},
|
|
|
|
nodes = {"group:soil"}
|
2022-10-21 15:53:00 -07:00
|
|
|
})
|
|
|
|
|
2023-03-15 14:27:40 -07:00
|
|
|
creatura.register_on_spawn("animalia:frog", function(self, pos)
|
|
|
|
local biome_data = minetest.get_biome_data(pos)
|
|
|
|
local biome_name = minetest.get_biome_name(biome_data.biome)
|
|
|
|
|
|
|
|
if is_value_in_table(animalia.registered_biome_groups["tropical"].biomes, biome_name) then
|
|
|
|
self:set_mesh(3)
|
|
|
|
elseif is_value_in_table(animalia.registered_biome_groups["temperate"].biomes, biome_name)
|
|
|
|
or is_value_in_table(animalia.registered_biome_groups["boreal"].biomes, biome_name) then
|
|
|
|
self:set_mesh(1)
|
|
|
|
elseif is_value_in_table(animalia.registered_biome_groups["grassland"].biomes, biome_name) then
|
|
|
|
self:set_mesh(2)
|
|
|
|
else
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
|
|
|
|
local activate = self.activate_func
|
|
|
|
|
|
|
|
activate(self)
|
|
|
|
end)
|
|
|
|
|
2022-10-21 15:53:00 -07:00
|
|
|
creatura.register_abm_spawn("animalia:tropical_fish", {
|
2022-10-22 01:27:58 -07:00
|
|
|
chance = ambient_spawn_chance,
|
2022-10-21 15:53:00 -07:00
|
|
|
min_height = -128,
|
|
|
|
max_height = 1,
|
|
|
|
min_group = 6,
|
|
|
|
max_group = 12,
|
|
|
|
nodes = {"group:water"},
|
|
|
|
neighbors = {"group:coral"}
|
2022-08-27 20:15:57 -07:00
|
|
|
})
|