init.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. -- make arcs for all default stone and wood nodes
  164. pkarcs.register_node("default:cobble")
  165. pkarcs.register_node("default:mossycobble")
  166. pkarcs.register_node("default:desert_cobble")
  167. pkarcs.register_node("default:stone")
  168. pkarcs.register_node("default:stonebrick")
  169. pkarcs.register_node("default:stone_block")
  170. pkarcs.register_node("default:desert_stone")
  171. pkarcs.register_node("default:desert_stonebrick")
  172. pkarcs.register_node("default:desert_stone_block")
  173. pkarcs.register_node("default:desert_sandstone")
  174. pkarcs.register_node("default:desert_sandstone_block")
  175. pkarcs.register_node("default:desert_sandstone_brick")
  176. pkarcs.register_node("default:silver_sandstone")
  177. pkarcs.register_node("default:silver_sandstone_block")
  178. pkarcs.register_node("default:silver_sandstone_brick")
  179. pkarcs.register_node("default:sandstone")
  180. pkarcs.register_node("default:sandstonebrick")
  181. pkarcs.register_node("default:sandstone_block")
  182. pkarcs.register_node("default:brick")
  183. pkarcs.register_node("default:obsidian")
  184. pkarcs.register_node("default:obsidianbrick")
  185. pkarcs.register_node("default:obsidian_block")
  186. function pkarcs.register_craft(station, mod, node)
  187. pkarcs.register_node(mod..':'..node)
  188. stations.dual_register_recipe(station, {
  189. input = {
  190. [mod..':'..node] = 1,
  191. },
  192. output = 'pkarcs:'..node..'_outer_arc 3',
  193. })
  194. stations.dual_register_recipe(station, {
  195. input = {
  196. [mod..':'..node] = 1,
  197. },
  198. output = 'pkarcs:'..node..'_arc 2',
  199. })
  200. stations.dual_register_recipe(station, {
  201. input = {
  202. [mod..':'..node] = 1,
  203. },
  204. output = 'pkarcs:'..node..'_inner_arc',
  205. })
  206. end
  207. pkarcs.register_craft('woodworking', 'default', 'wood')
  208. pkarcs.register_craft('woodworking', 'default', 'junglewood')
  209. pkarcs.register_craft('woodworking', 'default', 'pine_wood')
  210. pkarcs.register_craft('woodworking', 'default', 'acacia_wood')
  211. pkarcs.register_craft('woodworking', 'default', 'aspen_wood')