From 2bf7365974d52a7f5fe7c485d9a3f2dc9f6849da Mon Sep 17 00:00:00 2001 From: Rochambeau Date: Sat, 21 Jul 2018 19:41:20 +0200 Subject: [PATCH] more LuaVoxelManip --- buildings.lua | 15 +++++++++++---- foundation.lua | 2 +- utils.lua | 20 +++++++++++++++----- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/buildings.lua b/buildings.lua index f430a8a..1a72137 100644 --- a/buildings.lua +++ b/buildings.lua @@ -13,7 +13,11 @@ local number_built -- function settlements.build_schematic(pos, building, replace_wall, name) -- get building node material for better integration to surrounding - local balcony_material = minetest.get_node_or_nil(pos).name + local platform_material = minetest.get_node_or_nil(pos) + if not platform_material then + return + end + platform_material = platform_material.name -- pick random material local material = wallmaterial[math.random(1,#wallmaterial)] -- schematic conversion to lua @@ -25,7 +29,7 @@ function settlements.build_schematic(pos, building, replace_wall, name) schem_lua = schem_lua:gsub("default:cobble", material) end schem_lua = schem_lua:gsub("default:dirt_with_grass", - balcony_material) + platform_material) -- special material for spawning npcs schem_lua = schem_lua:gsub("default:junglewood", "settlements:junglewood") @@ -60,7 +64,7 @@ function settlements.place_settlement_lvm(data, va, minp, maxp) -- find center of chunk local center = { x=maxp.x-half_map_chunk_size, - y=maxp.y-half_map_chunk_size, + y=maxp.y, z=maxp.z-half_map_chunk_size } -- find center_surcafe of chunk @@ -96,9 +100,12 @@ function settlements.place_settlement_lvm(data, va, minp, maxp) for j = 0, 360, 15 do local angle = j * math.pi / 180 local ptx, ptz = x + r * math.cos( angle ), z + r * math.sin( angle ) + ptx = settlements.round(ptx, 0) + ptz = settlements.round(ptz, 0) local pos1 = { x=ptx, y=center_surface.y, z=ptz} -- - local pos_surface = settlements.find_surface(pos1) + local pos_surface = settlements.find_surface_lvm(pos1, data, va) + --local pos_surface = settlements.find_surface(pos1) if pos_surface then if settlements.pick_next_building(pos_surface) diff --git a/foundation.lua b/foundation.lua index 266d809..9152c84 100644 --- a/foundation.lua +++ b/foundation.lua @@ -8,7 +8,7 @@ function settlements.ground(pos) -- role model: Wendelsteinkircherl, Brannenburg p2.y = p2.y-1 while true do cnt = cnt+1 - if cnt > 50 then break end + if cnt > 20 then break end if cnt>math.random(2,4) then mat = "stone" end minetest.swap_node(p2, {name="default:"..mat}) p2.y = p2.y-1 diff --git a/utils.lua b/utils.lua index f78e2af..009fbad 100644 --- a/utils.lua +++ b/utils.lua @@ -32,6 +32,13 @@ function settlements.shallowCopy(original) return copy end -- +-- +-- +function settlements.round(num, numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end +-- -- function to find surface block y coordinate -- function settlements.find_surface_lvm(pos, data, va) @@ -49,6 +56,8 @@ function settlements.find_surface_lvm(pos, data, va) local cnt_max = 200 -- starting point for looking for surface local vi = va:index(p6.x, p6.y, p6.z) + if data[vi] == nil then return nil end +-- local tmp = minetest.get_name_from_content_id(data[vi]) if data[vi] == c_air then itter = -1 else @@ -56,11 +65,12 @@ function settlements.find_surface_lvm(pos, data, va) end while cnt < cnt_max do cnt = cnt+1 - vi = va:index(p6.x, p6.y, p6.z) - if vi == nil - then - return nil - end + local vi = va:index(p6.x, p6.y, p6.z) +-- local tmp = minetest.get_name_from_content_id(data[vi]) +-- if vi == nil +-- then +-- return nil +-- end for i, mats in ipairs(surface_mat) do local node_check = va:index(p6.x, p6.y+1, p6.z) if node_check and vi and data[vi] == mats and