Add util.bound_perlin() and apply to code
parent
ebaa5c4b9a
commit
144f21862c
|
@ -5,13 +5,9 @@ local ceiling_schematic = schematic.new({x = 16, y = 1, z = 16}, "ikea:ceiling")
|
|||
-- Originally Written By Warr1024
|
||||
|
||||
-- Wait until mapgen initializes to get the noise
|
||||
local perlin
|
||||
local pn
|
||||
minetest.after(0, function()
|
||||
local pn = minetest.get_perlin(0, 1, 0, 1)
|
||||
perlin = function(x, y, z)
|
||||
local n = pn:get_3d({x = x, y = y, z = z})
|
||||
return n - math.floor(n)
|
||||
end
|
||||
pn = minetest.get_perlin(0, 1, 0, 1)
|
||||
end)
|
||||
|
||||
local function split(r, min, max, val, bd)
|
||||
|
@ -26,8 +22,7 @@ local function split(r, min, max, val, bd)
|
|||
end
|
||||
|
||||
local function pick_department(options, x_min, x_max, z_min, z_max, x, z)
|
||||
local rand = perlin(x_min, 2, z_min)
|
||||
local department = options.departments[math.floor(rand * #options.departments) + 1]
|
||||
local department = options.departments[util.bound_perlin(pn, #options.departments, x_min, 2, z_min) + 1]
|
||||
local edges = {w = x <= x_min, e = x >= x_max, s = z <= z_min, n = z >= z_max}
|
||||
return department, edges
|
||||
end
|
||||
|
@ -36,9 +31,9 @@ local function subdivide(options, x_min, x_max, z_min, z_max, x, z)
|
|||
local width = x_max - x_min + 1
|
||||
local height = z_max - z_min + 1
|
||||
|
||||
if (width > options.max_size) or (height > options.max_size) or (perlin(x_min, 0, z_min) < 0.5) then
|
||||
if (width > options.max_size) or (height > options.max_size) or (util.bound_perlin(pn, 1, x_min, 0, z_min) < 0.5) then
|
||||
if height > width then
|
||||
local z_min2, z_max2 = split(perlin(x_min, 1, z_min), z_min, z_max, z, options.min_size)
|
||||
local z_min2, z_max2 = split(util.bound_perlin(pn, 1, x_min, 1, z_min), z_min, z_max, z, options.min_size)
|
||||
local height2 = z_max2 - z_min2 + 1
|
||||
|
||||
if (height2 < options.min_size) or ((height - height2) < options.min_size) then
|
||||
|
@ -47,7 +42,7 @@ local function subdivide(options, x_min, x_max, z_min, z_max, x, z)
|
|||
|
||||
return subdivide(options, x_min, x_max, z_min2, z_max2, x, z)
|
||||
else
|
||||
local x_min2, x_max2 = split(perlin(x_min, 1, z_min), x_min, x_max, x, options.min_size)
|
||||
local x_min2, x_max2 = split(util.bound_perlin(pn, 1, x_min, 1, z_min), x_min, x_max, x, options.min_size)
|
||||
local width2 = x_max2 - x_min2 + 1
|
||||
|
||||
if (width2 < options.min_size) or ((width - width2) < options.min_size) then
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local applicable_furniture
|
||||
local should_place_aisle = util.every_n_mapblocks(4)
|
||||
local RackContentNoise = PerlinNoise({
|
||||
local Perlin = PerlinNoise({
|
||||
offset = 0,
|
||||
scale = 15,
|
||||
spread = {x = 10, y = 10, z = 10},
|
||||
|
@ -28,11 +28,7 @@ local function place_rack_contents(vm, pos, rotate)
|
|||
end
|
||||
|
||||
for x = pos.x, pos.x + 15 do
|
||||
local local_pos = {x = x, y = pos.y, z = pos.z}
|
||||
local noise = RackContentNoise:get_2d(local_pos)
|
||||
local large_num = 100000
|
||||
local furniture_id = (math.floor(noise * large_num) % (#applicable_furniture)) + 1
|
||||
|
||||
local furniture_id = util.bound_perlin(Perlin, #applicable_furniture, x, pos.y, pos.z) + 1
|
||||
local furniture_node = {name = applicable_furniture[furniture_id].node_name, param2 = rotation}
|
||||
local box_node = {name = "ikea:box"}
|
||||
local filler_node = {name = "ikea:invisible_wall"}
|
||||
|
@ -41,14 +37,14 @@ local function place_rack_contents(vm, pos, rotate)
|
|||
size = {x = 1, y = 7, z = 1},
|
||||
data = {box_node, box_node, furniture_node, filler_node, box_node, box_node, box_node},
|
||||
}
|
||||
minetest.place_schematic_on_vmanip(vm, local_pos, schem, 0, true, "")
|
||||
minetest.place_schematic_on_vmanip(vm, {x = x, y = pos.y, z = pos.z}, schem, 0, true, "")
|
||||
|
||||
local box_positions = {
|
||||
{x = local_pos.x, y = local_pos.y, z = local_pos.z},
|
||||
{x = local_pos.x, y = local_pos.y + 1, z = local_pos.z},
|
||||
{x = local_pos.x, y = local_pos.y + 4, z = local_pos.z},
|
||||
{x = local_pos.x, y = local_pos.y + 5, z = local_pos.z},
|
||||
{x = local_pos.x, y = local_pos.y + 6, z = local_pos.z},
|
||||
{x = x, y = pos.y, z = pos.z},
|
||||
{x = x, y = pos.y + 1, z = pos.z},
|
||||
{x = x, y = pos.y + 4, z = pos.z},
|
||||
{x = x, y = pos.y + 5, z = pos.z},
|
||||
{x = x, y = pos.y + 6, z = pos.z},
|
||||
}
|
||||
|
||||
for j = 1, #box_positions do
|
||||
|
@ -57,7 +53,7 @@ local function place_rack_contents(vm, pos, rotate)
|
|||
meta:set_string("leave_behind", "ikea:invisible_wall")
|
||||
end
|
||||
|
||||
local furniture_meta = minetest.get_meta({x = local_pos.x, y = local_pos.y + 2, z = local_pos.z})
|
||||
local furniture_meta = minetest.get_meta({x = x, y = pos.y + 2, z = pos.z})
|
||||
furniture_meta:set_string("leave_behind", "ikea:invisible_wall")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,3 +27,8 @@ function util.leave_behind(pos, oldnode, oldmetadata, digger)
|
|||
minetest.set_node(pos, {name = oldmetadata.fields.leave_behind})
|
||||
end
|
||||
end
|
||||
|
||||
function util.bound_perlin(Perlin, limit, x, y, z)
|
||||
local num = Perlin:get_3d({x = x, y = y, z = z})
|
||||
return math.floor((num - math.floor(num)) * limit)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue