init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. lottother = {}
  2. dofile(minetest.get_modpath("lottother").."/rings/rings.lua")
  3. dofile(minetest.get_modpath("lottother").."/rings/gems.lua")
  4. dofile(minetest.get_modpath("lottother").."/rings/ringsilver.lua")
  5. dofile(minetest.get_modpath("lottother").."/rings/ringcraft.lua")
  6. dofile(minetest.get_modpath("lottother").."/mob_spawners.lua")
  7. dofile(minetest.get_modpath("lottother").."/credits.lua")
  8. minetest.register_node("lottother:blue_flame", {
  9. description = "Blue Flame",
  10. drawtype = "firelike",
  11. tiles = {{
  12. name="lottother_blue_flame_animated.png",
  13. animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=1},
  14. }},
  15. inventory_image = "lottother_blue_flame.png",
  16. light_source = 14,
  17. groups = {igniterblue=2,dig_immediate=3,hot=3},
  18. drop = '',
  19. walkable = false,
  20. buildable_to = true,
  21. damage_per_second = 4,
  22. after_place_node = function(pos, placer)
  23. fire.on_flame_add_at(pos)
  24. end,
  25. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  26. fire.on_flame_remove_at(pos)
  27. end,
  28. })
  29. lottother.D = 6
  30. lottother.sounds = {}
  31. function lottother.get_area_p0p1(pos)
  32. local p0 = {
  33. x=math.floor(pos.x/lottother.D)*lottother.D,
  34. y=math.floor(pos.y/lottother.D)*lottother.D,
  35. z=math.floor(pos.z/lottother.D)*lottother.D,
  36. }
  37. local p1 = {
  38. x=p0.x+lottother.D-1,
  39. y=p0.y+lottother.D-1,
  40. z=p0.z+lottother.D-1
  41. }
  42. return p0, p1
  43. end
  44. function lottother.update_sounds_around(pos)
  45. local p0, p1 = lottother.get_area_p0p1(pos)
  46. local cp = {x=(p0.x+p1.x)/2, y=(p0.y+p1.y)/2, z=(p0.z+p1.z)/2}
  47. local flames_p = minetest.find_nodes_in_area(p0, p1, {"lottother:blue_flame"})
  48. local should_have_sound = (#flames_p > 0)
  49. local wanted_sound = nil
  50. if #flames_p >= 9 then
  51. wanted_sound = {name="fire_large", gain=1.5}
  52. elseif #flames_p > 0 then
  53. wanted_sound = {name="fire_small", gain=1.5}
  54. end
  55. local p0_hash = minetest.hash_node_position(p0)
  56. local sound = lottother.sounds[p0_hash]
  57. if not sound then
  58. if should_have_sound then
  59. lottother.sounds[p0_hash] = {
  60. handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
  61. name = wanted_sound.name,
  62. }
  63. end
  64. else
  65. if not wanted_sound then
  66. minetest.sound_stop(sound.handle)
  67. lottother.sounds[p0_hash] = nil
  68. elseif sound.name ~= wanted_sound.name then
  69. minetest.sound_stop(sound.handle)
  70. lottother.sounds[p0_hash] = {
  71. handle = minetest.sound_play(wanted_sound, {pos=cp, loop=true}),
  72. name = wanted_sound.name,
  73. }
  74. end
  75. end
  76. end
  77. function lottother.on_flame_add_at(pos)
  78. lottother.update_sounds_around(pos)
  79. end
  80. function lottother.on_flame_remove_at(pos)
  81. lottother.update_sounds_around(pos)
  82. end
  83. function lottother.find_pos_for_flame_around(pos)
  84. return minetest.find_node_near(pos, 1, {"air"})
  85. end
  86. function lottother.flame_should_extinguish(pos)
  87. if minetest.setting_getbool("disable_fire") then return true end
  88. local p0 = {x=pos.x-2, y=pos.y, z=pos.z-2}
  89. local p1 = {x=pos.x+2, y=pos.y, z=pos.z+2}
  90. local ps = minetest.find_nodes_in_area(p0, p1, {"group:puts_out_lottother"})
  91. return (#ps ~= 0)
  92. end
  93. minetest.register_abm({
  94. nodenames = {"group:flammableblue"},
  95. neighbors = {"group:igniterblue"},
  96. interval = 1,
  97. chance = 2,
  98. action = function(p0, node, _, _)
  99. if lottother.flame_should_extinguish(p0) then
  100. return
  101. end
  102. local p = lottother.find_pos_for_flame_around(p0)
  103. if p then
  104. minetest.set_node(p, {name="lottother:blue_flame"})
  105. lottother.on_flame_add_at(p)
  106. end
  107. end,
  108. })
  109. minetest.register_abm({
  110. nodenames = {"group:igniterblue"},
  111. neighbors = {"air"},
  112. interval = 2,
  113. chance = 10,
  114. action = function(p0, node, _, _)
  115. local reg = minetest.registered_nodes[node.name]
  116. if not reg or not reg.groups.igniterblue or reg.groups.igniterblue < 2 then
  117. return
  118. end
  119. local d = reg.groups.igniterblue
  120. local p = minetest.find_node_near(p0, d, {"group:flammableblue"})
  121. if p then
  122. if lottother.flame_should_extinguish(p) then
  123. return
  124. end
  125. local p2 = lottother.find_pos_for_flame_around(p)
  126. if p2 then
  127. minetest.set_node(p2, {name="lottother:blue_flame"})
  128. lottother.on_flame_add_at(p2)
  129. end
  130. end
  131. end,
  132. })
  133. minetest.register_abm({
  134. nodenames = {"lottother:blue_flame"},
  135. interval = 1,
  136. chance = 2,
  137. action = function(p0, node, _, _)
  138. if lottother.flame_should_extinguish(p0) then
  139. minetest.remove_node(p0)
  140. lottother.on_flame_remove_at(p0)
  141. return
  142. end
  143. if math.random(1,3) == 1 then
  144. return
  145. end
  146. if not minetest.find_node_near(p0, 1, {"group:flammableblue"}) then
  147. minetest.remove_node(p0)
  148. lottother.on_flame_remove_at(p0)
  149. return
  150. end
  151. if math.random(1,4) == 1 then
  152. local p = minetest.find_node_near(p0, 1, {"group:flammableblue"})
  153. if p then
  154. if lottother.flame_should_extinguish(p0) then
  155. return
  156. end
  157. minetest.remove_node(p)
  158. minetest.check_for_falling(p)
  159. end
  160. else
  161. minetest.remove_node(p0)
  162. lottother.on_flame_remove_at(p0)
  163. end
  164. end,
  165. })
  166. minetest.register_node("lottother:dirt", {
  167. description = "Dirt Substitute",
  168. tiles = {"default_dirt.png"},
  169. is_ground_content = true,
  170. drop = 'default:dirt',
  171. groups = {crumbly=3,soil=1,not_in_creative_inventory=1},
  172. sounds = default.node_sound_dirt_defaults(),
  173. })
  174. minetest.register_node("lottother:snow", {
  175. description = "Snow Substitute",
  176. tiles = {"default_snow.png"},
  177. is_ground_content = true,
  178. drop = 'default:snowblock',
  179. freezemelt = "default:water_source",
  180. groups = {crumbly=3, melts=1, not_in_creative_inventory=1},
  181. sounds = default.node_sound_dirt_defaults({
  182. footstep = {name="default_snow_footstep", gain=0.25},
  183. dug = {name="default_snow_footstep", gain=0.75},
  184. }),
  185. })
  186. minetest.register_node("lottother:mordor_stone", {
  187. description = "Mordor Stone Substitute",
  188. tiles = {"lottmapgen_mordor_stone.png"},
  189. is_ground_content = true,
  190. drop = 'lottmapgen:mordor_stone',
  191. groups = {cracky=3, stone=1, not_in_creative_inventory=1},
  192. sounds = default.node_sound_stone_defaults(),
  193. })
  194. minetest.register_node("lottother:stone", {
  195. description = "Stone Substitute",
  196. tiles = {"default_stone.png"},
  197. is_ground_content = true,
  198. drop = 'default:cobble',
  199. groups = {cracky=3, stone=1, not_in_creative_inventory=1},
  200. sounds = default.node_sound_stone_defaults(),
  201. on_construct = function(pos)
  202. local found_air = 0
  203. local y = 0
  204. for h = 1, 50 do
  205. if minetest.get_node({x = pos.x, y = pos.y + h, z = pos.z}).name == "air" then
  206. found_air = found_air + 1
  207. elseif minetest.get_node({x = pos.x, y = pos.y + h + 4, z = pos.z}).name == "default:water_source" then
  208. return
  209. end
  210. for i = -1, 1 do
  211. for j = -3, -1 do
  212. local p = {x = pos.x + i, y = pos.y + h, z = pos.z + j}
  213. if j == -3 and i == 0 then
  214. minetest.set_node(p, {name = "default:ladder", param2 = 2})
  215. elseif h % 3 == 0 and j == -2 and i == -1 then
  216. minetest.set_node(p, {name = "default:torch", param2 = 3})
  217. elseif h % 3 == 0 and j == -2 and i == 1 then
  218. minetest.set_node(p, {name = "default:torch", param2 = 2})
  219. else
  220. minetest.remove_node(p)
  221. end
  222. end
  223. end
  224. if found_air > 3 then
  225. y = h
  226. break
  227. end
  228. if h == 50 then
  229. y = 50
  230. end
  231. end
  232. for j = -3, 0 do
  233. for k = -4, 0 do
  234. for i = -2, 2 do
  235. if k == 0 or k == -4 or i == -2 or i == 2 or j == 0 then
  236. minetest.set_node({x=pos.x+i, y = pos.y+y+j, z=pos.z+k}, {name="lottblocks:dwarfstone_black"})
  237. end
  238. if j == -3 then
  239. minetest.set_node({x = pos.x+i, y = pos.y+y+j-1, z = pos.z+k}, {name = "lottblocks:dwarfstone_black"})
  240. end
  241. if j == -3 and k == -3 and i == 0 then
  242. minetest.set_node({x = pos.x+i, y = pos.y+y+j-1, z = pos.z+k}, {name = "default:ladder", param2 = 2})
  243. end
  244. if k == 0 and i == 0 then
  245. if j == -3 then
  246. minetest.set_node({x = pos.x+i, y = pos.y+y+j, z = pos.z+k}, {name = "lottblocks:door_alder_b_1", param2 = 2})
  247. elseif j == -2 then
  248. minetest.set_node({x = pos.x+i, y = pos.y+y+j, z = pos.z+k}, {name = "lottblocks:door_alder_t_1", param2 = 2})
  249. end
  250. end
  251. end
  252. end
  253. end
  254. minetest.set_node(pos, {name = "default:stone"})
  255. end,
  256. })
  257. minetest.register_node("lottother:air", {
  258. description = "Air Substitute",
  259. drawtype = "glasslike",
  260. tiles = {"lottother_air.png"},
  261. paramtype = "light",
  262. sunlight_propagates = true,
  263. is_ground_content = false,
  264. walkable = false,
  265. buildable_to = true,
  266. pointable = false,
  267. groups = {not_in_creative_inventory=1,dig_immediate=3},
  268. sounds = default.node_sound_glass_defaults(),
  269. drop = "",
  270. })
  271. minetest.register_abm({
  272. nodenames = {"lottother:dirt"},
  273. neighbors = {"air"},
  274. interval = 5,
  275. chance = 1,
  276. action = function(pos, node, active_object_count, active_object_count_wider)
  277. local x = pos.x
  278. local y = pos.y
  279. local z = pos.z
  280. local down = {x=x,y=y-1,z=z}
  281. local down2 = {x=x,y=y-2,z=z}
  282. local down3 = {x=x,y=y-3,z=z}
  283. local down4 = {x=x,y=y-4,z=z}
  284. local down5 = {x=x,y=y-5,z=z}
  285. local down6 = {x=x,y=y-6,z=z}
  286. local down7 = {x=x,y=y-7,z=z}
  287. if minetest.get_node(down).name == "air" then
  288. minetest.set_node(down, {name="default:dirt"})
  289. minetest.set_node(down2, {name="default:dirt"})
  290. minetest.set_node(down3, {name="default:dirt"})
  291. minetest.set_node(down4, {name="default:dirt"})
  292. minetest.set_node(down5, {name="default:dirt"})
  293. minetest.set_node(down6, {name="default:dirt"})
  294. minetest.set_node(down7, {name="lottother:dirt"})
  295. end
  296. end,
  297. })
  298. minetest.register_abm({
  299. nodenames = {"lottother:snow"},
  300. neighbors = {"air"},
  301. interval = 5,
  302. chance = 1,
  303. action = function(pos, node, active_object_count, active_object_count_wider)
  304. local x = pos.x
  305. local y = pos.y
  306. local z = pos.z
  307. local down = {x=x,y=y-1,z=z}
  308. local down2 = {x=x,y=y-2,z=z}
  309. local down3 = {x=x,y=y-3,z=z}
  310. local down4 = {x=x,y=y-4,z=z}
  311. local down5 = {x=x,y=y-5,z=z}
  312. local down6 = {x=x,y=y-6,z=z}
  313. local down7 = {x=x,y=y-7,z=z}
  314. if minetest.get_node(down).name == "air" then
  315. minetest.set_node(down, {name="default:snowblock"})
  316. minetest.set_node(down2, {name="default:snowblock"})
  317. minetest.set_node(down3, {name="default:snowblock"})
  318. minetest.set_node(down4, {name="default:snowblock"})
  319. minetest.set_node(down5, {name="default:snowblock"})
  320. minetest.set_node(down6, {name="default:snowblock"})
  321. minetest.set_node(down7, {name="lottother:snow"})
  322. end
  323. end,
  324. })
  325. minetest.register_abm({
  326. nodenames = {"lottother:mordor_stone"},
  327. neighbors = {"air"},
  328. interval = 5,
  329. chance = 1,
  330. action = function(pos, node, active_object_count, active_object_count_wider)
  331. local x = pos.x
  332. local y = pos.y
  333. local z = pos.z
  334. local down = {x=x,y=y-1,z=z}
  335. local down2 = {x=x,y=y-2,z=z}
  336. local down3 = {x=x,y=y-3,z=z}
  337. local down4 = {x=x,y=y-4,z=z}
  338. local down5 = {x=x,y=y-5,z=z}
  339. local down6 = {x=x,y=y-6,z=z}
  340. local down7 = {x=x,y=y-7,z=z}
  341. if minetest.get_node(down).name == "air" then
  342. minetest.set_node(down, {name="lottmapgen:mordor_stone"})
  343. minetest.set_node(down2, {name="lottmapgen:mordor_stone"})
  344. minetest.set_node(down3, {name="lottmapgen:mordor_stone"})
  345. minetest.set_node(down4, {name="lottmapgen:mordor_stone"})
  346. minetest.set_node(down5, {name="lottmapgen:mordor_stone"})
  347. minetest.set_node(down6, {name="lottmapgen:mordor_stone"})
  348. minetest.set_node(down7, {name="lottother:mordor_stone"})
  349. end
  350. end,
  351. })
  352. minetest.register_abm({
  353. nodenames = {"lottother:dirt"},
  354. neighbors = {"default:dirt"},
  355. interval = 150,
  356. chance = 1,
  357. action = function(pos, node, active_object_count, active_object_count_wider)
  358. local x = pos.x
  359. local y = pos.y
  360. local z = pos.z
  361. local here = {x=x,y=y,z=z}
  362. minetest.set_node(here, {name="default:dirt"})
  363. end,
  364. })
  365. minetest.register_abm({
  366. nodenames = {"lottother:snow"},
  367. neighbors = {"default:snowblock"},
  368. interval = 150,
  369. chance = 1,
  370. action = function(pos, node, active_object_count, active_object_count_wider)
  371. local x = pos.x
  372. local y = pos.y
  373. local z = pos.z
  374. local here = {x=x,y=y,z=z}
  375. minetest.set_node(here, {name="default:snowblock"})
  376. end,
  377. })
  378. minetest.register_abm({
  379. nodenames = {"lottother:mordor_stone"},
  380. neighbors = {"lottmapgen:mordor_stone"},
  381. interval = 150,
  382. chance = 1,
  383. action = function(pos, node, active_object_count, active_object_count_wider)
  384. local x = pos.x
  385. local y = pos.y
  386. local z = pos.z
  387. local here = {x=x,y=y,z=z}
  388. minetest.set_node(here, {name="lottmapgen:mordor_stone"})
  389. end,
  390. })
  391. minetest.register_abm({
  392. nodenames = {"lottother:air"},
  393. interval = 7,
  394. chance = 1,
  395. action = function(pos, node, active_object_count, active_object_count_wider)
  396. minetest.remove_node(pos)
  397. end,
  398. })