building.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. --[[
  2. This function registers the nodes and craft rezieps for the reinforce stuff
  3. * name: String which is used in description and as technical name (lower letters)
  4. * craftItem: the Item where the reinforce is crafted out of
  5. * nodedef: Nodedefinition table as used as in minetest.register_node()
  6. The Nodes are caled
  7. <modname>:reinforced_<name>
  8. <modname>:reinforced_<name>_slope
  9. <modname>:reinforced_<name>_arrow
  10. <modname>:reinforced_<name>_bars
  11. The modname is automatically the mod that currently calls this function.
  12. e.g. if you call darkage.register_reinforce from the mod medieval modname will be medieval
  13. ]]
  14. function darkage.register_reinforce(name, craftItem, nodedef)
  15. assert(type(nodedef.tiles)=="table","ERRROR: nodedef.tiles have to be a table")
  16. assert(nodedef.tiles[1], "ERROR: "..dump(nodedef.tiles).." requires at least 1 entry")
  17. if nodedef.groups then
  18. nodedef.groups["not_cuttable"] = 1;
  19. else
  20. nodedef.groups = {};
  21. nodedef.groups["not_cuttable"] = 1;
  22. end
  23. local modname = minetest.get_current_modname();
  24. local tname = string.gsub(name:lower()," ", "_"); -- Technical name
  25. -- Reinforced X
  26. local reinforced = table.copy(nodedef);
  27. local reinforced_tname = modname..":reinforced_"..tname
  28. reinforced.description = "Reinforced "..name
  29. for i,tile in ipairs(reinforced.tiles) do
  30. reinforced.tiles[i] = tile .."^darkage_reinforce.png"
  31. end
  32. minetest.register_node(reinforced_tname, reinforced)
  33. minetest.register_craft({
  34. output = reinforced_tname,
  35. recipe = {
  36. {"group:stick", craftItem, "group:stick"},
  37. {craftItem, "group:stick", craftItem},
  38. {"group:stick", craftItem, "group:stick"},
  39. }
  40. })
  41. -- Recycling
  42. minetest.register_craft({
  43. output = craftItem,
  44. recipe = {
  45. { reinforced_tname },
  46. }
  47. })
  48. -- Reinforced Slope
  49. local slope = table.copy(nodedef);
  50. local slope_tname = modname..":reinforced_"..tname.."_slope"
  51. slope.description = "Reinforced "..name.." Slope\nHint: use the screwdriver to rotate."
  52. slope.paramtype2 = "facedir";
  53. local slope_tile_extend = {"^darkage_reinforce_right.png" , "^darkage_reinforce_right.png" , --top ,down
  54. "^darkage_reinforce_right.png" , "^darkage_reinforce_right.png" , --right, left
  55. "^darkage_reinforce_left.png" , "^darkage_reinforce_left.png"} -- front, back
  56. for i=1,6 do
  57. local tile = slope.tiles[i] or nodedef.tiles[1]; -- There have to be at least one tile.
  58. slope.tiles[i] = tile ..slope_tile_extend[i]
  59. end
  60. minetest.register_node(slope_tname, slope)
  61. minetest.register_craft({
  62. output = slope_tname,
  63. recipe = {
  64. {craftItem, craftItem, "group:stick"},
  65. {craftItem, "group:stick", craftItem},
  66. {"group:stick", craftItem, craftItem},
  67. }
  68. })
  69. -- Flipped recipe
  70. minetest.register_craft({
  71. output = slope_tname,
  72. recipe = {
  73. {"group:stick", craftItem, craftItem},
  74. {craftItem, "group:stick", craftItem},
  75. {craftItem, craftItem, "group:stick"},
  76. }
  77. })
  78. -- Recycling
  79. minetest.register_craft({
  80. output = craftItem,
  81. recipe = {
  82. { slope_tname }
  83. }
  84. })
  85. -- Alias to convert old nodes
  86. minetest.register_alias(modname..":reinforced_"..tname.."_right", slope_tname)
  87. minetest.register_alias(modname..":reinforced_"..tname.."_left", slope_tname)
  88. -- Arrow bar
  89. local arrow = table.copy(nodedef)
  90. local arrow_tname = modname..":reinforced_"..tname.."_arrow"
  91. arrow.paramtype2 = "facedir";
  92. arrow.description = "Reinforced "..name.." Arrow \nHint: use the screwdriver to rotate."
  93. local arrow_tile_extend = {"" , "" , --top ,down
  94. "^(darkage_reinforce_arrow.png^[transformR90)" , "^(darkage_reinforce_arrow.png^[transformR270)" , --right, left
  95. "^(darkage_reinforce_arrow.png^[transformR180)" , "^darkage_reinforce_arrow.png"} -- front, back
  96. for i=1,6 do
  97. local tile = arrow.tiles[i] or arrow.tiles[1]; -- There have to be at least one tile.
  98. arrow.tiles[i] = tile .. arrow_tile_extend[i]
  99. end
  100. minetest.register_node(arrow_tname, arrow)
  101. minetest.register_craft({
  102. output = arrow_tname,
  103. recipe = {
  104. {craftItem, "group:stick", craftItem},
  105. {"group:stick", craftItem, "group:stick"},
  106. {"group:stick", craftItem, "group:stick"},
  107. }
  108. })
  109. -- Recycling
  110. minetest.register_craft({
  111. output = craftItem,
  112. recipe = {
  113. { arrow_tname }
  114. }
  115. })
  116. -- Reinforced Bars
  117. local bars = table.copy(nodedef)
  118. local bars_tname = modname..":reinforced_"..tname.."_bars"
  119. bars.description = name.." Bars"
  120. for i,tile in ipairs(bars.tiles) do
  121. bars.tiles[i] = tile .."^darkage_reinforce_bars.png"
  122. end
  123. minetest.register_node(bars_tname, bars)
  124. minetest.register_craft({
  125. output = bars_tname,
  126. recipe = {
  127. {"group:stick", craftItem, "group:stick"},
  128. {"group:stick", craftItem, "group:stick"},
  129. {"group:stick", craftItem, "group:stick"},
  130. }
  131. })
  132. minetest.register_craft({
  133. output = craftItem,
  134. recipe = {
  135. { bars_tname }
  136. }
  137. })
  138. end
  139. darkage.register_reinforce("Chalk", "darkage:chalk_powder", {
  140. tiles = {"darkage_chalk.png"},
  141. groups = {cracky=3},
  142. sounds = default.node_sound_stone_defaults()
  143. })
  144. darkage.register_reinforce("Wood", "default:wood", {
  145. tiles = {"default_wood.png"},
  146. groups = {snappy=2, choppy=3, flammable=3},
  147. sounds = default.node_sound_wood_defaults()
  148. })
  149. darkage.register_reinforce("Chalked Bricks", "darkage:chalked_bricks", {
  150. tiles = {"darkage_chalked_bricks.png"},
  151. groups = {cracky = 2, stone = 1},
  152. sounds = default.node_sound_stone_defaults()
  153. })