Skip to content

Commit

Permalink
more LuaVoxelManip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeb187 committed Jul 21, 2018
1 parent 075b5bf commit 2bf7365
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
15 changes: 11 additions & 4 deletions buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -49,18 +56,21 @@ 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
itter = 1
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
Expand Down

0 comments on commit 2bf7365

Please sign in to comment.