diff --git a/mods/ikea/functions.lua b/mods/ikea/functions.lua index 19ea736..43e5f18 100644 --- a/mods/ikea/functions.lua +++ b/mods/ikea/functions.lua @@ -22,8 +22,12 @@ function table.shuffle(t) return t end -function table.merge(t1, t2) - for k,v in pairs(t2) do table.insert(t1, v) end +function table.merge(t1, t2, use_keys) + if use_keys then + for k,v in pairs(t2) do t1[k] = v end + else + for k,v in ipairs(t2) do table.insert(t1, v) end + end end function string:insert(pos, str) diff --git a/mods/ikea_chairs/init.lua b/mods/ikea_chairs/init.lua index 79bee38..88fe053 100644 --- a/mods/ikea_chairs/init.lua +++ b/mods/ikea_chairs/init.lua @@ -1,23 +1,25 @@ -ikea.furniture.register_kit("chairs:vedbo", { - mesh = "ikea_chairs_vedbo.obj", - tiles = {"ikea_chairs_vedbo.png"}, - box_contents = {"chairs:vedbo"}, - selection_box = { - type = "fixed", - fixed = { - {-7/16, -8/16, -7/16, 7/16, 2/16, 7/16}, -- Bottom - {-7/16, 2/16, 6/16, 7/16, 16/16, 7/16}, -- Back - {-7/16, 2/16, -7/16, -5/16, 4/16, 6/16}, -- Right Armrest - {5/16, 2/16, -7/16, 7/16, 4/16, 6/16}, -- Left Armrest +ikea.furniture.register_kit("chairs:vedbo", + { + description = "Vedbo Chair (Pink)", + mesh = "ikea_chairs_vedbo.obj", + tiles = {"ikea_chairs_vedbo.png"}, + selection_box = { + type = "fixed", + fixed = { + {-7/16, -8/16, -7/16, 7/16, 2/16, 7/16}, -- Bottom + {-7/16, 2/16, 6/16, 7/16, 16/16, 7/16}, -- Back + {-7/16, 2/16, -7/16, -5/16, 4/16, 6/16}, -- Right Armrest + {5/16, 2/16, -7/16, 7/16, 4/16, 6/16}, -- Left Armrest + }, }, - }, - collision_box = { - type = "fixed", - fixed = { - {-7/16, -8/16, -7/16, 7/16, 2/16, 7/16}, -- Bottom - {-7/16, 2/16, 6/16, 7/16, 16/16, 7/16}, -- Back - {-7/16, 2/16, -7/16, -5/16, 4/16, 6/16}, -- Right Armrest - {5/16, 2/16, -7/16, 7/16, 4/16, 6/16}, -- Left Armrest + collision_box = { + type = "fixed", + fixed = { + {-7/16, -8/16, -7/16, 7/16, 2/16, 7/16}, -- Bottom + {-7/16, 2/16, 6/16, 7/16, 16/16, 7/16}, -- Back + {-7/16, 2/16, -7/16, -5/16, 4/16, 6/16}, -- Right Armrest + {5/16, 2/16, -7/16, 7/16, 4/16, 6/16}, -- Left Armrest + }, }, - }, -}) + } +) diff --git a/mods/ikea_furniture/init.lua b/mods/ikea_furniture/init.lua index 623ea1f..df41eb4 100644 --- a/mods/ikea_furniture/init.lua +++ b/mods/ikea_furniture/init.lua @@ -1,15 +1,27 @@ ikea.furniture = {} +ikea.furniture.registered_kits = {} -local kit_default = { +-- Defaults For Furniture Kits, Overwritten By The Params Passed In register_kit +ikea.furniture.kit_defaults = { description = "Default Description For Furniture Kits", + paramtype = "light", + paramtype2 = "facedir", + drawtype = "mesh", mesh = "error.obj", tiles = {"unknown_node.png^[colorize:#ff0000:255"}, - collision_box = nil, - selection_box = nil, + groups = {carryable = 1}, +} - -- Box Specific Options - box_contents = {}, - box_tiles = { +minetest.register_node(":furniture:box", { + description = "Cardboard Box", + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { -6/16, -0.499, -6/16, 6/16, 4/16, 6/16 }, + }, + tiles = { {name = "ikea_furniture_box_top.png", backface_culling = false}, {name = "ikea_furniture_box_bottom.png", backface_culling = false}, {name = "ikea_furniture_box_side.png", backface_culling = false}, @@ -17,8 +29,20 @@ local kit_default = { {name = "ikea_furniture_box_front.png", backface_culling = false}, {name = "ikea_furniture_box_front.png", backface_culling = false}, }, + use_texture_alpha = true, + groups = {carryable = 1}, +}) - box_open_tiles = { +minetest.register_node(":furniture:box_open", { + description = "Cardboard Box, Open (You Hacker!)", + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { -6/16, -0.499, -6/16, 6/16, 8/16, 6/16 }, + }, + tiles = { {name = "ikea_furniture_box_top.png^[opacity:0", backface_culling = false}, {name = "ikea_furniture_box_bottom.png", backface_culling = false}, {name = "ikea_furniture_box_side.png", backface_culling = false}, @@ -26,140 +50,23 @@ local kit_default = { {name = "ikea_furniture_box_back_open.png", backface_culling = false}, {name = "ikea_furniture_box_front_open.png", backface_culling = false}, }, -} + use_texture_alpha = true, + groups = {carryable = 1}, +}) -function ikea.furniture.register_kit(name, def) - def = def or {} + +function ikea.furniture.register_kit(name, def_raw) + local def_raw = def_raw or {} -- Furniture Node - minetest.register_node(":" .. name, { - description = (def.description or kit_default.description), - paramtype = "light", - paramtype2 = "facedir", - drawtype = "mesh", - mesh = (def.mesh or kit_default.mesh), - tiles = (def.tiles or kit_default.tiles), - groups = {carryable = 1}, - collision_box = (def.collision_box or kit_default.collision_box), - selection_box = (def.selection_box or kit_default.selection_box), - }) + local def = ikea.furniture.kit_defaults + table.merge(def, def_raw, true) - -- Box Node - minetest.register_node(":" .. name .. "_box", { - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { -6/16, -0.499, -6/16, 6/16, 4/16, 6/16 }, - }, - description = (def.description or kit_default.description), - paramtype = "light", - paramtype2 = "facedir", - tiles = (def.box_tiles or kit_default.box_tiles), - use_texture_alpha = true, - groups = {carryable = 1}, + minetest.register_node(":" .. name, def) - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - minetest.set_node(pos, {name = name.."_box_open"}) - end - }) - - -- Opened Box Node - minetest.register_node(":" .. name .. "_box_open", { - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { -6/16, -0.499, -6/16, 6/16, 8/16, 6/16 }, - }, - description = (def.description or kit_default.description), - paramtype = "light", - paramtype2 = "facedir", - tiles = (def.box_open_tiles or kit_default.box_open_tiles), - use_texture_alpha = true, - groups = {carryable = 1}, - drop = "", - - on_construct = function(pos) - for k, v in pairs(def.box_contents) do - vel = math.random(5, 8) - minetest.spawn_item(pos, v):set_velocity({x=0,y=vel,z=0}) - end - minetest.get_node_timer(pos):start(5) - end, - - on_timer = function(pos) - minetest.set_node(pos, {name = "air"}) - end, - }) - - -- Furniture For Use On Warehouse Racks - minetest.register_node(":" .. name .. "_rack", { - is_ground_content = true, - sunlight_propagates = true, - description = (def.description or kit_default.description) .. "For Use On warehouse:rack", - paramtype = "light", - paramtype2 = "facedir", - drawtype = "mesh", - mesh = (def.mesh or kit_default.mesh), - tiles = (def.tiles or kit_default.tiles), - groups = {carryable = 1}, - selection_box = (def.selection_box or kit_default.selection_box), - drop = name, - - after_dig_node = function(pos, oldnode, oldmeta, digger) - minetest.set_node(pos, {name = "warehouse:rack_filler"}) - end, - }) - - -- Boxes For Use On Warehouse Racks - minetest.register_node(":" .. name .. "_box" .. "_rack", { - is_ground_content = true, - sunlight_propagates = true, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { -6/16, -0.499, -6/16, 6/16, 4/16, 6/16 }, - }, - collision_box = {type = "regular"}, - description = (def.description or kit_default.description), - paramtype = "light", - paramtype2 = "facedir", - tiles = (def.box_tiles or kit_default.box_tiles), - use_texture_alpha = true, - groups = {carryable = 1}, - drop = name .. "_box", - - after_dig_node = function(pos, oldnode, oldmeta, digger) - minetest.set_node(pos, {name = "warehouse:rack_filler"}) - end, - }) - - -- Register Warehouse Rack Decoration - local furniture_node = {name = name .. "_rack", param1 = 255, param2 = 0} - local box_node = {name = name .. "_box_rack", param1 = 255, param2 = 0} - local filler_node = {name = "warehouse:rack_filler", param1 = 255, param2 = 0} - local schem = { - size = {x = 1, y = 7, z = 1}, - data = { - box_node, - box_node, - furniture_node, - filler_node, - box_node, - box_node, - box_node, - }, - } - - minetest.register_decoration({ - deco_type = "schematic", - place_on = "warehouse:rack_filler", - sidelen = 16, - biomes = {"warehouse"}, - flags = "place_center_x, force_placement", - max_y = 31000, - min_y = 0, - place_offset_y = -6, - schematic = schem, - fill_ratio = 1, + -- Register Kit Into Global Table + table.insert(ikea.furniture.registered_kits, { + furniture_node = name, + box_contents = def.box_contents or {name} }) end diff --git a/mods/ikea_furniture/mod.conf b/mods/ikea_furniture/mod.conf index abd6558..6ab8904 100644 --- a/mods/ikea_furniture/mod.conf +++ b/mods/ikea_furniture/mod.conf @@ -1,2 +1,2 @@ name = ikea_furniture -depends = ikea,ikea_warehouse \ No newline at end of file +depends = ikea diff --git a/mods/ikea_mapgen/init.lua b/mods/ikea_mapgen/init.lua index ff3c9c7..33b09cb 100644 --- a/mods/ikea_mapgen/init.lua +++ b/mods/ikea_mapgen/init.lua @@ -20,6 +20,7 @@ function ikea.mapgen.register_schematic(def) rotation = def.rotation or 0, force_placement = def.force_placement or false, flags = def.flags or "", + on_place = def.on_place or nil, }) end @@ -29,6 +30,7 @@ function ikea.mapgen.every_n_mapblocks(n) end end +-- Big mapgen function, places schematics if should_place and then called on_place minetest.register_on_generated(function(minp, maxp, seed) local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") local data = vm:get_data() @@ -44,6 +46,10 @@ minetest.register_on_generated(function(minp, maxp, seed) for i,v in ipairs(ikea.mapgen.schems[content_id]) do if v.should_place(x,y,z) then minetest.place_schematic_on_vmanip(vm, {x=x,y=y,z=z}, v.schematic, v.rotation, v.force_placement, v.flags) + + if v.on_place then + v.on_place(vm, x, y, z) + end end end end diff --git a/mods/ikea_warehouse/init.lua b/mods/ikea_warehouse/init.lua index 4216cdb..5e272f0 100644 --- a/mods/ikea_warehouse/init.lua +++ b/mods/ikea_warehouse/init.lua @@ -1,11 +1,36 @@ ikea.warehouse = {} +ikea.warehouse.RackContentNoise = PerlinNoise({ + offset = 0, + scale = 15, + spread = {x=10, y=10, z=10}, + seed = 1, + octaves = 2, + persistence = 3, + lacunarity = 2, + flags = "defaults, absvalue", +}) + local modpath = minetest.get_modpath("ikea_warehouse") dofile(modpath .. "/nodes.lua") dofile(modpath .. "/schematics.lua") local should_place_aisle = ikea.mapgen.every_n_mapblocks(4) +-- Places a content schematic to pos, choosing a furniture node based on Perlin Noise. Also rotates 180 degrees if rotate == true +function ikea.warehouse.place_rack_contents(vm, pos, rotate) + local rotation = 0 + if rotate then rotation = 2 end + local furniture_id = (math.floor(ikea.warehouse.RackContentNoise:get_2d(pos) * 100000) % (#ikea.furniture.registered_kits)) + 1 + print(furniture_id) + local box_node = {name = "furniture:box"} + local furniture_node = {name = ikea.furniture.registered_kits[furniture_id].furniture_node, param2 = rotation} + local schem = ikea.warehouse.make_rack_content_schem(furniture_node, box_node) + + minetest.place_schematic_on_vmanip(vm, pos, schem, 0, true, "") +end + + minetest.register_biome({ name = "warehouse", node_top = "warehouse:concrete", @@ -16,6 +41,7 @@ minetest.register_biome({ y_min = 0, }) +-- Register rack placement schematic and mapgen information ikea.mapgen.register_schematic({ schematic = ikea.warehouse.rack_schem, place_on = "warehouse:concrete", @@ -23,8 +49,45 @@ ikea.mapgen.register_schematic({ return not should_place_aisle(x) end, force_placement = true, + + -- Place contents in rack positions where applicable + on_place = function(vm, x, y, z) + y = y + 1 + + local x2 = x + + for i=1,16 do + ikea.warehouse.place_rack_contents(vm, {x = x2, y = y, z = z}, true) + x2 = x2 + 1 + end + + x2 = x + z = z + 7 + + for i=1,16 do + ikea.warehouse.place_rack_contents(vm, {x = x2, y = y, z = z}, false) + x2 = x2 + 1 + end + + x2 = x + z = z + 1 + + for i=1,16 do + ikea.warehouse.place_rack_contents(vm, {x = x2, y = y, z = z}, true) + x2 = x2 + 1 + end + + x2 = x + z = z + 7 + + for i=1,16 do + ikea.warehouse.place_rack_contents(vm, {x = x2, y = y, z = z}, false) + x2 = x2 + 1 + end + end, }) +-- Register aisle schematic and mapgen information ikea.mapgen.register_schematic({ schematic = ikea.warehouse.aisle_schem, place_on = "warehouse:concrete", diff --git a/mods/ikea_warehouse/mod.conf b/mods/ikea_warehouse/mod.conf index 6bf0613..711bc85 100644 --- a/mods/ikea_warehouse/mod.conf +++ b/mods/ikea_warehouse/mod.conf @@ -1,2 +1,2 @@ name = ikea_warehouse -depends = ikea_mapgen,ikea_light +depends = ikea_mapgen,ikea_furniture,ikea_light diff --git a/mods/ikea_warehouse/schematics.lua b/mods/ikea_warehouse/schematics.lua index cef5497..55e4f96 100644 --- a/mods/ikea_warehouse/schematics.lua +++ b/mods/ikea_warehouse/schematics.lua @@ -3,14 +3,34 @@ local filler_node = {name = "warehouse:rack_filler"} local rack_node = {name = "warehouse:rack"} local ignore_node = {name = "ignore"} local air_node = {name = "air"} +local furniture_node = {name = "ikea:error"} local light_node = {name = "warehouse:light"} local row_sign_node = {name = "warehouse:row_sign"} +-- Functions + +function ikea.warehouse.make_rack_content_schem(furniture, box) + return { + size = {x=1, y=7, z=1}, + data = { + box, + box, + furniture, + filler_node, + box, + box, + box, + }, + } +end + -- Schematic Layers local ignore_layer = {} local rack_layer = {} local filler_layer = {} local air_layer = {} +local box_layer = {} +local furniture_layer = {} local row_sign_layer = {} local light_layer = { @@ -70,7 +90,7 @@ ikea.warehouse.rack_schem = { } -- Data -local function aisle_slice(light) +local function rack_aisle_slice(light) table.merge(ikea.warehouse.rack_schem.data, ignore_layer) table.merge(ikea.warehouse.rack_schem.data, air_layer) table.merge(ikea.warehouse.rack_schem.data, air_layer) @@ -93,7 +113,7 @@ local function aisle_slice(light) table.merge(ikea.warehouse.rack_schem.data, air_layer) end -local function rack_slice() +local function rack_rack_slice() table.merge(ikea.warehouse.rack_schem.data, rack_layer) table.merge(ikea.warehouse.rack_schem.data, filler_layer) table.merge(ikea.warehouse.rack_schem.data, filler_layer) @@ -112,7 +132,7 @@ local function rack_slice() table.merge(ikea.warehouse.rack_schem.data, air_layer) end -local function filler_slice() +local function rack_filler_slice() table.merge(ikea.warehouse.rack_schem.data, air_layer) table.merge(ikea.warehouse.rack_schem.data, filler_layer) table.merge(ikea.warehouse.rack_schem.data, filler_layer) @@ -131,32 +151,32 @@ local function filler_slice() table.merge(ikea.warehouse.rack_schem.data, air_layer) end -rack_slice() -aisle_slice(false) -aisle_slice(false) -aisle_slice(true) -aisle_slice(false) -aisle_slice(false) -aisle_slice(false) -filler_slice() -rack_slice() -aisle_slice(false) -aisle_slice(false) -aisle_slice(true) -aisle_slice(false) -aisle_slice(false) -aisle_slice(false) -filler_slice() +rack_rack_slice() +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_aisle_slice(true) +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_filler_slice() +rack_rack_slice() +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_aisle_slice(true) +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_aisle_slice(false) +rack_filler_slice() -- Aisle Schematic Template ikea.warehouse.aisle_schem = { size = {x=16, y=16, z=16}, - data = {} + data = {}, } -- Data -local function ignore_slice(light) +local function aisle_ignore_slice(light) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) @@ -179,7 +199,7 @@ local function ignore_slice(light) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) end -local function row_sign_slice() +local function aisle_sign_slice() table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) @@ -198,19 +218,19 @@ local function row_sign_slice() table.merge(ikea.warehouse.aisle_schem.data, ignore_layer) end -row_sign_slice() -ignore_slice(false) -ignore_slice(false) -ignore_slice(false) -ignore_slice(false) -ignore_slice(false) -ignore_slice(false) -row_sign_slice() -row_sign_slice() -ignore_slice(false) -ignore_slice(false) -ignore_slice(true) -ignore_slice(false) -ignore_slice(false) -ignore_slice(false) -row_sign_slice() \ No newline at end of file +aisle_sign_slice() +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_sign_slice() +aisle_sign_slice() +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(true) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_ignore_slice(false) +aisle_sign_slice() \ No newline at end of file