From 87511cf25173fa966b44a8e10e093f2707330f27 Mon Sep 17 00:00:00 2001 From: berengma Date: Sun, 7 Feb 2021 16:27:49 +0100 Subject: [PATCH] better support for islands - better spawning --- animals/crocodile.lua | 3 ++- api.lua | 12 ++++++++++++ chatcommands.lua | 20 ++++++++++++++++++++ compat.lua | 19 +++++++++++++++++++ init.lua | 4 +++- spawn.lua | 6 ++++-- 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 compat.lua diff --git a/animals/crocodile.lua b/animals/crocodile.lua index bdee884..eaf9e97 100644 --- a/animals/crocodile.lua +++ b/animals/crocodile.lua @@ -49,6 +49,7 @@ local function croc_brain(self) end if mobkit.timer(self,1) then + local prty = mobkit.get_queue_priority(self) if not mobkit.recall(self,"landlife") and not mobkit.recall(self,"waterlife") then mobkit.remember(self,"waterlife",os.time()) @@ -68,7 +69,7 @@ local function croc_brain(self) end end - local prty = mobkit.get_queue_priority(self) + if prty < 20 then local target = mobkit.get_nearby_player(self) diff --git a/api.lua b/api.lua index c390549..6b77a90 100644 --- a/api.lua +++ b/api.lua @@ -98,6 +98,18 @@ function water_life_get_biome_data(pos) return biome end +-- get list of biome names +function water_life.get_biomes() + + local biomes = {} + + for k,v in pairs(minetest.registered_biomes) do + table.insert(biomes, k) + end + + if #biomes > 0 then return biomes else return nil end + +end -- returns closest enemy or player, if player is true enemies must be in entity definition: predators = {[name1]=1,[name2]=1,.....} diff --git a/chatcommands.lua b/chatcommands.lua index 39c056f..3a908c0 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -73,6 +73,26 @@ minetest.register_chatcommand("wl_kill", { end }) + +minetest.register_chatcommand("wl_lb", { + params = "", + description = "list biomes", + privs = {interact = true}, + func = function() + + + local biom = water_life.get_biomes() + + if not biom then return end + + for i=1,#biom,1 do + minetest.chat_send_all(dump(i)..") "..dump(biom[i])) + + end + + end +}) + minetest.register_chatcommand("wl_test", { params = "", description = "test", diff --git a/compat.lua b/compat.lua new file mode 100644 index 0000000..b5103f7 --- /dev/null +++ b/compat.lua @@ -0,0 +1,19 @@ + +-- check for islands mod +if minetest.get_modpath("islands") then + + local bnames = water_life.get_biomes() + water_life.spawn_on_islands = true + + if bnames then + + for i=1,#bnames,1 do + local keep = string.match(bnames[i],"savanna") or string.match(bnames[i],"rainforest") + if not keep then minetest.unregister_biome(bnames[i]) end + end + end +end + + + + diff --git a/init.lua b/init.lua index d915630..8e66e61 100644 --- a/init.lua +++ b/init.lua @@ -6,7 +6,7 @@ ----------------------------------------------------------- water_life = {} -water_life.version = "210206" +water_life.version = "210207" water_life.shark_food = {} water_life.repellant = {} water_life.gull_bait = {} @@ -43,7 +43,9 @@ water_life.bloody = minetest.settings:get_bool("water_life_bloody") or true local path = minetest.get_modpath(minetest.get_current_modname()) + dofile(path.."/api.lua") -- load water_life api +dofile(path.."/compat.lua") dofile(path.."/paths.lua") -- load pathfinding if water_life.muddy_water then dofile(path.."/mapgen.lua") end -- load muddy_water dofile(path.."/crafts.lua") -- load crafts diff --git a/spawn.lua b/spawn.lua index a6f5b77..bde307d 100644 --- a/spawn.lua +++ b/spawn.lua @@ -379,11 +379,13 @@ local function spawnstep(dtime) --minetest.chat_send_all(dump(minetest.pos_to_string(surface)).." "..dump(minetest.pos_to_string(ground))) mobname = 'water_life:fish' --local nearlife = water_life.count_objects(pos2,24,"water_life:piranha") - if water_life.fish_spawn_rate >= random(1000) and ((animal.all < (water_life.maxmobs-5)) or getcount(animal[mobname]) < 5) and (liquidflag == "river" or liquidflag == "muddy") then + if water_life.fish_spawn_rate >= random(1000) and ((animal.all < (water_life.maxmobs-5)) or getcount(animal[mobname]) < 5) and (((liquidflag == "river" or liquidflag == "muddy")) or (water_life.spawn_on_islands and not water_life.check_for_pool(nil,2,3,pos2) and + water_life.check_for_pool(nil,2,16,pos2))) then local table = minetest.get_biome_data(pos) - if not water_life.dangerous and table and water_life.piranha_biomes[minetest.get_biome_name(table.biome)] then + if not water_life.dangerous and ((table and water_life.piranha_biomes[minetest.get_biome_name(table.biome)]) + or water_life.spawn_on_islands) then mobname = "water_life:piranha" end