panels.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. --[[
  2. More Blocks: panel definitions
  3. Copyright (c) 2011-2017 Hugo Locurcio and contributors.
  4. Licensed under the zlib license. See LICENSE.md for more information.
  5. --]]
  6. local S = moreblocks.intllib
  7. -- Node will be called <modname>:panel_<subname>
  8. function register_panel(modname, subname, recipeitem, groups, images, description, drop, light)
  9. stairsplus:register_panel(modname, subname, recipeitem, {
  10. groups = groups,
  11. tiles = images,
  12. description = description,
  13. drop = drop,
  14. light_source = light,
  15. sounds = default.node_sound_stone_defaults(),
  16. })
  17. end
  18. local panels_defs = {
  19. [""] = {
  20. node_box = {
  21. type = "fixed",
  22. fixed = {-0.5, -0.5, 0, 0.5, 0, 0.5},
  23. },
  24. },
  25. ["_1"] = {
  26. node_box = {
  27. type = "fixed",
  28. fixed = {-0.5, -0.5, 0, 0.5, -0.4375, 0.5},
  29. },
  30. },
  31. ["_2"] = {
  32. node_box = {
  33. type = "fixed",
  34. fixed = {-0.5, -0.5, 0, 0.5, -0.375, 0.5},
  35. },
  36. },
  37. ["_4"] = {
  38. node_box = {
  39. type = "fixed",
  40. fixed = {-0.5, -0.5, 0, 0.5, -0.25, 0.5},
  41. },
  42. },
  43. ["_12"] = {
  44. node_box = {
  45. type = "fixed",
  46. fixed = {-0.5, -0.5, 0, 0.5, 0.25, 0.5},
  47. },
  48. },
  49. ["_14"] = {
  50. node_box = {
  51. type = "fixed",
  52. fixed = {-0.5, -0.5, 0, 0.5, 0.375, 0.5},
  53. },
  54. },
  55. ["_15"] = {
  56. node_box = {
  57. type = "fixed",
  58. fixed = {-0.5, -0.5, 0, 0.5, 0.4375, 0.5},
  59. },
  60. }
  61. }
  62. for k,v in pairs(panels_defs) do
  63. table.insert(stairsplus.shapes_list, { "panel_", k })
  64. end
  65. function stairsplus:register_panel_alias(modname_old, subname_old, modname_new, subname_new)
  66. local defs = stairsplus.copytable(panels_defs)
  67. for alternate, def in pairs(defs) do
  68. minetest.register_alias(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate)
  69. end
  70. end
  71. function stairsplus:register_panel_alias_force(modname_old, subname_old, modname_new, subname_new)
  72. local defs = stairsplus.copytable(panels_defs)
  73. for alternate, def in pairs(defs) do
  74. minetest.register_alias_force(modname_old .. ":panel_" .. subname_old .. alternate, modname_new .. ":panel_" .. subname_new .. alternate)
  75. end
  76. end
  77. function stairsplus:register_panel(modname, subname, recipeitem, fields)
  78. local defs = stairsplus.copytable(panels_defs)
  79. local desc = S("%s Panel"):format(fields.description)
  80. local use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "blend" or fields.use_texture_alpha
  81. for alternate, def in pairs(defs) do
  82. for k, v in pairs(fields) do
  83. def[k] = v
  84. end
  85. def.drawtype = "nodebox"
  86. def.paramtype = "light"
  87. def.paramtype2 = def.paramtype2 or "facedir"
  88. def.use_texture_alpha = use_texture_alpha
  89. def.on_place = minetest.rotate_node
  90. def.description = desc
  91. def.groups = stairsplus:prepare_groups(fields.groups)
  92. if alternate == "_1" then
  93. def.groups.not_blocking_trains = 1
  94. end
  95. if fields.drop and not (type(fields.drop) == "table") then
  96. def.drop = modname.. ":panel_" ..fields.drop..alternate
  97. end
  98. minetest.register_node(":" ..modname.. ":panel_" ..subname..alternate, def)
  99. end
  100. minetest.register_alias(modname.. ":panel_" ..subname.. "_bottom", modname.. ":panel_" ..subname)
  101. circular_saw.known_nodes[recipeitem] = {modname, subname}
  102. -- Some saw-less recipes:
  103. minetest.register_craft({
  104. output = modname .. ":panel_" .. subname .. " 12",
  105. recipe = {
  106. {recipeitem, ""},
  107. {recipeitem, recipeitem},
  108. },
  109. })
  110. minetest.register_craft({
  111. output = modname .. ":panel_" .. subname .. " 12",
  112. recipe = {
  113. {"", recipeitem},
  114. {recipeitem, recipeitem},
  115. },
  116. })
  117. minetest.register_craft({
  118. type = "shapeless",
  119. output = modname .. ":panel_" .. subname,
  120. recipe = {modname .. ":micro_" .. subname, modname .. ":micro_" .. subname},
  121. })
  122. minetest.register_craft({
  123. type = "shapeless",
  124. output = recipeitem,
  125. recipe = {modname .. ":panel_" .. subname, modname .. ":panel_" .. subname, modname .. ":panel_" .. subname, modname .. ":panel_" .. subname},
  126. })
  127. end