Skip to content

Commit

Permalink
Mount Gen: use local links to global functions. Closes #1892
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Jan 3, 2025
1 parent d5aa411 commit ba0a5b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion mods/lord/World/mountgen/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = mountgen
depends = builtin
depends = builtin, default
41 changes: 22 additions & 19 deletions mods/lord/World/mountgen/mountgen.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
local math_floor, math_ceil, math_tan, table_insert, id
= math.floor, math.ceil, math.tan, table.insert, minetest.get_content_id

local stone_id = id("default:stone")
local air_id = id("air")

mountgen.list_chunks = function(p1, p2)
local chunks = {}
local size = 64

local fp1 = {
x = math.floor(p1.x / size) * size,
y = math.floor(p1.y / size) * size,
z = math.floor(p1.z / size) *
x = math_floor(p1.x / size) * size,
y = math_floor(p1.y / size) * size,
z = math_floor(p1.z / size) *
size
}
local cp2 = { x = math.ceil(p2.x / size) * size, y = math.ceil(p2.y / size) * size, z = math.ceil(p2.z / size) * size }
local cp2 = { x = math_ceil(p2.x / size) * size, y = math_ceil(p2.y / size) * size, z = math_ceil(p2.z / size) * size }

local nx = (cp2.x - fp1.x) / size
local ny = (cp2.y - fp1.y) / size
Expand All @@ -19,23 +25,23 @@ mountgen.list_chunks = function(p1, p2)
for x = 1, nx do
local lp1 = { x = fp1.x + size * (x - 1), y = fp1.y + size * (y - 1), z = fp1.z + size * (z - 1) }
local lp2 = { x = lp1.x + size - 1, y = lp1.y + size - 1, z = lp1.z + size - 1 }
table.insert(chunks, { lp1, lp2 })
table_insert(chunks, { lp1, lp2 })
end
end
end

return chunks
end

local can_place_dirt = function(data, stone_id)
local can_place_dirt = function(data)
if data ~= stone_id then
return true
end

return false
end

local can_place_plant = function(data, air_id)
local can_place_plant = function(data)
if data == air_id then
return true
end
Expand All @@ -45,9 +51,9 @@ end

mountgen.mountgen = function(top, config)
local method_name = config.METHOD
top.x = math.floor(top.x + 0.5)
top.y = math.floor(top.y + 0.5)
top.z = math.floor(top.z + 0.5)
top.x = math_floor(top.x + 0.5)
top.y = math_floor(top.y + 0.5)
top.z = math_floor(top.z + 0.5)

if top.y <= config.Y0 then
minetest.log("Trying to build negative mountain")
Expand All @@ -57,7 +63,7 @@ mountgen.mountgen = function(top, config)
local y1 = config.Y0
local y2 = top.y
local H = y2 - y1
local W = math.ceil(2 * H * math.tan(config.ANGLE * 3.141 / 180 / 2)) + 3
local W = math_ceil(2 * H * math_tan(config.ANGLE * 3.141 / 180 / 2)) + 3

local height_map, width, center
if method_name == "cone" then
Expand Down Expand Up @@ -97,13 +103,10 @@ mountgen.mountgen = function(top, config)
local offset_y = lp1.y - p1.y
local offset_z = lp1.z - p1.z

local stone_id = minetest.get_content_id("default:stone")
local air_id = minetest.get_content_id("air")

local data = voxel_manip:get_data()
for i in area:iterp(p1, p2) do
local local_z = math.floor((i - 1) / (wx * wy)) + 1 - dz
local local_y = math.floor((i - 1) / wx) % wy + 1 - dy
local local_z = math_floor((i - 1) / (wx * wy)) + 1 - dz
local local_y = math_floor((i - 1) / wx) % wy + 1 - dy
local local_x = (i - 1) % wx + 1 - dx

local global_z = local_z + offset_z
Expand All @@ -113,21 +116,21 @@ mountgen.mountgen = function(top, config)
if global_z >= 1 and global_z <= width and
global_x >= 1 and global_x <= width and
global_y >= 1 then
local height = math.floor(height_map[global_z][global_x] + 0.5)
local height = math_floor(height_map[global_z][global_x] + 0.5)
if height > 0 then
if global_y < height then
data[i] = stone_id
elseif global_y == height then
if can_place_dirt(data[i], stone_id) then
local top_node = mountgen.top_node({ x = global_x, y = global_y, z = global_z }, config)
data[i] = minetest.get_content_id(top_node)
data[i] = id(top_node)
end
elseif global_y == height + 1 then
if can_place_plant(data[i], air_id) then
local upper_node = mountgen.upper_node({ x = global_x, y = global_y, z = global_z },
config)
if upper_node ~= nil then
data[i] = minetest.get_content_id(upper_node)
data[i] = id(upper_node)
end
end
end
Expand Down

0 comments on commit ba0a5b1

Please sign in to comment.