123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- -- Minetest 0.4 mod: stairs
- -- See README.txt for licensing and other information.
- -- Localize for performance.
- local math_floor = math.floor
- local math_random = math.random
- -- Global namespace for functions
- local S = function(str) return str end
- stairs = {}
- if not minetest.global_exists("circular_saw") then circular_saw = {} end
- circular_saw.known_nodes = circular_saw.known_nodes or {}
- local function pixel_box(x1, y1, z1, x2, y2, z2)
- return {
- x1 / 16 - 0.5,
- y1 / 16 - 0.5,
- z1 / 16 - 0.5,
- x2 / 16 - 0.5,
- y2 / 16 - 0.5,
- z2 / 16 - 0.5,
- }
- end
- -- Also used by walls.
- function stairs.setup_nodedef_callbacks(subname, def)
- if string.find(subname, "ice") or string.find(subname, "snow") then
- assert(not def.on_construct)
- def.on_construct = function(pos)
- if rc.ice_melts_at_pos(pos) then
- minetest.get_node_timer(pos):start(math_random(ice.minmax_time()))
- end
- end
- assert(not def.on_timer)
- def.on_timer = function(pos, elapsed)
- if rc.ice_melts_at_pos(pos) then
- minetest.add_node(pos, {name="default:water_flowing"})
- end
- end
- end
- end
- function stairs.rotate_and_place(itemstack, placer, pt)
- if pt.type == "node" then
- local node = minetest.get_node(pt.under)
- if node.name == itemstack:get_name() then
- local param2 = node.param2
- return minetest.item_place(itemstack, placer, pt, param2)
- end
- end
- return minetest.rotate_node(itemstack, placer, pt)
- end
- dofile(minetest.get_modpath("stairs") .. "/slopes.lua")
- local slabs_defs = {
- ["_quarter"] = {num=4, light=0.25, is_flat=true},
- ["_three_quarter"] = {num=12, light=0.75, is_flat=true},
- ["_1"] = {num=1, light=1/16, is_flat=true},
- ["_2"] = {num=2, light=2/16, is_flat=true},
- ["_14"] = {num=14, light=14/16, is_flat=true},
- ["_15"] = {num=15, light=15/16, is_flat=true},
- ["_two_sides"] = {
- nodebox = {
- { -0.5, -0.5, -0.5, 0.5, -7/16, 7/16 },
- { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
- }
- },
- ["_three_sides"] = {
- nodebox = {
- { -7/16, -0.5, -0.5, 0.5, -7/16, 7/16 },
- { -7/16, -0.5, 7/16, 0.5, 0.5, 0.5 },
- { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
- }
- },
- ["_three_sides_u"] = {
- nodebox = {
- { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
- { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
- { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
- }
- },
- ["_four_sides"] = {
- nodebox = {
- { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
- { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
- { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
- { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
- }
- },
- ["_hole"] = {
- nodebox = {
- {-0.5, -0.5, -0.5, 0.5, 0.5, -7/16},
- {-0.5, -0.5, 0.5, 0.5, 0.5, 7/16},
- {-0.5, -0.5, -7/16, -7/16, 0.5, 7/16},
- {0.5, -0.5, -7/16, 7/16, 0.5, 7/16},
- }
- },
- ["_two_opposite"] = {
- nodebox = {
- {-0.5, -0.5, -0.5, 0.5, 0.5, -7/16},
- {-0.5, -0.5, 0.5, 0.5, 0.5, 7/16},
- }
- },
- ["_pit"] = {
- nodebox = {
- { -0.5, -0.5, -0.5, 0.5, 0.5, -7/16 },
- { -0.5, -0.5, -7/16, 0.5, -7/16, 7/16 },
- { -0.5, -0.5, 7/16, 0.5, 0.5, 0.5 },
- { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
- { -7/16, 0.5, -7/16, 0.5, 7/16, 7/16 },
- }
- },
- ["_pit_half"] = {
- nodebox = {
- { -0.5, -0.5, -0.5, 0.0, 0.5, -7/16 },
- { -0.5, -0.5, -7/16, 0.0, -7/16, 7/16 },
- { -0.5, -0.5, 7/16, 0.0, 0.5, 0.5 },
- { -0.5, -7/16, -7/16, -7/16, 0.5, 7/16 },
- { -7/16, 0.5, -7/16, 0.0, 7/16, 7/16 },
- }
- },
- ["_hole_half"] = {
- nodebox = {
- {-0.5, -0.5, -0.5, 0.5, 0, -7/16},
- {-0.5, -0.5, 0.5, 0.5, 0, 7/16},
- {-0.5, -0.5, -7/16, -7/16, 0, 7/16},
- {0.5, -0.5, -7/16, 7/16, 0, 7/16},
- }
- },
- }
- function stairs.register_extra_slabs(subname, recipeitem, groups, images, description, sounds)
- local stair_images = {}
- for i, image in ipairs(images) do
- if type(image) == "string" then
- stair_images[i] = {
- name = image,
- backface_culling = true,
- }
- elseif image.backface_culling == nil then -- override using any other value
- stair_images[i] = table.copy(image)
- stair_images[i].backface_culling = true
- end
- end
- local defs = table.copy(slabs_defs)
- -- Do not modify function argument.
- local groups = table.copy(groups)
- groups.not_in_craft_guide = 1
- groups.stairs_slab = 1
- groups.stairs_node = 1
-
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- for alternate, num in pairs(defs) do
- local def
- if num.num then
- def = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, -0.5, 0.5, (num.num/16)-0.5, 0.5},
- }
- }
- elseif num.nodebox then
- def = {
- node_box = {
- type = "fixed",
- fixed = num.nodebox,
- }
- }
- end
-
- def.drawtype = "nodebox"
- def.paramtype = "light"
- def.paramtype2 = "facedir"
- def.on_place = function(...) return stairs.rotate_and_place(...) end
- def.groups = groups
- def.sounds = sounds
- def.description = description
- def.tiles = stair_images
- def.light_source = math.ceil(ndef.light_source*(num.light or 0))
- -- Only for flat slabs.
- if num.is_flat then
- def.movement_speed_depends = recipeitem
- end
-
- stairs.setup_nodedef_callbacks(subname, def)
- minetest.register_node(":stairs:slab_" .. subname .. alternate, def)
- end
- if recipeitem then
- circular_saw.known_nodes[recipeitem] = {"stairs", subname}
- end
- end
- local stairs_defs = {
- ["_half"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0, 0, 0.5},
- {-0.5, 0, 0, 0, 0.5, 0.5},
- },
- },
- light=3/8,
- },
- ["_right_half" ]= {
- node_box = {
- type = "fixed",
- fixed = {
- {0, -0.5, -0.5, 0.5, 0, 0.5},
- {0, 0, 0, 0.5, 0.5, 0.5},
- },
- },
- light=3/8,
- },
- ["_half_1"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, -7/16, 0, 0.5},
- {-0.5, 0, 0, -7/16, 0.5, 0.5},
- },
- },
- light=1/8,
- },
- ["_right_half_1" ]= {
- node_box = {
- type = "fixed",
- fixed = {
- {7/16, -0.5, -0.5, 0.5, 0, 0.5},
- {7/16, 0, 0, 0.5, 0.5, 0.5},
- },
- },
- light=1/8,
- },
- ["_inner"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
- {-0.5, 0, 0, 0.5, 0.5, 0.5},
- {-0.5, 0, -0.5, 0, 0.5, 0},
- },
- },
- light=7/8,
- },
- ["_outer"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
- {-0.5, 0, 0, 0, 0.5, 0.5},
- },
- },
- light=5/8,
- },
- ["_alt"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0.5, 0, 0},
- {-0.5, 0, 0, 0.5, 0.5, 0.5},
- },
- },
- light=1/2,
- },
- ["_alt_1"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.0625, -0.5, 0.5, 0, 0},
- {-0.5, 0.4375, 0, 0.5, 0.5, 0.5},
- },
- },
- light=1/16,
- },
- ["_alt_5"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.0625, 0.0, 0.5, 0, 0.5},
- {-0.5, 0.4375, 0, 0.5, 0.5, 0.5},
- },
- },
- light=1/16,
- },
- ["_alt_6"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.0625, -0.5, 0.5, 0, 0.5},
- {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
- },
- },
- light=1/16,
- },
- ["_alt_2"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.125, -0.5, 0.5, 0, 0},
- {-0.5, 0.375, 0, 0.5, 0.5, 0.5},
- },
- },
- light=2/16,
- },
- ["_alt_4"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.25, -0.5, 0.5, 0, 0},
- {-0.5, 0.25, 0, 0.5, 0.5, 0.5},
- },
- },
- light=4/16,
- },
- }
- function stairs.register_extra_stairs(subname, recipeitem, groups, images, description, sounds)
- local stair_images = {}
- for i, image in ipairs(images) do
- if type(image) == "string" then
- stair_images[i] = {
- name = image,
- backface_culling = true,
- }
- elseif image.backface_culling == nil then -- override using any other value
- stair_images[i] = table.copy(image)
- stair_images[i].backface_culling = true
- end
- end
- local defs = table.copy(stairs_defs)
-
- -- Do not modify function argument.
- local groups = table.copy(groups)
- groups.not_in_craft_guide = 1
- groups.stairs_stair = 1
- groups.stairs_node = 1
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- for alternate, def in pairs(defs) do
- def.drawtype = "nodebox"
- def.paramtype = "light"
- def.paramtype2 = "facedir"
- def.on_place = function(...) return stairs.rotate_and_place(...) end
- def.groups = groups
- def.sounds = sounds
- def.description = description
- def.tiles = stair_images
- def.light_source = math.ceil(ndef.light_source*def.light)
- def.light = nil
-
- stairs.setup_nodedef_callbacks(subname, def)
- minetest.register_node(":stairs:stair_" ..subname..alternate, def)
- if recipeitem then
- if alternate == "_inner" then
- minetest.register_craft({
- type = "shapeless",
- output = recipeitem .. ' 7',
- recipe = {
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- },
- })
- minetest.register_craft({
- output = "stairs:stair_" .. subname .. alternate .. ' 8',
- recipe = {
- {recipeitem, recipeitem, recipeitem},
- {recipeitem, recipeitem, ''},
- {recipeitem, '', recipeitem},
- },
- })
- elseif alternate == "_outer" then
- minetest.register_craft({
- type = "shapeless",
- output = recipeitem .. ' 5',
- recipe = {
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- "stairs:stair_" .. subname .. alternate,
- },
- })
- minetest.register_craft({
- output = "stairs:stair_" .. subname .. alternate .. ' 8',
- recipe = {
- {recipeitem, recipeitem, recipeitem},
- {recipeitem, '', ''},
- {recipeitem, '', ''},
- },
- })
- end
- end
- end
- minetest.register_alias("stairs:stair_" ..subname.. "_bottom", "stairs:stair_" ..subname)
- if recipeitem then
- circular_saw.known_nodes[recipeitem] = {"stairs", subname}
- end
- end
- local panels_defs = {
- [""] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, 0, 0.5},
- },
- light=1/4,
- },
- ["_1"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, -0.4375, 0.5},
- },
- light=1/32,
- },
- ["_2"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, -0.375, 0.5},
- },
- light=2/32,
- },
- ["_4"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, -0.25, 0.5},
- },
- light=4/32,
- },
- ["_12"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, 0.25, 0.5},
- },
- light=12/32,
- },
- ["_14"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, 0.375, 0.5},
- },
- light=14/32,
- },
- ["_15"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
- },
- light=15/32,
- },
- ["_16"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0.5, 0.5, 0.5},
- },
- light=16/32,
- },
- -- Nodeboxes for Columns inspired
- -- (but not copied) from Artemis's design in Middle-Ages mod
- -- Licensed: WTFPL
- -- Integrated to circular saw by MustTest
- ["_pillar"] = {
- description = "Column",
- node_box = {
- type = "fixed",
- fixed = {
- pixel_box(2, 0, 5, 14, 16, 11),
- pixel_box(3, 0, 3, 13, 16, 13),
- pixel_box(5, 0, 2, 11, 16, 14),
- },
- },
- selection_box = {
- type = "fixed",
- fixed = {
- pixel_box(2, 0, 2, 14, 16, 14),
- },
- },
- light=1,
- },
- ["_pcend"] = {
- description = "Column End",
- node_box = {
- type = "fixed",
- fixed = {
- pixel_box(2, 0, 5, 14, 16, 11),
- pixel_box(3, 0, 3, 13, 16, 13),
- pixel_box(5, 0, 2, 11, 16, 14),
- pixel_box(0, 0, 0, 16, 3, 16),
- pixel_box(1, 3, 1, 15, 5, 15),
- pixel_box(2, 5, 2, 14, 7, 14),
- },
- },
- selection_box = {
- type = "fixed",
- fixed = {
- -- The 5.1 is intentional, it keeps the wireframe from being burried,
- -- which looks ugly.
- pixel_box(2, 5.1, 2, 14, 16, 14),
- pixel_box(0, 0, 0, 16, 5, 16),
- },
- },
- light=1,
- },
- }
- function stairs.register_panel(subname, recipeitem, groups, images, description, sounds)
- local stair_images = {}
- for i, image in ipairs(images) do
- if type(image) == "string" then
- stair_images[i] = {
- name = image,
- backface_culling = true,
- }
- elseif image.backface_culling == nil then -- override using any other value
- stair_images[i] = table.copy(image)
- stair_images[i].backface_culling = true
- end
- end
- local defs = table.copy(panels_defs)
-
- -- Do not modify function argument.
- local groups = table.copy(groups)
- groups.not_in_craft_guide = 1
- groups.stairs_panel = 1
- groups.stairs_node = 1
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- for alternate, def in pairs(defs) do
- def.drawtype = "nodebox"
- def.paramtype = "light"
- def.paramtype2 = "facedir"
- def.on_place = function(...) return stairs.rotate_and_place(...) end
- def.groups = groups
- def.sounds = sounds
- def.description = description .. " " .. (def.description or "Panel")
- def.tiles = stair_images
- def.light_source = math.ceil(ndef.light_source*def.light)
- def.light = nil
-
- stairs.setup_nodedef_callbacks(subname, def)
- minetest.register_node(":stairs:panel_" ..subname..alternate, def)
- end
- minetest.register_alias("stairs:panel_" ..subname.. "_bottom", "stairs:panel_" ..subname)
- if recipeitem then
- circular_saw.known_nodes[recipeitem] = {"stairs", subname}
- end
- end
- local microblocks_defs = {
- [""] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, 0, 0.5},
- },
- light=8/64,
- },
- ["_c"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.25, -0.5, -0.25, 0.25, 0, 0.25},
- },
- light=8/64,
- },
- ["_1c"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.25, -0.5, -0.25, 0.25, -0.4375, 0.25},
- },
- light=1/64,
- },
- ["_1"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, -0.4375, 0.5},
- },
- light=1/64,
- },
- ["_2"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, -0.375, 0.5},
- },
- light=2/64,
- },
- ["_4"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, -0.25, 0.5},
- },
- light=4/64,
- },
- ["_12"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, 0.25, 0.5},
- },
- light=12/64,
- },
- ["_14"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, 0.375, 0.5},
- },
- light=14/64,
- },
- ["_15"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, 0.4375, 0.5},
- },
- light=15/64,
- },
- ["_16"] = {
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, 0, 0, 0.5, 0.5},
- },
- light=16/64,
- },
- ["_1s"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0, -0.4375, 0},
- {0, -0.5, 0, 0.5, -0.4375, 0.5},
- },
- },
- light=2/64,
- },
- ["_16s"] = {
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0, 0, 0},
- {0, -0.5, 0, 0.5, 0, 0.5},
- },
- },
- light=16/64,
- }
- }
- function stairs.register_micro(subname, recipeitem, groups, images, description, sounds)
- local stair_images = {}
- for i, image in ipairs(images) do
- if type(image) == "string" then
- stair_images[i] = {
- name = image,
- backface_culling = true,
- }
- elseif image.backface_culling == nil then -- override using any other value
- stair_images[i] = table.copy(image)
- stair_images[i].backface_culling = true
- end
- end
- local defs = table.copy(microblocks_defs)
-
- -- Do not modify function argument.
- local groups = table.copy(groups)
- groups.not_in_craft_guide = 1
- groups.stairs_microblock = 1
- groups.stairs_node = 1
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- for alternate, def in pairs(defs) do
- def.drawtype = "nodebox"
- def.paramtype = "light"
- def.paramtype2 = "facedir"
- def.on_place = function(...) return stairs.rotate_and_place(...) end
- def.groups = groups
- def.sounds = sounds
- def.description = description
- def.tiles = stair_images
- def.light_source = math.ceil(ndef.light_source*def.light)
- def.light = nil
-
- stairs.setup_nodedef_callbacks(subname, def)
- minetest.register_node(":stairs:micro_" .. subname .. alternate, def)
- end
- minetest.register_alias("stairs:micro_" ..subname.. "_bottom", "stairs:micro_" ..subname)
- if recipeitem then
- circular_saw.known_nodes[recipeitem] = {"stairs", subname}
- end
- end
- -- Register aliases for new pine node names
- minetest.register_alias("stairs:stair_pinewood", "stairs:stair_pine_wood")
- minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
- -- Register stairs.
- -- Node will be called stairs:stair_<subname>
- function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
- local stair_images = {}
- for i, image in ipairs(images) do
- if type(image) == "string" then
- stair_images[i] = {
- name = image,
- backface_culling = true,
- }
- elseif image.backface_culling == nil then -- override using any other value
- stair_images[i] = table.copy(image)
- stair_images[i].backface_culling = true
- end
- end
- -- Do not modify function argument.
- groups = table.copy(groups)
- groups.stair = 1
- groups.stairs_stair = 1
- groups.not_in_craft_guide = 1
- groups.stairs_node = 1
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- local stair_def = {
- description = description,
- drawtype = "mesh",
- mesh = "stairs_stair.obj",
- tiles = stair_images,
- paramtype = "light",
- paramtype2 = "facedir",
- is_ground_content = false,
- groups = groups,
- sounds = sounds,
- move_speed_stair = recipeitem,
- light_source = math.ceil(ndef.light_source*0.75),
- selection_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
- {-0.5, 0, 0, 0.5, 0.5, 0.5},
- },
- },
- collision_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
- {-0.5, 0, 0, 0.5, 0.5, 0.5},
- },
- },
- on_place = function(itemstack, placer, pointed_thing)
- if pointed_thing.type ~= "node" then
- return itemstack
- end
- local p0 = pointed_thing.under
- local p1 = pointed_thing.above
- local param2 = 0
- local placer_pos = placer:get_pos()
- if placer_pos then
- local dir = {
- x = p1.x - placer_pos.x,
- y = p1.y - placer_pos.y,
- z = p1.z - placer_pos.z
- }
- param2 = minetest.dir_to_facedir(dir)
- end
- if p0.y - 1 == p1.y then
- param2 = param2 + 20
- if param2 == 21 then
- param2 = 23
- elseif param2 == 23 then
- param2 = 21
- end
- end
- return minetest.item_place(itemstack, placer, pointed_thing, param2)
- end,
- }
- stairs.setup_nodedef_callbacks(subname, stair_def)
- minetest.register_node(":stairs:stair_" .. subname, stair_def)
- if recipeitem then
- assert(type(recipeitem) == "string")
- circular_saw.known_nodes[recipeitem] = {"stairs", subname}
- -- Use stairs to craft full blocks again (1:1)
- minetest.register_craft({
- output = recipeitem .. ' 3',
- recipe = {
- {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
- {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
- },
- })
- -- Recipe matches appearence in inventory
- minetest.register_craft({
- output = 'stairs:stair_' .. subname .. ' 8',
- recipe = {
- {"", "", recipeitem},
- {"", recipeitem, recipeitem},
- {recipeitem, recipeitem, recipeitem},
- },
- })
- end
- end
- -- Slab facedir to placement 6d matching table
- local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
- -- Slab facedir when placing initial slab against other surface
- local slab_trans_dir_place = {[0] = 0, 20, 12, 16, 4, 8}
- -- Register slabs.
- -- Node will be called stairs:slab_<subname>
- function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
- -- Do not modify function argument.
- groups = table.copy(groups)
- groups.slab = 1
- groups.stairs_slab = 1
- groups.not_in_craft_guide = 1
- groups.stairs_node = 1
- local ndef = minetest.registered_items[recipeitem]
- assert(ndef)
- local slab_def = {
- description = description,
- drawtype = "nodebox",
- tiles = images,
- paramtype = "light",
- paramtype2 = "facedir",
- is_ground_content = false,
- groups = groups,
- sounds = sounds,
- movement_speed_depends = recipeitem,
- light_source = math.ceil(ndef.light_source*0.5),
- node_box = {
- type = "fixed",
- fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
- },
- on_place = function(itemstack, placer, pointed_thing)
- local under = minetest.get_node(pointed_thing.under)
- local wield_item = itemstack:get_name()
- if under and wield_item == under.name then
- -- place slab using under node orientation
- local dir = minetest.dir_to_facedir(vector.subtract(
- pointed_thing.above, pointed_thing.under), true)
- local p2 = under.param2
- -- combine two slabs if possible
- if slab_trans_dir[math_floor(p2 / 4)] == dir then
- if not recipeitem then
- return itemstack
- end
- local player_name = placer:get_player_name()
- if minetest.is_protected(pointed_thing.under, player_name) and not
- minetest.check_player_privs(placer, "protection_bypass") then
- minetest.record_protection_violation(pointed_thing.under,
- player_name)
- return
- end
- minetest.add_node(pointed_thing.under, {name = recipeitem, param2 = p2})
- itemstack:take_item()
- return itemstack
- end
- -- Placing a slab on an upside down slab should make it right-side up.
- if p2 >= 20 and dir == 8 then
- p2 = p2 - 20
- -- same for the opposite case: slab below normal slab
- elseif p2 <= 3 and dir == 4 then
- p2 = p2 + 20
- end
- -- else attempt to place node with proper param2
- minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
- itemstack:take_item()
- return itemstack
- else
- -- place slab using look direction of player
- local dir = minetest.dir_to_wallmounted(vector.subtract(
- pointed_thing.above, pointed_thing.under), true)
- local rot = slab_trans_dir_place[dir]
- if rot == 0 or rot == 20 then
- rot = rot + minetest.dir_to_facedir(placer:get_look_dir())
- end
- return minetest.item_place(itemstack, placer, pointed_thing, rot)
- end
- end,
- }
- stairs.setup_nodedef_callbacks(subname, slab_def)
- minetest.register_node(":stairs:slab_" .. subname, slab_def)
- if recipeitem then
- -- Use 2 slabs to craft a full block again (1:1)
- minetest.register_craft({
- output = recipeitem,
- recipe = {
- {'stairs:slab_' .. subname},
- {'stairs:slab_' .. subname},
- },
- })
- minetest.register_craft({
- output = 'stairs:slab_' .. subname .. ' 6',
- recipe = {
- {recipeitem, recipeitem, recipeitem},
- },
- })
- end
- end
- -- Stair/slab registration function.
- -- Now includes all extra blocks.
- function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc, sounds)
- stairs.register_micro(subname, recipeitem, groups, images, desc .. " Microblock", sounds)
- stairs.register_panel(subname, recipeitem, groups, images, desc, sounds)
- stairs.register_stair(subname, recipeitem, groups, images, desc .. " Stair", sounds)
- stairs.register_extra_stairs(subname, recipeitem, groups, images, desc .. " Stair", sounds)
- stairs.register_slab(subname, recipeitem, groups, images, desc .. " Slab", sounds)
- stairs.register_extra_slabs(subname, recipeitem, groups, images, desc .. " Slab", sounds)
- stairs.register_slopes(subname, recipeitem, groups, images, desc .. " Slope", sounds)
- end
|