init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. -- [Mod] Simple Arcs [pkarcs]
  2. -- by PEAK
  3. -- 06-05-2017
  4. pkarcs = {}
  5. -- define nodes
  6. function pkarcs.register_all(nodename, desc, tile, sound, group, craftmaterial)
  7. local tile_collection
  8. if type(tile) == "string" then
  9. tile_collection[1] = tile
  10. else
  11. tile_collection = table.copy(tile)
  12. end
  13. minetest.register_node(":pkarcs:"..nodename.."_arc", {
  14. description = desc.." Arc",
  15. paramtype = "light",
  16. paramtype2 = "facedir",
  17. tiles = tile_collection,
  18. drawtype = "mesh",
  19. mesh = 'pkarcs_center.obj',
  20. groups = group,
  21. sounds = sound,
  22. on_place = function(itemstack, placer, pointed_thing)
  23. if pointed_thing.type ~= "node" then
  24. return itemstack
  25. end
  26. local p1 = pointed_thing.under
  27. local p0 = pointed_thing.above
  28. local param2 = 0
  29. local placer_pos = placer:get_pos()
  30. if placer_pos then
  31. local dir = {
  32. x = p1.x - placer_pos.x,
  33. y = p1.y - placer_pos.y,
  34. z = p1.z - placer_pos.z
  35. }
  36. param2 = minetest.dir_to_facedir(dir)
  37. end
  38. if p0.y-1 == p1.y then
  39. param2 = param2 + 20
  40. if param2 == 21 then
  41. param2 = 23
  42. elseif param2 == 23 then
  43. param2 = 21
  44. end
  45. end
  46. local NROT = 4 -- Number of possible "rotations" (4 Up down left right)
  47. local rot = param2 % NROT
  48. local wall = math.floor(param2/NROT)
  49. if rot >=3 then
  50. rot = 0
  51. else
  52. rot = rot +1
  53. end
  54. param2 = wall*NROT+rot
  55. return minetest.item_place(itemstack, placer, pointed_thing, param2)
  56. end,
  57. })
  58. minetest.register_node(":pkarcs:"..nodename.."_outer_arc", {
  59. description = desc.." Outer Arc",
  60. paramtype = "light",
  61. paramtype2 = "facedir",
  62. tiles = tile_collection,
  63. drawtype = "mesh",
  64. mesh = 'pkarcs_O_corner.obj',
  65. groups = group,
  66. sounds = sound,
  67. on_place = function(itemstack, placer, pointed_thing)
  68. if pointed_thing.type ~= "node" then
  69. return itemstack
  70. end
  71. local p1 = pointed_thing.under
  72. local p0 = pointed_thing.above
  73. local param2 = 0
  74. local placer_pos = placer:get_pos()
  75. if placer_pos then
  76. local dir = {
  77. x = p1.x - placer_pos.x,
  78. y = p1.y - placer_pos.y,
  79. z = p1.z - placer_pos.z
  80. }
  81. param2 = minetest.dir_to_facedir(dir)
  82. end
  83. if p0.y-1 == p1.y then
  84. param2 = param2 + 20
  85. if param2 == 21 then
  86. param2 = 23
  87. elseif param2 == 23 then
  88. param2 = 21
  89. end
  90. end
  91. local NROT = 4 -- Number of possible "rotations" (4 Up down left right)
  92. local rot = param2 % NROT
  93. local wall = math.floor(param2/NROT)
  94. if rot >=3 then
  95. rot = 0
  96. else
  97. rot = rot +1
  98. end
  99. param2 = wall*NROT+rot
  100. return minetest.item_place(itemstack, placer, pointed_thing, param2)
  101. end,
  102. })
  103. minetest.register_node(":pkarcs:"..nodename.."_inner_arc", {
  104. description = desc.." Inner Arc",
  105. paramtype = "light",
  106. paramtype2 = "facedir",
  107. tiles = tile_collection,
  108. drawtype = "mesh",
  109. mesh = 'pkarcs_I_corner.obj',
  110. groups = group,
  111. sounds = sound,
  112. on_place = function(itemstack, placer, pointed_thing)
  113. if pointed_thing.type ~= "node" then
  114. return itemstack
  115. end
  116. local p1 = pointed_thing.under
  117. local p0 = pointed_thing.above
  118. local param2 = 0
  119. local placer_pos = placer:get_pos()
  120. if placer_pos then
  121. local dir = {
  122. x = p1.x - placer_pos.x,
  123. y = p1.y - placer_pos.y,
  124. z = p1.z - placer_pos.z
  125. }
  126. param2 = minetest.dir_to_facedir(dir)
  127. end
  128. if p0.y-1 == p1.y then
  129. param2 = param2 + 20
  130. if param2 == 21 then
  131. param2 = 23
  132. elseif param2 == 23 then
  133. param2 = 21
  134. end
  135. end
  136. local NROT = 4 -- Number of possible "rotations" (4 Up down left right)
  137. local rot = param2 % NROT
  138. local wall = math.floor(param2/NROT)
  139. if rot >=3 then
  140. rot = 0
  141. else
  142. rot = rot +1
  143. end
  144. param2 = wall*NROT+rot
  145. return minetest.item_place(itemstack, placer, pointed_thing, param2)
  146. end,
  147. })
  148. end
  149. -- register nodes
  150. function pkarcs.register_node(name)
  151. local node_def = minetest.registered_nodes[name]
  152. if not node_def then
  153. minetest.log("warning", "[pkarcs] Skipping unknown node: ".. name)
  154. return
  155. end
  156. local node_name = name:split(':')[2]
  157. if not node_def.tiles then
  158. node_def.tiles = table.copy(node_def.tile_images)
  159. node_def.tile_images = nil
  160. end
  161. pkarcs.register_all(node_name, node_def.description, node_def.tiles, node_def.sounds, node_def.groups, name)
  162. end
  163. function pkarcs.register_craft(station, mod, node)
  164. pkarcs.register_node(mod..':'..node)
  165. stations.dual_register_recipe(station, {
  166. input = {
  167. [mod..':'..node] = 1,
  168. },
  169. output = 'pkarcs:'..node..'_outer_arc 3',
  170. })
  171. stations.dual_register_recipe(station, {
  172. input = {
  173. [mod..':'..node] = 1,
  174. },
  175. output = 'pkarcs:'..node..'_arc 2',
  176. })
  177. stations.dual_register_recipe(station, {
  178. input = {
  179. [mod..':'..node] = 1,
  180. },
  181. output = 'pkarcs:'..node..'_inner_arc',
  182. })
  183. end
  184. pkarcs.register_craft('woodworking', 'default', 'wood')
  185. pkarcs.register_craft('woodworking', 'default', 'junglewood')
  186. pkarcs.register_craft('woodworking', 'default', 'pine_wood')
  187. pkarcs.register_craft('woodworking', 'default', 'acacia_wood')
  188. pkarcs.register_craft('woodworking', 'default', 'aspen_wood')
  189. pkarcs.register_craft('stone_carving', 'asteroid', 'redstone')
  190. pkarcs.register_craft('stone_carving', 'caverealms', 'glow_obsidian')
  191. pkarcs.register_craft('stone_carving', 'caverealms', 'glow_obsidian_2')
  192. pkarcs.register_craft('stone_carving', 'darkage', 'basalt')
  193. pkarcs.register_craft('stone_carving', 'darkage', 'gneiss')
  194. pkarcs.register_craft('stone_carving', 'darkage', 'rhyolitic_tuff')
  195. pkarcs.register_craft('stone_carving', 'darkage', 'marble')
  196. pkarcs.register_craft('stone_carving', 'darkage', 'ors')
  197. pkarcs.register_craft('stone_carving', 'darkage', 'schist')
  198. pkarcs.register_craft('stone_carving', 'darkage', 'serpentine')
  199. pkarcs.register_craft('stone_carving', 'darkage', 'shale')
  200. pkarcs.register_craft('stone_carving', 'darkage', 'slate')
  201. pkarcs.register_craft('stone_carving', 'darkage', 'tuff')
  202. pkarcs.register_craft('stone_carving', 'default', 'brick')
  203. pkarcs.register_craft('stone_carving', 'default', 'desert_stone')
  204. pkarcs.register_craft('stone_carving', 'default', 'desert_sandstone')
  205. pkarcs.register_craft('stone_carving', 'default', 'obsidian')
  206. pkarcs.register_craft('stone_carving', 'default', 'sandstone')
  207. pkarcs.register_craft('stone_carving', 'default', 'silver_sandstone')
  208. pkarcs.register_craft('stone_carving', 'default', 'stone')
  209. pkarcs.register_craft('stone_carving', 'default', 'obsidian')
  210. pkarcs.register_craft('stone_carving', 'moreblocks', 'coal_stone')
  211. pkarcs.register_craft('stone_carving', 'moreblocks', 'iron_stone')
  212. pkarcs.register_craft('stone_carving', 'nether', 'rack')