common.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. def._doc_items_create_entry = false
  28. -- This makes node rotation work on placement
  29. def.place_param2 = nil
  30. -- Darken light sources slightly to make up for their smaller visual size
  31. def.light_source = math.max(0, (def.light_source or 0) - 1)
  32. def.on_place = minetest.rotate_node
  33. def.groups = stairsplus:prepare_groups(fields.groups)
  34. if category == "slab" then
  35. if type(info) ~= "table" then
  36. def.node_box = {
  37. type = "fixed",
  38. fixed = {-0.5, -0.5, -0.5, 0.5, (info/16)-0.5, 0.5},
  39. }
  40. def.description = ("%s (%d/16)"):format(desc_base, info)
  41. else
  42. def.node_box = {
  43. type = "fixed",
  44. fixed = info,
  45. }
  46. def.description = desc_base .. alternate:gsub("_", " "):gsub("(%a)(%S*)", function(a, b) return a:upper() .. b end)
  47. end
  48. else
  49. def.description = desc_base
  50. if category == "slope" then
  51. def.drawtype = "mesh"
  52. elseif category == "stair" and alternate == "" then
  53. def.groups.stair = 1
  54. end
  55. end
  56. if fields.drop and not (type(fields.drop) == "table") then
  57. def.drop = modname.. ":" .. category .. "_" .. fields.drop .. alternate
  58. end
  59. minetest.register_node(":" ..modname.. ":" .. category .. "_" .. subname .. alternate, def)
  60. stairsplus.register_recipes(category, alternate, modname, subname, recipeitem)
  61. end