Add Showroom Walls

master
benrob0329 2020-01-30 18:16:06 -05:00
parent 2306a14c2a
commit 422553cf18
4 changed files with 83 additions and 12 deletions

View File

@ -20,13 +20,21 @@ minetest.register_node(":showroom:floor", {
sunlight_propagates = true,
})
minetest.register_node(":showroom:wall", {
paramtype = "light",
description = "Base Wall Node, Do Not Place (You Hacker!)",
tiles = {{name = "ikea_showroom_wall.png"}},
groups = {static = 1},
sunlight_propagates = true,
})
ikea.register_department({
name = "showroom",
get_schematic = function(edges, x, z)
if edges.e or edges.w or edges.n or edges.s then
return schems.floor, nil
return schems.get_outer(Perlin, edges, x, z), nil
else
return schems.get(Perlin, x, z), nil
return schems.get_inner(Perlin, x, z), nil
end
end,
})

View File

@ -1,5 +1,54 @@
local schems = {}
schems.floor = schematic.new({x = 16, y = 1, z = 16}, "showroom:floor")
-- Corner North/South East/West Top/Bottom
local corner_swb = {x=0,y=0,z=0}
local corner_seb = {x=15,y=0,z=0}
local corner_nwb = {x=0,y=0,z=15}
local corner_neb = {x=15,y=0,z=15}
local corner_swt = {x=0,y=15,z=0}
local corner_set = {x=15,y=15,z=0}
local corner_nwt = {x=0,y=15,z=15}
local corner_net = {x=15,y=15,z=15}
function schems.get_outer(Perlin, edges, x, z)
local schem = schematic.new({x=16,y=16,z=16}, "air")
local has_opening = util.bound_perlin(Perlin, 8, x, 4, z) + 1 == 1
-- Corners First
if edges.n and edges.e then
schematic.fill_area(schem, "showroom:wall", corner_swb, corner_swt)
elseif edges.n and edges.w then
schematic.fill_area(schem, "showroom:wall", corner_seb, corner_set)
elseif edges.s and edges.w then
schematic.fill_area(schem, "showroom:wall", corner_neb, corner_net)
elseif edges.s and edges.e then
schematic.fill_area(schem, "showroom:wall", corner_nwb, corner_nwt)
elseif edges.n then
schematic.fill_area(schem, "showroom:wall", corner_swb, corner_set)
if has_opening then
schematic.fill_area(schem, "air", {x=7,y=0,z=0}, {x=8,y=4,z=0})
end
elseif edges.s then
schematic.fill_area(schem, "showroom:wall", corner_nwb, corner_net)
if has_opening then
schematic.fill_area(schem, "air", {x=7,y=0,z=15}, {x=8,y=4,z=15})
end
elseif edges.w then
schematic.fill_area(schem, "showroom:wall", corner_seb, corner_net)
if has_opening then
schematic.fill_area(schem, "air", {x=15,y=0,z=7}, {x=15,y=4,z=8})
end
elseif edges.e then
schematic.fill_area(schem, "showroom:wall", corner_swb, corner_nwt)
if has_opening then
schematic.fill_area(schem, "air", {x=0,y=0,z=7}, {x=0,y=4,z=8})
end
end
schematic.fill_area(schem, "showroom:floor", corner_swb, corner_neb)
return schem
end
local rooms = {"lounge", "kitchen", "bedroom"}
local display_tables = {
@ -28,11 +77,11 @@ local display_tables = {
},
}
function schems.get(Perlin, x, z)
function schems.get_inner(Perlin, x, z)
local room_name = rooms[util.bound_perlin(Perlin, #rooms, x, 0, z) + 1]
local applicable_displays = table.search(display_tables, {includes = {rooms = {room_name}}})
local combined_schem = schematic.new({x = 16, y = 16, z = 16, "air"})
schematic.fill_area(combined_schem, "showroom:floor", {x = 0, y = 0, z = 0}, {x = 15, y = 0, z = 15})
local schem = schematic.new({x = 16, y = 16, z = 16, "air"})
schematic.fill_area(schem, "showroom:floor", {x = 0, y = 0, z = 0}, {x = 15, y = 0, z = 15})
for x2 = 0, 15, 8 do
for z2 = 0, 15, 8 do
@ -42,12 +91,12 @@ function schems.get(Perlin, x, z)
local applicable_furniture = table.search(ikea.registered_furniture, {includes = {tags = {v.type, room_name}}})
local id = util.bound_perlin(Perlin, #applicable_furniture, x + x2, 2, z + z2) + 1
local index = schematic.index(combined_schem, vector.add(v.pos, {x = x2, y = 1, z = z2}))
combined_schem.data[index] = {name = applicable_furniture[id].node_name}
local index = schematic.index(schem, vector.add(v.pos, {x = x2, y = 1, z = z2}))
schem.data[index] = {name = applicable_furniture[id].node_name}
end
end
end
return combined_schem
return schem
end
return schems

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

View File

@ -17,10 +17,24 @@ end
function schematic.fill_area(schem, node, pos1, pos2)
node = util.node_or_ignore(node)
local x_incr = 1
local y_incr = 1
local z_incr = 1
for z = pos1.z, pos2.z do
for y = pos1.y, pos2.y do
for x = pos1.x, pos2.x do
-- Lua does not infer a negative increment
if pos1.x > pos2.x then
x_incr = -1
end
if pos1.y > pos2.y then
y_incr = -1
end
if pos1.z > pos2.z then
z_incr = -1
end
for z = pos1.z, pos2.z, z_incr do
for y = pos1.y, pos2.y, y_incr do
for x = pos1.x, pos2.x, x_incr do
local index = schematic.index(schem, {x = x, y = y, z = z})
schem.data[index] = node
end