From 68782753cee95a3d351f12cd80c151b754d74438 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 4 Sep 2019 15:53:06 +0200 Subject: [PATCH] Improve village ground generation --- mods/util/init.lua | 4 +-- mods/village/generate.lua | 35 ++++++++++++++------- mods/village/schematics/village_filler.mts | Bin 294 -> 313 bytes 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/mods/util/init.lua b/mods/util/init.lua index 18120f6..5f948d9 100644 --- a/mods/util/init.lua +++ b/mods/util/init.lua @@ -42,7 +42,7 @@ function util.fixlight(pos1, pos2) return #nodes end -function util.nodefunc(pos1, pos2, name, func, nomanip) +function util.nodefunc(pos1, pos2, nodes, func, nomanip) -- function based off fixlight -- call a function for every node of a single type local pos1, pos2 = util.sort_pos(pos1, pos2) @@ -52,7 +52,7 @@ function util.nodefunc(pos1, pos2, name, func, nomanip) manip:read_from_map(pos1, pos2) end - local nodes = minetest.find_nodes_in_area(pos1, pos2, name) + local nodes = minetest.find_nodes_in_area(pos1, pos2, nodes) for _, pos in ipairs(nodes) do func(pos) end diff --git a/mods/village/generate.lua b/mods/village/generate.lua index e3638ec..4759c30 100644 --- a/mods/village/generate.lua +++ b/mods/village/generate.lua @@ -11,6 +11,7 @@ local village_file = minetest.get_worldpath() .. "/villages.dat" local modpath = minetest.get_modpath("village") local mapseed = minetest.get_mapgen_setting("seed") +local water_level = tonumber(minetest.get_mapgen_setting("water_level")) --[[ List of village wood materials (schematic replacements) One of these will be chosen at random and it applies @@ -208,15 +209,19 @@ function village.lift_ground(pos, scanheight) local stonenode = nil + if minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name == "air" then + return + end + for y = pos.y, pos.y - scanheight, -1 do local p = {x = pos.x, y = y, z = pos.z} local nn = minetest.get_node(p).name local an = minetest.get_node({x = p.x, y = p.y + 1, z = p.z}).name - if nn ~= "air" then + if nn ~= "air" and minetest.registered_nodes[nn].liquidtype ~= "none" then local nd = minetest.registered_nodes[nn] - if not nd.buildable_to then -- avoid grass, fluids, etc. + if not nd.buildable_to then if topnode == nil and nn ~= an then topnode = nn elseif fillernode == nil and nn ~= an then @@ -251,6 +256,7 @@ function village.lift_ground(pos, scanheight) local th = pos.y - y + -- TODO: Optimize speed if th <= fillerdepth - topdepth then minetest.set_node(p, {name = fillernode}) elseif th <= topdepth then @@ -265,10 +271,22 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill) util.getvoxelmanip(pos, {x = pos.x+12, y = pos.y+12, z = pos.z+12}) if nofill ~= true then + minetest.place_schematic( + {x = pos.x-6, y = pos.y-5, z = pos.z-6}, + modpath .. "/schematics/village_filler.mts", + "0", + {}, + false + ) + + local py = pos.y-6 + if py < water_level then + py = water_level + end util.nodefunc( - {x = pos.x-6, y = pos.y-7, z = pos.z-6}, - {x = pos.x+17, y = pos.y-6, z = pos.z+17}, - "air", + {x = pos.x-6, y = py, z = pos.z-6}, + {x = pos.x+17, y = py, z = pos.z+17}, + {"air", "group:liquid"}, function(pos) village.lift_ground(pos, 15) -- distance to lift ground; larger numbers will be slower end, true) @@ -281,13 +299,6 @@ function village.spawn_chunk(pos, orient, replace, pr, chunktype, nofill) true ) - minetest.place_schematic( - {x = pos.x-6, y = pos.y-5, z = pos.z-6}, - modpath .. "/schematics/village_filler.mts", - "0", - {}, - false - ) end if chunktype == "orchard" then diff --git a/mods/village/schematics/village_filler.mts b/mods/village/schematics/village_filler.mts index 161154216b772fa6c80694667f37f0a198fa62a4..2fa621edb970208bf7466fb7ac50d3289f378165 100644 GIT binary patch delta 268 zcmZ3+w3CU)Hze4XfrUYWfsH|8qLg|4^wWIJ20RCD{jI34<`QyWEr;b^Q_0Ec5#8# zQRipJWIU<-J>PEL)v&p*OcwIjzHpZRb)ntv3y@j2@x1AM@xtd{*KFg;1R8f~Rr!q1 zRbkneqe_pRG+RGE=kqTJ#dp~%Z1pFO~2Lq?6n`Kl*Fl@ z{h-qxpE~#WePf%}Jnz~zy(WIU9}k+(m&m`gwSK&BR^JCZ-tG4}w###GkLTS!pa1(_ PW(F{rUd+C-=7Sgj;^BYS delta 249 zcmdnVw2Vp0Hze4XfrUYWL4-k~9tBL~F|WUE$ah#lz}3-O{QTA61s-8393l7e&*z+; z=5Mkgm%Tc@;nladS7*i@tZJ9~_4OOqHR~$|>%On?-0RHy|MlOsKJNn#$Lu|xx9VHn zK4Yzjw<)vNf4}W}^`86pua#5ZWna3x{QlI-xr^;5IPU+YI=$|zx8C1Z(_?;J)!+GL zb$rpw@cm&=F0HRSxitRoByXUK>$ShW)=g4hb?fn|m)joxXYvo(dK{?#aP2AKmx7aE aXwe=<1~_nv`TI`_&SOZp#?Bj_#0~%t-+9vj