registration.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. function xdecor.register(name, def)
  39. def = xdecor.tablecopy(def) -- Don't modify input table.
  40. local function xdecor_stairs_alternative(nodename, def)
  41. local mod, name = nodename:match("(.*):(.*)")
  42. for groupname, value in pairs(def.groups) do
  43. if groupname ~= "cracky" and groupname ~= "choppy" and
  44. groupname ~= "flammable" and groupname ~= "crumbly" and
  45. groupname ~= "snappy" then
  46. def.groups[groupname] = nil
  47. end
  48. end
  49. stairs.register_stair_and_slab(
  50. "xd_" .. name, -- Don't clobber names from other mods.
  51. nodename,
  52. def.groups,
  53. def.tiles,
  54. utility.get_short_desc(def.description),
  55. def.sounds
  56. )
  57. end
  58. def.drawtype = def.drawtype or (def.mesh and "mesh") or (def.node_box and "nodebox")
  59. def.sounds = def.sounds or default.node_sound_defaults()
  60. if not (def.drawtype == "normal" or def.drawtype == "signlike" or
  61. def.drawtype == "plantlike" or def.drawtype == "glasslike_framed" or
  62. def.drawtype == "glasslike_framed_optional") then
  63. def.paramtype2 = def.paramtype2 or "facedir"
  64. end
  65. if def.sunlight_propagates ~= false and
  66. (def.drawtype == "plantlike" or def.drawtype == "torchlike" or
  67. def.drawtype == "signlike" or def.drawtype == "fencelike") then
  68. def.sunlight_propagates = true
  69. end
  70. if not def.paramtype and
  71. (def.light_source or def.sunlight_propagates or
  72. def.drawtype == "nodebox" or def.drawtype == "mesh") then
  73. def.paramtype = "light"
  74. end
  75. local infotext = def.infotext
  76. local inventory = def.inventory
  77. def.inventory = nil
  78. if inventory then
  79. def.on_construct = def.on_construct or function(pos)
  80. local meta = minetest.get_meta(pos)
  81. if infotext then meta:set_string("infotext", infotext) end
  82. local size = inventory.size or default_inventory_size
  83. local inv = meta:get_inventory()
  84. inv:set_size("main", size)
  85. meta:set_string("formspec", (inventory.formspec or
  86. get_formspec_by_size(size))..xbg)
  87. end
  88. def.can_dig = def.can_dig or default_can_dig
  89. elseif infotext and not def.on_construct then
  90. def.on_construct = function(pos)
  91. local meta = minetest.get_meta(pos)
  92. meta:set_string("infotext", infotext)
  93. end
  94. end
  95. minetest.register_node("xdecor:"..name, def)
  96. if xdecor.stairs_valid_def(def) then
  97. xdecor_stairs_alternative("xdecor:"..name, def)
  98. end
  99. end