common.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --[[
  2. More Blocks: registrations
  3. Copyright © 2011-2020 Hugo Locurcio and contributors.
  4. Licensed under the zlib license. See LICENSE.md for more information.
  5. --]]
  6. local S = moreblocks.S
  7. local descriptions = {
  8. ["micro"] = S("%s Microblock"),
  9. ["slab"] = S("%s Slab"),
  10. ["slope"] = S("%s Slope"),
  11. ["panel"] = S("%s Panel"),
  12. ["stair"] = S("%s Stairs"),
  13. }
  14. stairsplus.register_single = function(category, alternate, info, modname, subname, recipeitem, fields)
  15. local desc_base = descriptions[category]:format(fields.description)
  16. local def = {}
  17. if category ~= "slab" then
  18. def = table.copy(info)
  19. end
  20. -- copy fields to def
  21. for k, v in pairs(fields) do
  22. def[k] = v
  23. end
  24. def.drawtype = "nodebox"
  25. def.paramtype = "light"
  26. def.paramtype2 = def.paramtype2 or "facedir"
  27. -- This makes node rotation work on placement
  28. def.place_param2 = nil
  29. -- Darken light sources slightly to make up for their smaller visual size
  30. def.light_source = math.max(0, (def.light_source or 0) - 1)
  31. def.on_place = minetest.rotate_node
  32. def.groups = stairsplus:prepare_groups(fields.groups)
  33. if category == "slab" then
  34. if type(info) ~= "table" then
  35. def.node_box = {
  36. type = "fixed",
  37. fixed = {-0.5, -0.5, -0.5, 0.5, (info/16)-0.5, 0.5},
  38. }
  39. def.description = ("%s (%d/16)"):format(desc_base, info)
  40. else
  41. def.node_box = {
  42. type = "fixed",
  43. fixed = info,
  44. }
  45. def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
  46. end
  47. else
  48. def.description = desc_base
  49. if category == "slope" then
  50. def.drawtype = "mesh"
  51. elseif category == "stair" and alternate == "" then
  52. def.groups.stair = 1
  53. end
  54. end
  55. if fields.drop and not (type(fields.drop) == "table") then
  56. def.drop = modname.. ":" .. category .. "_" .. fields.drop .. alternate
  57. end
  58. minetest.register_node(":" ..modname.. ":" .. category .. "_" .. subname .. alternate, def)
  59. stairsplus.register_recipes(category, alternate, modname, subname, recipeitem)
  60. end