api.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. --[[
  2. k_smallblocks is a Minetest mod that adds smaller blocks to minetest aswell as
  3. its own node placement prediction/system
  4. Copyright (C) 2019 Kurtzmusch
  5. This file is part of k_smallblocks
  6. k_smallblocks is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation; either version 2.1 of the License, or (at your option) any
  9. later version.
  10. k_smallblocks is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with k_smallblocks. If not, see <https://www.gnu.org/licenses/>.
  15. --]]
  16. local function register_recipes( node_name, shapeless )
  17. local recipe_type = "shaped"
  18. if( shapeless ) then recipe_type = "shapeless" end
  19. local smallblock_recipes = {
  20. [1] = {
  21. type = recipe_type,
  22. output = "k_smallblocks:1_"..node_name.." 8",
  23. recipe = {
  24. { "default:"..node_name, "", "" },
  25. { "", "", "" },
  26. { "", "", "" }
  27. }
  28. },
  29. [2] = {
  30. type = recipe_type,
  31. output = "k_smallblocks:1_"..node_name.." 2",
  32. recipe = {
  33. { "k_smallblocks:3_"..node_name, "", "" },
  34. { "", "", "" },
  35. { "", "", "" }
  36. }
  37. },
  38. [3] = {
  39. type = recipe_type,
  40. output = "k_smallblocks:1_"..node_name.." 4",
  41. recipe = {
  42. { "k_smallblocks:15_"..node_name, "", "" },
  43. { "", "", "" },
  44. { "", "", "" }
  45. }
  46. },
  47. [4] = {
  48. type = recipe_type,
  49. output = "k_smallblocks:1_"..node_name.." 6",
  50. recipe = {
  51. { "k_smallblocks:63_"..node_name, "", "" },
  52. { "", "", "" },
  53. { "", "", "" }
  54. }
  55. },
  56. }
  57. local halfslab_recipe = {
  58. type = recipe_type,
  59. output = "k_smallblocks:3_"..node_name,
  60. recipe = {
  61. { "k_smallblocks:1_"..node_name, "k_smallblocks:1_"..node_name,"" },
  62. { "", "", "" },
  63. { "", "", "" }
  64. }
  65. }
  66. local slab_recipes = {
  67. [1] = {
  68. type = recipe_type,
  69. output = "k_smallblocks:15_"..node_name,
  70. recipe = {
  71. { "k_smallblocks:1_"..node_name, "k_smallblocks:1_"..node_name,"" },
  72. { "k_smallblocks:1_"..node_name, "k_smallblocks:1_"..node_name, "" },
  73. { "", "", "" }
  74. }
  75. },
  76. [2] = {
  77. type = recipe_type,
  78. output = "k_smallblocks:15_"..node_name,
  79. recipe = {
  80. { "k_smallblocks:3_"..node_name, "", "" },
  81. { "k_smallblocks:3_"..node_name, "", "" },
  82. { "", "", "" }
  83. }
  84. }
  85. }
  86. local fullNode_recipes = {
  87. --TODO
  88. }
  89. local stair_recipe = {
  90. type= recipe_type,
  91. output = "k_smallblocks:63_"..node_name,
  92. recipe = {
  93. { "k_smallblocks:3_"..node_name, "", "" },
  94. { "k_smallblocks:3_"..node_name, "k_smallblocks:3_"..node_name, "" },
  95. { "", "", "" }
  96. }
  97. }
  98. for key_int, val_recipe in pairs( smallblock_recipes ) do
  99. minetest.register_craft( val_recipe )
  100. end
  101. minetest.register_craft( halfslab_recipe )
  102. for key_int, val_recipe in pairs( slab_recipes ) do
  103. minetest.register_craft( val_recipe )
  104. end
  105. minetest.register_craft( stair_recipe )
  106. end
  107. local function register_nodes( node_name )
  108. for key_int, val_bitmap_name in pairs( smallblocks.origin_bitmaps ) do
  109. local origin_bitmap_nodebox = smallblocks.nodeboxes[key_int]
  110. if( bitmap_name_definition_map[val_bitmap_name] ) then
  111. minetest.register_node("k_smallblocks:".. val_bitmap_name.."_"..node_name,
  112. {
  113. description = bitmap_name_definition_map[val_bitmap_name].description,
  114. paramtype = "light",
  115. paramtype2 = "facedir",
  116. drawtype = "nodebox",
  117. tiles = { {name="default_stone_brick.png", align_style="world"} },
  118. is_ground_content = false,
  119. groups = { cracky=2, not_in_creative_inventory= 0},
  120. sunlight_propagates = true,
  121. node_box = {
  122. type = "fixed",
  123. fixed = origin_bitmap_nodebox
  124. },
  125. on_rightclick = common.on_right_click,
  126. on_punch = function()
  127. minetest.chat_send_all( "node got punched" )
  128. end,
  129. on_use = bitmap_name_definition_map[val_bitmap_name].on_use
  130. }
  131. )
  132. else
  133. minetest.register_node("k_smallblocks:"..val_bitmap_name.."_"..node_name,
  134. {
  135. description = node_name.." odd shape",
  136. paramtype = "light",
  137. paramtype2 = "facedir",
  138. drawtype = "nodebox",
  139. tiles = { {name="default_stone_brick.png", align_style="world"} },
  140. is_ground_content = false,
  141. groups = { cracky=2, not_in_creative_inventory= 1},
  142. sunlight_propagates = true,
  143. node_box = {
  144. type = "fixed",
  145. fixed = origin_bitmap_nodebox
  146. },
  147. on_rightclick = common.on_right_click,
  148. on_punch = function()
  149. minetest.chat_send_all( "node got punched" )
  150. end,
  151. }
  152. )
  153. end
  154. end
  155. end
  156. smallblocks.register_node = function( node_name, generate_recipes, shapeless )
  157. register_nodes( node_name )
  158. if( generate_recipes ) then register_recipes( node_name, shapeless ) end
  159. end