From 662caac9ae01df35abf3cb93eba4f4f45943eb0c Mon Sep 17 00:00:00 2001 From: berengma Date: Sun, 21 Jun 2020 18:44:54 +0200 Subject: [PATCH] fix strange spawn bug --- api.lua | 3 +++ init.lua | 2 +- spawn.lua | 36 ++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/api.lua b/api.lua index 5f31cc0..ac223b4 100644 --- a/api.lua +++ b/api.lua @@ -496,6 +496,9 @@ function water_life.get_next_waypoint_fast(self,tpos,nogopos) local dir=vector.direction(pos,tpos) local neighbor = mobkit.dir2neighbor(dir) local height, pos2, liquidflag = mobkit.is_neighbor_node_reachable(self,neighbor) + local heightr = nil + local heightl = nil + local liq = nil if height then local fast = false diff --git a/init.lua b/init.lua index 7cd1a8e..83e6498 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,5 @@ water_life = {} -water_life.version = "200620" +water_life.version = "210620" water_life.shark_food = {} water_life.petz = minetest.get_modpath("petz") water_life.mobsredo = minetest.get_modpath("mobs") diff --git a/spawn.lua b/spawn.lua index 7b00272..dcbf7f8 100644 --- a/spawn.lua +++ b/spawn.lua @@ -38,6 +38,11 @@ local function spawnstep(dtime) local pos2 = mobkit.pos_translate2d(pos,yaw,radius) -- calculate position local depth = water_life.water_depth(pos2,25) -- get surface pos and water depth local bdata = water_life_get_biome_data(pos2) -- get biome data at spaen position + local savepos = pos2 + local dalam = depth.depth + local ground = {} + ground = depth.surface + if depth.depth > 0 then if water_life.radar_debug then @@ -45,7 +50,8 @@ local function spawnstep(dtime) minetest.chat_send_all(">>> Depth ="..dump(depth.depth).." <<< "..dump(depth.type)) minetest.chat_send_all(dump(bdata.name)) end - pos2 = depth.surface + pos2 = depth.surface + ground.y = ground.y -dalam + 1 end local liquidflag = nil @@ -62,7 +68,7 @@ local function spawnstep(dtime) end if liquidflag and not toomuch then - + --minetest.chat_send_all(dump(depth.surface)) local mobname = 'water_life:croc' local faktor = 100 - getcount(animal[mobname]) * 33 if random(100) < faktor then @@ -75,7 +81,7 @@ local function spawnstep(dtime) end - + --minetest.chat_send_all(dump(depth.surface)) local mobname = 'water_life:shark' if water_life.shark_spawn_rate >= random(1000) then @@ -89,11 +95,10 @@ local function spawnstep(dtime) end end - + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) mobname = "water_life:urchin" if water_life.urchin_spawn_rate >= random(1000) then - local ground = depth.surface - ground.y = ground.y - depth.depth + local coraltable = minetest.find_nodes_in_area({x=ground.x-5, y=ground.y-2, z=ground.z-5}, {x=ground.x+5, y=ground.y+2, z=ground.z+5}, water_life.urchinspawn) --local nearlife = water_life.count_objects(ground,5,"water_life:urchin") if coraltable and #coraltable > 0 and getcount(animal[mobname]) < 15 and liquidflag == "sea" then @@ -107,10 +112,11 @@ local function spawnstep(dtime) end end + depth = water_life.water_depth(savepos,25) -- do not ask why, but this is a must. Maybe I will discover later. Leave it and all .y val will be wrong + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) mobname = "water_life:clams" if water_life.clams_spawn_rate >= random(1000) then - local ground = depth.surface - ground.y = ground.y - depth.depth + local coraltable = minetest.find_nodes_in_area({x=ground.x-8, y=ground.y-2, z=ground.z-8}, {x=ground.x+8, y=ground.y+2, z=ground.z+8}, water_life.clams_spawn) --local nearlife = water_life.count_objects(ground,8,"water_life:clams") if coraltable and #coraltable > 0 and getcount(animal[mobname]) < 15 and liquidflag == "sea" then @@ -124,10 +130,10 @@ local function spawnstep(dtime) end end - + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) mobname = "water_life:jellyfish" - local ground = depth.surface + local faktor = 100 - getcount(animal[mobname]) * 20 if random(100) < faktor and liquidflag == "sea" then local obj=minetest.add_entity(ground,mobname) @@ -136,8 +142,8 @@ local function spawnstep(dtime) mobname = "water_life:coralfish" + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) - ground.y = ground.y - depth.depth local coraltable = minetest.find_nodes_in_area({x=ground.x-5, y=ground.y-2, z=ground.z-5}, {x=ground.x+5, y=ground.y+2, z=ground.z+5}, water_life.urchinspawn) --local nearlife = water_life.count_objects(ground,nil,mobname) faktor = 100 - getcount(animal[mobname]) * 6.66 @@ -156,7 +162,7 @@ local function spawnstep(dtime) end - + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) mobname = "water_life:clownfish" faktor = 100 - getcount(animal[mobname]) * 50 @@ -170,7 +176,7 @@ local function spawnstep(dtime) end end - + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) 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 @@ -192,6 +198,8 @@ local function spawnstep(dtime) end + + --minetest.chat_send_all(dump(depth.surface).." "..dump(pos2)) if water_life.whale_spawn_rate >= random(1000) and getcount(animal[mobname]) < (water_life.maxwhales) and liquidflag == "sea" then mobname = 'water_life:whale' @@ -203,7 +211,7 @@ local function spawnstep(dtime) for i = 0,3,1 do local whpos2 = mobkit.pos_translate2d(whpos,math.rad(i*90),30) local under = water_life.find_collision(whpos,whpos2, false) - --minetest.chat_send_all(dump(under)) + ----minetest.chat_send_all(dump(under)) if under and under < 25 then gotwhale = false break