spiral.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. potions.utils.area = function(out, min, max, node)
  2. local n
  3. if type(node) == "string" then
  4. n = {name=node}
  5. else
  6. n = node
  7. end
  8. local minx = math.min(min.x, max.x)
  9. local miny = math.min(min.y, max.y)
  10. local minz = math.min(min.z, max.z)
  11. local maxx = math.max(min.x, max.x)
  12. local maxy = math.max(min.y, max.y)
  13. local maxz = math.max(min.z, max.z)
  14. for y = miny,maxy do
  15. for x = minx,maxx do
  16. for z = minz,maxz do
  17. table.insert(out, {{x=x, y=y, z=z}, n})
  18. end
  19. end
  20. end
  21. return out
  22. end
  23. potions.utils.stairs = function(out, start, dir, height, stair_node, space_above, fill_node)
  24. -- local out = {}
  25. local adv = {x=0, z=0}
  26. local param2 = minetest.dir_to_facedir(dir)
  27. for h = 0,height-1 do
  28. local p = {x=start.x+adv.x, y=start.y+h, z=start.z+adv.z}
  29. table.insert(out, {vector.new(p), {name=stair_node, param2=param2}})
  30. if fill_node then
  31. while p.y > start.y do
  32. p.y = p.y - 1
  33. table.insert(out, {vector.new(p), {name=fill_node, param2=param2}})
  34. end
  35. end
  36. p.y = start.y + h + 1
  37. for i = 1,space_above do
  38. table.insert(out, {vector.new(p), {name="air"}})
  39. p.y = p.y + 1
  40. end
  41. adv.x = adv.x + dir.x
  42. adv.z = adv.z + dir.z
  43. end
  44. return out
  45. end
  46. potions.utils.disc_cheap = function(out, pos, radius, node)
  47. local r = math.ceil(radius)
  48. -- local out = {}
  49. for x = -r,r do
  50. for z = -r,r do
  51. if radius >= math.sqrt(x*x + z*z) then
  52. table.insert(out, {{x=pos.x+x, y=pos.y, z=pos.z+z}, {name=node}})
  53. end
  54. end
  55. end
  56. return out
  57. end
  58. -- the nodes are not in consecutive order
  59. potions.utils.circle_cheap = function(out, pos, radius, node)
  60. local r = radius
  61. local r2f = math.floor(r * math.sin(math.pi/4) + .5)
  62. local r2c = math.floor(r * math.sin(math.pi/4) + .5)
  63. -- local out = {}
  64. for x = -r2f,r2c,1 do
  65. local z = math.sqrt(r*r - x*x)
  66. table.insert(out, {{x=pos.x+x, y=pos.y, z=pos.z+z}, {name=node}})
  67. table.insert(out, {{x=pos.x+x, y=pos.y, z=pos.z-z}, {name=node}})
  68. -- minetest.set_node({x=pos.x+x, y=pos.y, z=pos.z+z}, {name=node})
  69. -- minetest.set_node({x=pos.x+x, y=pos.y, z=pos.z-z}, {name=node})
  70. end
  71. for z = -r2f,r2c,1 do
  72. local x = math.sqrt(r*r - z*z)
  73. table.insert(out, {{x=pos.x+x, y=pos.y, z=pos.z+z}, {name=node}})
  74. table.insert(out, {{x=pos.x-x, y=pos.y, z=pos.z+z}, {name=node}})
  75. -- minetest.set_node({x=pos.x+x, y=pos.y+1, z=pos.z+z}, {name=node})
  76. -- minetest.set_node({x=pos.x-x, y=pos.y+1, z=pos.z+z}, {name=node})
  77. end
  78. return out
  79. end
  80. -- the nodes are not in consecutive order
  81. potions.utils.cylinder_cheap = function(out, pos, radius, height, node)
  82. local circ = potions.utils.circle_cheap({}, pos, radius, node)
  83. -- local out = {}
  84. for h = 1,height do
  85. for _,pn in ipairs(circ) do
  86. table.insert(out, {vector.add(pn[1], {x=0, y=h, z=0}), pn[2]})
  87. end
  88. end
  89. return out
  90. end
  91. minetest.register_craftitem("potions:test_tool", {
  92. description = "Test Tool",
  93. inventory_image = "default_sand.png",
  94. groups = {cracky=3,},
  95. liquids_pointable=true,
  96. on_use = function(itemstack, player, pointed_thing)
  97. local pos = pointed_thing.above
  98. pos.y=pos.y-1
  99. local meta = minetest.get_meta(pos)
  100. print(dump(meta:to_table()))
  101. end,
  102. })
  103. minetest.register_craftitem("potions:spiral_test", {
  104. description = "Spiral Seed",
  105. inventory_image = "default_brick.png",
  106. groups = {cracky=3,},
  107. liquids_pointable=true,
  108. on_use = function(itemstack, player, pointed_thing)
  109. local pos = pointed_thing.above
  110. if not pos then
  111. return
  112. end
  113. pos.y = pos.y + 1
  114. local nodes = {}
  115. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+0, z=pos.z}, 6.8, "default:stonebrick")
  116. -- minetest.bulk_set_node(disc, {name="default:wood"})
  117. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+5, z=pos.z}, 6.8, "default:wood")
  118. -- minetest.bulk_set_node(disc, {name="default:wood"})
  119. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+10, z=pos.z}, 6.8, "default:aspen_wood")
  120. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+15, z=pos.z}, 6.8, "default:pine_wood")
  121. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+20, z=pos.z}, 6.8, "default:junglewood")
  122. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+25, z=pos.z}, 6.8, "default:wood")
  123. potions.utils.disc_cheap(nodes, {x=pos.x, y=pos.y+30, z=pos.z}, 6.8, "default:wood")
  124. -- minetest.bulk_set_node(disc, {name="default:wood"})
  125. local opos = vector.new(pos)
  126. potions.utils.stairs(nodes, vector.add(pos, {x=2,y=1,z=0}), {x=-1, z=0}, 5, "stairs:stair_stonebrick", 3, "default:tree")
  127. potions.utils.stairs(nodes, vector.add(pos, {x=-2,y=6,z=1}), {x=1, z=0}, 5, "stairs:stair_wood", 3, "default:tree")
  128. potions.utils.stairs(nodes, vector.add(pos, {x=2,y=11,z=0}), {x=-1, z=0}, 5, "stairs:stair_aspen_wood", 3, "default:tree")
  129. potions.utils.stairs(nodes, vector.add(pos, {x=-2,y=16,z=1}), {x=1, z=0}, 5, "stairs:stair_pine_wood", 3, "default:tree")
  130. potions.utils.stairs(nodes, vector.add(pos, {x=2,y=21,z=0}), {x=-1, z=0}, 5, "stairs:stair_junglewood", 3, "default:tree")
  131. potions.utils.stairs(nodes, vector.add(pos, {x=-2,y=26,z=1}), {x=1, z=0}, 5, "stairs:stair_wood", 3, "default:tree")
  132. pos = opos
  133. pos.y = pos.y - 1
  134. potions.utils.cylinder_cheap(nodes, pos, 7, 32, "default:stonebrick")
  135. -- door
  136. table.insert(nodes, {{x=pos.x+7, y=pos.y+3, z=pos.z}, {name="air"}})
  137. table.insert(nodes, {{x=pos.x+7, y=pos.y+2, z=pos.z}, {name="doors:door_steel_a", param2=1}})
  138. -- windows
  139. table.insert(nodes, {{x=pos.x+7, y=pos.y+8, z=pos.z}, {name="xpanes:bar_flat", param2=3}})
  140. table.insert(nodes, {{x=pos.x+7, y=pos.y+13, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  141. table.insert(nodes, {{x=pos.x+7, y=pos.y+18, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  142. table.insert(nodes, {{x=pos.x+7, y=pos.y+23, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  143. table.insert(nodes, {{x=pos.x+7, y=pos.y+28, z=pos.z}, {name="xpanes:obsidian_pane_flat", param2=3}})
  144. table.insert(nodes, {{x=pos.x-7, y=pos.y+8, z=pos.z}, {name="xpanes:bar_flat", param2=3}})
  145. table.insert(nodes, {{x=pos.x-7, y=pos.y+13, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  146. table.insert(nodes, {{x=pos.x-7, y=pos.y+18, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  147. table.insert(nodes, {{x=pos.x-7, y=pos.y+23, z=pos.z}, {name="xpanes:pane_flat", param2=3}})
  148. table.insert(nodes, {{x=pos.x-7, y=pos.y+28, z=pos.z}, {name="xpanes:obsidian_pane_flat", param2=3}})
  149. table.insert(nodes, {{x=pos.x, y=pos.y+8, z=pos.z+7}, {name="xpanes:bar_flat", param2=0}})
  150. table.insert(nodes, {{x=pos.x, y=pos.y+13, z=pos.z+7}, {name="xpanes:pane_flat", param2=0}})
  151. table.insert(nodes, {{x=pos.x, y=pos.y+18, z=pos.z+7}, {name="xpanes:pane_flat", param2=0}})
  152. table.insert(nodes, {{x=pos.x, y=pos.y+23, z=pos.z+7}, {name="xpanes:pane_flat", param2=0}})
  153. table.insert(nodes, {{x=pos.x, y=pos.y+28, z=pos.z+7}, {name="xpanes:obsidian_pane_flat", param2=0}})
  154. table.insert(nodes, {{x=pos.x, y=pos.y+8, z=pos.z-7}, {name="xpanes:bar_flat", param2=0}})
  155. table.insert(nodes, {{x=pos.x, y=pos.y+13, z=pos.z-7}, {name="xpanes:pane_flat", param2=0}})
  156. table.insert(nodes, {{x=pos.x, y=pos.y+18, z=pos.z-7}, {name="xpanes:pane_flat", param2=0}})
  157. table.insert(nodes, {{x=pos.x, y=pos.y+23, z=pos.z-7}, {name="xpanes:pane_flat", param2=0}})
  158. table.insert(nodes, {{x=pos.x, y=pos.y+28, z=pos.z-7}, {name="xpanes:obsidian_pane_flat", param2=0}})
  159. -- first level torches
  160. table.insert(nodes, {{x=pos.x-6, y=pos.y+4, z=pos.z}, {name="default:torch_wall", param2=3}})
  161. table.insert(nodes, {{x=pos.x, y=pos.y+4, z=pos.z+6}, {name="default:torch_wall", param2=4}})
  162. table.insert(nodes, {{x=pos.x, y=pos.y+4, z=pos.z-6}, {name="default:torch_wall", param2=5}})
  163. -- second level beds
  164. table.insert(nodes, {{x=pos.x-3, y=pos.y+7, z=pos.z-5}, {name="beds:fancy_bed_top", param2=2}})
  165. table.insert(nodes, {{x=pos.x-3, y=pos.y+7, z=pos.z-4}, {name="beds:fancy_bed_bottom", param2=2}})
  166. table.insert(nodes, {{x=pos.x-1, y=pos.y+7, z=pos.z-5}, {name="beds:fancy_bed_top", param2=2}})
  167. table.insert(nodes, {{x=pos.x-1, y=pos.y+7, z=pos.z-4}, {name="beds:fancy_bed_bottom", param2=2}})
  168. table.insert(nodes, {{x=pos.x+1, y=pos.y+7, z=pos.z-5}, {name="beds:fancy_bed_top", param2=2}})
  169. table.insert(nodes, {{x=pos.x+1, y=pos.y+7, z=pos.z-4}, {name="beds:fancy_bed_bottom", param2=2}})
  170. table.insert(nodes, {{x=pos.x+3, y=pos.y+7, z=pos.z-5}, {name="beds:fancy_bed_top", param2=2}})
  171. table.insert(nodes, {{x=pos.x+3, y=pos.y+7, z=pos.z-4}, {name="beds:fancy_bed_bottom", param2=2}})
  172. table.insert(nodes, {{x=pos.x-3, y=pos.y+7, z=pos.z+5}, {name="beds:fancy_bed_top", param2=0}})
  173. table.insert(nodes, {{x=pos.x-3, y=pos.y+7, z=pos.z+4}, {name="beds:fancy_bed_bottom", param2=0}})
  174. table.insert(nodes, {{x=pos.x-1, y=pos.y+7, z=pos.z+5}, {name="beds:fancy_bed_top", param2=0}})
  175. table.insert(nodes, {{x=pos.x-1, y=pos.y+7, z=pos.z+4}, {name="beds:fancy_bed_bottom", param2=0}})
  176. table.insert(nodes, {{x=pos.x+1, y=pos.y+7, z=pos.z+5}, {name="beds:fancy_bed_top", param2=0}})
  177. table.insert(nodes, {{x=pos.x+1, y=pos.y+7, z=pos.z+4}, {name="beds:fancy_bed_bottom", param2=0}})
  178. table.insert(nodes, {{x=pos.x+3, y=pos.y+7, z=pos.z+5}, {name="beds:fancy_bed_top", param2=0}})
  179. table.insert(nodes, {{x=pos.x+3, y=pos.y+7, z=pos.z+4}, {name="beds:fancy_bed_bottom", param2=0}})
  180. local food_inv = {}
  181. for _ = 1,32 do table.insert(food_inv, "default:apple 99") end
  182. table.insert(nodes, {{x=pos.x+6, y=pos.y+7, z=pos.z+2}, {name="default:chest", param2=1}, {main=food_inv}})
  183. table.insert(nodes, {{x=pos.x+6, y=pos.y+7, z=pos.z+1}, {name="default:chest", param2=1}, {main=food_inv}})
  184. table.insert(nodes, {{x=pos.x+6, y=pos.y+7, z=pos.z-1}, {name="default:chest", param2=1}, {main=food_inv}})
  185. table.insert(nodes, {{x=pos.x+6, y=pos.y+7, z=pos.z-2}, {name="default:chest", param2=1}, {main=food_inv}})
  186. local box_ring = {
  187. {{x=5, y=0, z=-4}, 1},
  188. {{x=5, y=0, z=-3}, 1},
  189. {{x=6, y=0, z=-2}, 1},
  190. {{x=6, y=0, z=-1}, 1},
  191. {{x=6, y=0, z=1}, 1},
  192. {{x=6, y=0, z=2}, 1},
  193. {{x=5, y=0, z=3}, 1},
  194. {{x=5, y=0, z=4}, 1},
  195. {{x=-5, y=0, z=-4}, 3},
  196. {{x=-5, y=0, z=-3}, 3},
  197. {{x=-6, y=0, z=-2}, 3},
  198. {{x=-6, y=0, z=-1}, 3},
  199. {{x=-6, y=0, z=1}, 3},
  200. {{x=-6, y=0, z=2}, 3},
  201. {{x=-5, y=0, z=3}, 3},
  202. {{x=-5, y=0, z=4}, 3},
  203. {{x=-4, y=0, z=5}, 0},
  204. {{x=-3, y=0, z=5}, 0},
  205. {{x=-2, y=0, z=6}, 0},
  206. {{x=-1, y=0, z=6}, 0},
  207. {{x=1, y=0, z=6}, 0},
  208. {{x=2, y=0, z=6}, 0},
  209. {{x=3, y=0, z=5}, 0},
  210. {{x=4, y=0, z=5}, 0},
  211. {{x=-4, y=0, z=-5}, 2},
  212. {{x=-3, y=0, z=-5}, 2},
  213. {{x=-2, y=0, z=-6}, 2},
  214. {{x=-1, y=0, z=-6}, 2},
  215. {{x=1, y=0, z=-6}, 2},
  216. {{x=2, y=0, z=-6}, 2},
  217. {{x=3, y=0, z=-5}, 2},
  218. {{x=4, y=0, z=-5}, 2},
  219. }
  220. -- local main = {"default:dirt 12"}
  221. local book_inv = {}
  222. for _ = 1,16 do table.insert(book_inv, "default:book") end
  223. -- local book_inv = {}
  224. -- for _ = 1,16 do table.insert(book_inv, "default:book") end
  225. for i,v in ipairs(box_ring) do
  226. table.insert(nodes, {vector.add({x=0,y=17,z=0}, vector.add(pos, v[1])), {name="default:chest_locked", param2=v[2]}, {}})
  227. table.insert(nodes, {vector.add({x=0,y=22,z=0}, vector.add(pos, v[1])), {name="vessels:shelf", param2=v[2]}, {}})
  228. table.insert(nodes, {vector.add({x=0,y=23,z=0}, vector.add(pos, v[1])), {name="vessels:shelf", param2=v[2]}, {}})
  229. table.insert(nodes, {vector.add({x=0,y=27,z=0}, vector.add(pos, v[1])), {name="default:bookshelf", param2=v[2]}, {books=book_inv}})
  230. table.insert(nodes, {vector.add({x=0,y=28,z=0}, vector.add(pos, v[1])), {name="default:bookshelf", param2=v[2]}, {books=book_inv}})
  231. table.insert(nodes, {vector.add({x=0,y=29,z=0}, vector.add(pos, v[1])), {name="default:bookshelf", param2=v[2]}, {books=book_inv}})
  232. table.insert(nodes, {vector.add({x=0,y=30,z=0}, vector.add(pos, v[1])), {name="default:bookshelf", param2=v[2]}, {books=book_inv}})
  233. end
  234. -- workshop equipment
  235. table.insert(nodes, {{x=pos.x+1, y=pos.y+22, z=pos.z-3}, {name="default:wood", param2=0}})
  236. table.insert(nodes, {{x=pos.x+1, y=pos.y+23, z=pos.z-3}, {name="potions:glass_still", param2=0}})
  237. table.insert(nodes, {{x=pos.x+0, y=pos.y+22, z=pos.z-3}, {name="default:wood", param2=0}})
  238. table.insert(nodes, {{x=pos.x+0, y=pos.y+23, z=pos.z-3}, {name="potions:glass_still", param2=0}})
  239. table.insert(nodes, {{x=pos.x-1, y=pos.y+22, z=pos.z-3}, {name="default:wood", param2=0}})
  240. table.insert(nodes, {{x=pos.x-1, y=pos.y+23, z=pos.z-3}, {name="potions:glass_still", param2=0}})
  241. table.insert(nodes, {{x=pos.x, y=pos.y+27, z=pos.z-3}, {name="potions:ench_table_wood", param2=0}})
  242. -- coral tank contents
  243. table.insert(nodes, {{x=pos.x+2, y=pos.y+12, z=pos.z-6}, {name="default:sand", param2=0}})
  244. table.insert(nodes, {{x=pos.x+1, y=pos.y+12, z=pos.z-6}, {name="default:coral_green", param2=0}})
  245. table.insert(nodes, {{x=pos.x, y=pos.y+12, z=pos.z-6}, {name="default:coral_cyan", param2=0}})
  246. table.insert(nodes, {{x=pos.x-1, y=pos.y+12, z=pos.z-6}, {name="default:coral_pink", param2=0}})
  247. table.insert(nodes, {{x=pos.x-2, y=pos.y+12, z=pos.z-6}, {name="default:sand", param2=0}})
  248. table.insert(nodes, {{x=pos.x+2, y=pos.y+12, z=pos.z+6}, {name="default:sand", param2=0}})
  249. table.insert(nodes, {{x=pos.x+1, y=pos.y+12, z=pos.z+6}, {name="default:coral_green", param2=0}})
  250. table.insert(nodes, {{x=pos.x, y=pos.y+12, z=pos.z+6}, {name="default:coral_pink", param2=0}})
  251. table.insert(nodes, {{x=pos.x-1, y=pos.y+12, z=pos.z+6}, {name="default:coral_cyan", param2=0}})
  252. table.insert(nodes, {{x=pos.x-2, y=pos.y+12, z=pos.z+6}, {name="default:sand", param2=0}})
  253. table.insert(nodes, {{x=pos.x+2, y=pos.y+12, z=pos.z+6}, {name="default:sand", param2=0}})
  254. -- coral tank water
  255. potions.utils.area(nodes, {x=pos.x-2, y=pos.y+13, z=pos.z+6},{x=pos.x+2, y=pos.y+13, z=pos.z+6}, "default:river_water_source")
  256. potions.utils.area(nodes, {x=pos.x-2, y=pos.y+13, z=pos.z-6},{x=pos.x+2, y=pos.y+13, z=pos.z-6}, "default:river_water_source")
  257. -- coral tank glass
  258. potions.utils.area(nodes, {x=pos.x-3, y=pos.y+12, z=pos.z+5},{x=pos.x+3, y=pos.y+13, z=pos.z+5}, "default:obsidian_glass")
  259. potions.utils.area(nodes, {x=pos.x-3, y=pos.y+12, z=pos.z-5},{x=pos.x+3, y=pos.y+13, z=pos.z-5}, "default:obsidian_glass")
  260. table.insert(nodes, {{x=pos.x-6, y=pos.y+17, z=pos.z+0}, {name="default:furnace", param2=3}})
  261. table.insert(nodes, {{x=pos.x+6, y=pos.y+17, z=pos.z+0}, {name="default:furnace", param2=1}})
  262. table.insert(nodes, {{x=pos.x+0, y=pos.y+17, z=pos.z+6}, {name="default:furnace", param2=0}})
  263. table.insert(nodes, {{x=pos.x+0, y=pos.y+17, z=pos.z-6}, {name="default:furnace", param2=2}})
  264. potions.utils.spawn_set(nodes, .5, 500)
  265. end,
  266. })