registration.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. xbg = default.gui_bg .. default.gui_bg_img .. default.gui_slots
  2. local default_inventory_size = 32
  3. local default_inventory_formspecs = {
  4. ["8"] = [[ size[8,6]
  5. list[context;main;0,0;8,1;]
  6. list[current_player;main;0,2;8,4;]
  7. listring[current_player;main]
  8. listring[context;main] ]] ..
  9. default.get_hotbar_bg(0,2),
  10. ["16"] = [[ size[8,7]
  11. list[context;main;0,0;8,2;]
  12. list[current_player;main;0,3;8,4;]
  13. listring[current_player;main]
  14. listring[context;main] ]] ..
  15. default.get_hotbar_bg(0,3),
  16. ["24"] = [[ size[8,8]
  17. list[context;main;0,0;8,3;]
  18. list[current_player;main;0,4;8,4;]
  19. listring[current_player;main]
  20. listring[context;main]" ]] ..
  21. default.get_hotbar_bg(0,4),
  22. ["32"] = [[ size[8,9]
  23. list[context;main;0,0.3;8,4;]
  24. list[current_player;main;0,4.85;8,1;]
  25. list[current_player;main;0,6.08;8,3;8]
  26. listring[current_player;main]
  27. listring[context;main] ]] ..
  28. default.get_hotbar_bg(0,4.85)
  29. }
  30. local function get_formspec_by_size(size)
  31. local formspec = default_inventory_formspecs[tostring(size)]
  32. return formspec or default_inventory_formspecs
  33. end
  34. local default_can_dig = function(pos)
  35. local inv = minetest.get_meta(pos):get_inventory()
  36. return inv:is_empty("main")
  37. end
  38. local function xdecor_stairs_alternative(nodename, def)
  39. local mod, name = nodename:match("(.*):(.*)")
  40. for groupname, value in pairs(def.groups) do
  41. if groupname ~= "cracky" and groupname ~= "choppy" and
  42. groupname ~= "flammable" and groupname ~= "crumbly" and
  43. groupname ~= "snappy" then
  44. def.groups.groupname = nil
  45. end
  46. end
  47. if minetest.get_modpath("moreblocks") then
  48. stairsplus:register_all(
  49. mod,
  50. name,
  51. nodename,
  52. {
  53. description = def.description,
  54. tiles = def.tiles,
  55. groups = def.groups,
  56. sounds = def.sounds,
  57. }
  58. )
  59. elseif minetest.get_modpath("stairs") then
  60. stairs.register_stair_and_slab(name,nodename,
  61. def.groups,
  62. def.tiles,
  63. ("%s Stair"):format(def.description),
  64. ("%s Slab"):format(def.description),
  65. def.sounds
  66. )
  67. end
  68. end
  69. function xdecor.register(name, def)
  70. def.drawtype = def.drawtype or (def.mesh and "mesh") or (def.node_box and "nodebox")
  71. def.sounds = def.sounds or default.node_sound_defaults()
  72. if not (def.drawtype == "normal" or def.drawtype == "signlike" or
  73. def.drawtype == "plantlike" or def.drawtype == "glasslike_framed" or
  74. def.drawtype == "glasslike_framed_optional") then
  75. def.paramtype2 = def.paramtype2 or "facedir"
  76. end
  77. if def.sunlight_propagates ~= false and
  78. (def.drawtype == "plantlike" or def.drawtype == "torchlike" or
  79. def.drawtype == "signlike" or def.drawtype == "fencelike") then
  80. def.sunlight_propagates = true
  81. end
  82. if not def.paramtype and
  83. (def.light_source or def.sunlight_propagates or
  84. def.drawtype == "nodebox" or def.drawtype == "mesh") then
  85. def.paramtype = "light"
  86. end
  87. local infotext = def.infotext
  88. local inventory = def.inventory
  89. def.inventory = nil
  90. if inventory then
  91. def.on_construct = def.on_construct or function(pos)
  92. local meta = minetest.get_meta(pos)
  93. if infotext then meta:set_string("infotext", infotext) end
  94. local size = inventory.size or default_inventory_size
  95. local inv = meta:get_inventory()
  96. inv:set_size("main", size)
  97. meta:set_string("formspec",
  98. (inventory.formspec or get_formspec_by_size(size)) .. xbg)
  99. end
  100. def.can_dig = def.can_dig or default_can_dig
  101. elseif infotext and not def.on_construct then
  102. def.on_construct = function(pos)
  103. local meta = minetest.get_meta(pos)
  104. meta:set_string("infotext", infotext)
  105. end
  106. end
  107. minetest.register_node("xdecor:" .. name, def)
  108. local workbench = minetest.settings:get_bool("enable_xdecor_workbench")
  109. if workbench == false and
  110. (minetest.get_modpath("moreblocks") or minetest.get_modpath("stairs")) then
  111. if xdecor.stairs_valid_def(def) then
  112. xdecor_stairs_alternative("xdecor:"..name, def)
  113. end
  114. end
  115. end