nodes.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. --[[
  2. Nether mod for minetest
  3. Copyright (C) 2013 PilzAdam
  4. Permission to use, copy, modify, and/or distribute this software for
  5. any purpose with or without fee is hereby granted, provided that the
  6. above copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  8. WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  9. WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
  10. BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
  11. OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  12. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  13. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  14. SOFTWARE.
  15. ]]--
  16. local S = nether.get_translator
  17. -- Portal/wormhole nodes
  18. nether.register_wormhole_node("nether:portal", {
  19. description = S("Nether Portal"),
  20. post_effect_color = {
  21. -- post_effect_color can't be changed dynamically in Minetest like the portal colour is.
  22. -- If you need a different post_effect_color then use register_wormhole_node to create
  23. -- another wormhole node and set it as the wormhole_node_name in your portaldef.
  24. -- Hopefully this colour is close enough to magenta to work with the traditional magenta
  25. -- portals, close enough to red to work for a red portal, and also close enough to red to
  26. -- work with blue & cyan portals - since blue portals are sometimes portrayed as being red
  27. -- from the opposite side / from the inside.
  28. a = 160, r = 128, g = 0, b = 80
  29. }
  30. })
  31. local portal_animation2 = {
  32. name = "nether_portal_alt.png",
  33. animation = {
  34. type = "vertical_frames",
  35. aspect_w = 16,
  36. aspect_h = 16,
  37. length = 0.5,
  38. },
  39. }
  40. nether.register_wormhole_node("nether:portal_alt", {
  41. description = S("Portal"),
  42. tiles = {
  43. "nether_transparent.png",
  44. "nether_transparent.png",
  45. "nether_transparent.png",
  46. "nether_transparent.png",
  47. portal_animation2,
  48. portal_animation2
  49. },
  50. post_effect_color = {
  51. -- hopefully blue enough to work with blue portals, and green enough to
  52. -- work with cyan portals.
  53. a = 120, r = 0, g = 128, b = 188
  54. }
  55. })
  56. -- Nether nodes
  57. minetest.register_node("nether:rack", {
  58. description = S("Netherrack"),
  59. tiles = {"nether_rack.png"},
  60. is_ground_content = true,
  61. groups = {cracky = 3, level = 2},
  62. sounds = default.node_sound_stone_defaults(),
  63. })
  64. minetest.register_node("nether:sand", {
  65. description = S("Nethersand"),
  66. tiles = {"nether_sand.png"},
  67. is_ground_content = true,
  68. groups = {crumbly = 3, level = 2, falling_node = 1},
  69. sounds = default.node_sound_gravel_defaults({
  70. footstep = {name = "default_gravel_footstep", gain = 0.45},
  71. }),
  72. })
  73. minetest.register_node("nether:glowstone", {
  74. description = S("Glowstone"),
  75. tiles = {"nether_glowstone.png"},
  76. is_ground_content = true,
  77. light_source = 14,
  78. paramtype = "light",
  79. groups = {cracky = 3, oddly_breakable_by_hand = 3},
  80. sounds = default.node_sound_glass_defaults(),
  81. })
  82. minetest.register_node("nether:brick", {
  83. description = S("Nether Brick"),
  84. tiles = {"nether_brick.png"},
  85. is_ground_content = false,
  86. groups = {cracky = 2, level = 2},
  87. sounds = default.node_sound_stone_defaults(),
  88. })
  89. -- A decorative node which can only be obtained from dungeons or structures
  90. minetest.register_node("nether:brick_cracked", {
  91. description = S("Cracked Nether Brick"),
  92. tiles = {"nether_brick_cracked.png"},
  93. is_ground_content = false,
  94. groups = {cracky = 2, level = 2},
  95. sounds = default.node_sound_stone_defaults(),
  96. })
  97. -- Basalt is intended as another portalstone - an alternative to obsidian that's available
  98. -- for other mods to use. It cannot be found in the regions of the nether where portals
  99. -- link to, so requires a journey to obtain.
  100. minetest.register_node("nether:basalt", {
  101. description = S("Basalt"),
  102. tiles = {
  103. "nether_basalt.png",
  104. "nether_basalt.png",
  105. "nether_basalt_side.png",
  106. "nether_basalt_side.png",
  107. "nether_basalt_side.png",
  108. "nether_basalt_side.png"
  109. },
  110. is_ground_content = true,
  111. groups = {cracky = 2, level = 3, stone = 1},
  112. sounds = default.node_sound_stone_defaults(),
  113. })
  114. -- creates a splash and leaves lava in place of the "nether:lava_crust"
  115. local function smash_lava_crust(pos)
  116. local lava_particlespawn_def = {
  117. amount = 6,
  118. time = 0.1,
  119. minpos = {x=pos.x - 0.5, y=pos.y + 0.3, z=pos.z - 0.5},
  120. maxpos = {x=pos.x + 0.5, y=pos.y + 0.5, z=pos.z + 0.5},
  121. minvel = {x = -1.5, y = 1.5, z = -1.5},
  122. maxvel = {x = 1.5, y = 5, z = 1.5},
  123. minacc = {x = 0, y = -10, z = 0},
  124. maxacc = {x = 0, y = -10, z = 0},
  125. minexptime = 1,
  126. maxexptime = 1,
  127. minsize = .2,
  128. maxsize = .8,
  129. texture = "^[colorize:#A00:255",
  130. glow = 8
  131. }
  132. minetest.add_particlespawner(lava_particlespawn_def)
  133. lava_particlespawn_def.texture = "^[colorize:#FB0:255"
  134. lava_particlespawn_def.maxvel.y = 3
  135. lava_particlespawn_def.glow = 12
  136. minetest.add_particlespawner(lava_particlespawn_def)
  137. minetest.set_node(pos, {name = "default:lava_source"})
  138. end
  139. minetest.register_node("nether:lava_crust", {
  140. description = "Lava crust",
  141. tiles = {
  142. {
  143. name="nether_lava_crust_animated.png",
  144. backface_culling=true,
  145. tileable_vertical=true,
  146. tileable_horizontal=true,
  147. align_style="world",
  148. scale=2,
  149. animation = {
  150. type = "vertical_frames",
  151. aspect_w = 32,
  152. aspect_h = 32,
  153. length = 2,
  154. },
  155. }
  156. },
  157. after_destruct = smash_lava_crust,
  158. on_blast = function(pos, intensity)
  159. smash_lava_crust(pos)
  160. end,
  161. paramtype = "light",
  162. light_source = default.LIGHT_MAX - 3,
  163. buildable_to = false,
  164. walkable_to = true,
  165. is_ground_content = true,
  166. drop = "",
  167. liquid_viscosity = 7,
  168. damage_per_second = 4 * 2,
  169. groups = {oddly_breakable_by_hand = 3, igniter = 1, stone = 1},
  170. })
  171. local fence_texture =
  172. "default_fence_overlay.png^nether_brick.png^default_fence_overlay.png^[makealpha:255,126,126"
  173. minetest.register_node("nether:fence_nether_brick", {
  174. description = S("Nether Brick Fence"),
  175. drawtype = "fencelike",
  176. tiles = {"nether_brick.png"},
  177. inventory_image = fence_texture,
  178. wield_image = fence_texture,
  179. paramtype = "light",
  180. sunlight_propagates = true,
  181. is_ground_content = false,
  182. selection_box = {
  183. type = "fixed",
  184. fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
  185. },
  186. groups = {cracky = 2, level = 2},
  187. sounds = default.node_sound_stone_defaults(),
  188. })
  189. -- Register stair and slab
  190. stairs.register_stair_and_slab(
  191. "nether_brick",
  192. "nether:brick",
  193. {cracky = 2, level = 2},
  194. {"nether_brick.png"},
  195. S("Nether Stair"),
  196. S("Nether Slab"),
  197. default.node_sound_stone_defaults()
  198. )
  199. stairs.register_stair(
  200. "netherrack",
  201. "nether:rack",
  202. {cracky = 2, level = 2},
  203. {"nether_rack.png"},
  204. S("Netherrack stair"),
  205. default.node_sound_stone_defaults()
  206. )
  207. -- StairsPlus
  208. if minetest.get_modpath("moreblocks") then
  209. stairsplus:register_all(
  210. "nether", "brick", "nether:brick", {
  211. description = S("Nether Brick"),
  212. groups = {cracky = 2, level = 2},
  213. tiles = {"nether_brick.png"},
  214. sounds = default.node_sound_stone_defaults(),
  215. })
  216. end
  217. -- Lava-sea source
  218. -- This is a lava source using a different animated texture so that each node
  219. -- is out of phase in its animation from its neighbour. This prevents the lava
  220. -- sea from visually clumping together into a patchwork of 16x16 squares.
  221. local lavasea_source = {}
  222. local lava_source = minetest.registered_nodes["default:lava_source"]
  223. for key, value in pairs(lava_source) do lavasea_source[key] = value end
  224. lavasea_source.name = nil
  225. lavasea_source.tiles = {
  226. {
  227. name = "nether_lava_source_animated.png",
  228. backface_culling = false,
  229. align_style = "world",
  230. scale = 2,
  231. animation = {
  232. type = "vertical_frames",
  233. aspect_w = 32,
  234. aspect_h = 32,
  235. length = 3.0,
  236. },
  237. },
  238. {
  239. name = "nether_lava_source_animated.png",
  240. backface_culling = true,
  241. align_style = "world",
  242. scale = 2,
  243. animation = {
  244. type = "vertical_frames",
  245. aspect_w = 32,
  246. aspect_h = 32,
  247. length = 3.0,
  248. },
  249. },
  250. }
  251. minetest.register_node("nether:lava_source", lavasea_source)
  252. minetest.register_on_mods_loaded(function()
  253. -- register a bucket of Lava-sea source - but make it just the same bucket as default lava.
  254. -- (by doing this in register_on_mods_loaded we don't need to declare a soft dependency)
  255. if minetest.get_modpath("bucket") and minetest.global_exists("bucket") then
  256. local lava_bucket = bucket.liquids["default:lava_source"]
  257. if lava_bucket ~= nil then
  258. local lavasea_bucket = {}
  259. for key, value in pairs(lava_bucket) do lavasea_bucket[key] = value end
  260. lavasea_bucket.source = "nether:lava_source"
  261. bucket.liquids[lavasea_bucket.source] = lavasea_bucket
  262. end
  263. end
  264. -- include "nether:lava_source" in any "default:lava_source" ABMs
  265. local function include_nether_lava(set_of_nodes)
  266. if (type(set_of_nodes) == "table") then
  267. for _, nodename in pairs(set_of_nodes) do
  268. if nodename == "default:lava_source" then
  269. -- I'm amazed this works, but it does
  270. table.insert(set_of_nodes, "nether:lava_source")
  271. break;
  272. end
  273. end
  274. end
  275. end
  276. for _, abm in pairs(minetest.registered_abms) do
  277. include_nether_lava(abm.nodenames)
  278. include_nether_lava(abm.neighbors)
  279. end
  280. for _, lbm in pairs(minetest.registered_lbms) do
  281. include_nether_lava(lbm.nodenames)
  282. end
  283. --minetest.log("minetest.registered_abms" .. dump(minetest.registered_abms))
  284. --minetest.log("minetest.registered_lbms" .. dump(minetest.registered_lbms))
  285. end)
  286. -- Fumaroles (Chimney's)
  287. local function fumarole_startTimer(pos, timeout_factor)
  288. if timeout_factor == nil then timeout_factor = 1 end
  289. local next_timeout = (math.random(50, 900) / 10) * timeout_factor
  290. minetest.get_meta(pos):set_float("expected_timeout", next_timeout)
  291. minetest.get_node_timer(pos):start(next_timeout)
  292. end
  293. -- Create an LBM to start fumarole node timers
  294. minetest.register_lbm({
  295. label = "Start fumarole smoke",
  296. name = "nether:start_fumarole",
  297. nodenames = {"nether:fumarole"},
  298. run_at_every_load = true,
  299. action = function(pos, node)
  300. local node_above = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z})
  301. if node_above.name == "air" then --and node.param2 % 4 == 0 then
  302. fumarole_startTimer(pos)
  303. end
  304. end
  305. })
  306. local function set_fire(pos, extinguish)
  307. local posBelow = {x = pos.x, y = pos.y - 1, z = pos.z}
  308. if extinguish then
  309. if minetest.get_node(pos).name == "fire:permanent_flame" then minetest.set_node(pos, {name="air"}) end
  310. if minetest.get_node(posBelow).name == "fire:permanent_flame" then minetest.set_node(posBelow, {name="air"}) end
  311. elseif minetest.get_node(posBelow).name == "air" then
  312. minetest.set_node(posBelow, {name="fire:permanent_flame"})
  313. elseif minetest.get_node(pos).name == "air" then
  314. minetest.set_node(pos, {name="fire:permanent_flame"})
  315. end
  316. end
  317. local function fumarole_onTimer(pos, elapsed)
  318. local expected_timeout = minetest.get_meta(pos):get_float("expected_timeout")
  319. if elapsed > expected_timeout + 10 then
  320. -- The timer didn't fire when it was supposed to, so the chunk was probably inactive and has
  321. -- just been approached again, meaning *every* fumarole's on_timer is about to go off.
  322. -- Skip this event and restart the clock for a future random interval.
  323. fumarole_startTimer(pos, 1)
  324. return false
  325. end
  326. -- Fumaroles in the Nether can catch fire.
  327. -- (if taken to the surface and used as cottage chimneys, they don't catch fire)
  328. local inNether = pos.y <= nether.DEPTH and pos.y >= nether.DEPTH_FLOOR
  329. local canCatchFire = inNether and minetest.registered_nodes["fire:permanent_flame"] ~= nil
  330. local smoke_offset = 0
  331. local timeout_factor = 1
  332. local smoke_time_adj = 1
  333. local posAbove = {x = pos.x, y = pos.y + 1, z = pos.z}
  334. local extinguish = minetest.get_node(posAbove).name ~= "air"
  335. if extinguish or (canCatchFire and math.floor(elapsed) % 7 == 0) then
  336. if not extinguish then
  337. -- fumarole gasses are igniting
  338. smoke_offset = 1
  339. timeout_factor = 0.22 -- reduce burning time
  340. end
  341. set_fire(posAbove, extinguish)
  342. set_fire({x = pos.x + 1, y = pos.y + 1, z = pos.z}, extinguish)
  343. set_fire({x = pos.x - 1, y = pos.y + 1, z = pos.z}, extinguish)
  344. set_fire({x = pos.x, y = pos.y + 1, z = pos.z + 1}, extinguish)
  345. set_fire({x = pos.x, y = pos.y + 1, z = pos.z - 1}, extinguish)
  346. elseif inNether then
  347. if math.floor(elapsed) % 3 == 1 then
  348. -- throw up some embers / lava splash
  349. local embers_particlespawn_def = {
  350. amount = 6,
  351. time = 0.1,
  352. minpos = {x=pos.x - 0.1, y=pos.y + 0.0, z=pos.z - 0.1},
  353. maxpos = {x=pos.x + 0.1, y=pos.y + 0.2, z=pos.z + 0.1},
  354. minvel = {x = -.5, y = 4.5, z = -.5},
  355. maxvel = {x = .5, y = 7, z = .5},
  356. minacc = {x = 0, y = -10, z = 0},
  357. maxacc = {x = 0, y = -10, z = 0},
  358. minexptime = 1.4,
  359. maxexptime = 1.4,
  360. minsize = .2,
  361. maxsize = .8,
  362. texture = "^[colorize:#A00:255",
  363. glow = 8
  364. }
  365. minetest.add_particlespawner(embers_particlespawn_def)
  366. embers_particlespawn_def.texture = "^[colorize:#A50:255"
  367. embers_particlespawn_def.maxvel.y = 3
  368. embers_particlespawn_def.glow = 12
  369. minetest.add_particlespawner(embers_particlespawn_def)
  370. else
  371. -- gas noises
  372. minetest.sound_play("nether_fumarole", {
  373. pos = pos,
  374. max_hear_distance = 60,
  375. gain = 0.24,
  376. pitch = math.random(35, 95) / 100
  377. })
  378. end
  379. else
  380. -- we're not in the Nether, so can afford to be a bit more smokey
  381. timeout_factor = 0.4
  382. smoke_time_adj = 1.3
  383. end
  384. -- let out some smoke
  385. minetest.add_particlespawner({
  386. amount = 12 * smoke_time_adj,
  387. time = math.random(40, 60) / 10 * smoke_time_adj,
  388. minpos = {x=pos.x - 0.2, y=pos.y + smoke_offset, z=pos.z - 0.2},
  389. maxpos = {x=pos.x + 0.2, y=pos.y + smoke_offset, z=pos.z + 0.2},
  390. minvel = {x=0, y=0.7, z=-0},
  391. maxvel = {x=0, y=0.8, z=-0},
  392. minacc = {x=0.0,y=0.0,z=-0},
  393. maxacc = {x=0.0,y=0.1,z=-0},
  394. minexptime = 5,
  395. maxexptime = 5.5,
  396. minsize = 1.5,
  397. maxsize = 7,
  398. texture = "nether_smoke_puff.png",
  399. })
  400. fumarole_startTimer(pos, timeout_factor)
  401. return false
  402. end
  403. minetest.register_node("nether:fumarole", {
  404. description="Fumarolic Chimney",
  405. tiles = {"nether_rack.png"},
  406. on_timer = fumarole_onTimer,
  407. after_place_node = function(pos, placer, itemstack, pointed_thing)
  408. fumarole_onTimer(pos, 1)
  409. return false
  410. end,
  411. is_ground_content = true,
  412. groups = {cracky = 3, level = 2, fumarole=1},
  413. paramtype = "light",
  414. drawtype = "nodebox",
  415. node_box = {
  416. type = "fixed",
  417. fixed = {
  418. {-0.5000, -0.5000, -0.5000, -0.2500, 0.5000, 0.5000},
  419. {-0.5000, -0.5000, -0.5000, 0.5000, 0.5000, -0.2500},
  420. {-0.5000, -0.5000, 0.2500, 0.5000, 0.5000, 0.5000},
  421. {0.2500, -0.5000, -0.5000, 0.5000, 0.5000, 0.5000}
  422. }
  423. },
  424. selection_box = {type = 'fixed', fixed = {-.5, -.5, -.5, .5, .5, .5}}
  425. })
  426. minetest.register_node("nether:fumarole_slab", {
  427. description="Fumarolic Chimney Slab",
  428. tiles = {"nether_rack.png"},
  429. is_ground_content = true,
  430. on_timer = fumarole_onTimer,
  431. after_place_node = function(pos, placer, itemstack, pointed_thing)
  432. fumarole_onTimer(pos, 1)
  433. return false
  434. end,
  435. groups = {cracky = 3, level = 2, fumarole=1},
  436. paramtype = "light",
  437. drawtype = "nodebox",
  438. node_box = {
  439. type = "fixed",
  440. fixed = {
  441. {-0.5000, -0.5000, -0.5000, -0.2500, 0.000, 0.5000},
  442. {-0.5000, -0.5000, -0.5000, 0.5000, 0.000, -0.2500},
  443. {-0.5000, -0.5000, 0.2500, 0.5000, 0.000, 0.5000},
  444. {0.2500, -0.5000, -0.5000, 0.5000, 0.000, 0.5000}
  445. }
  446. },
  447. selection_box = {type = 'fixed', fixed = {-.5, -.5, -.5, .5, 0, .5}},
  448. collision_box = {type = 'fixed', fixed = {-.5, -.5, -.5, .5, 0, .5}}
  449. })
  450. minetest.register_node("nether:fumarole_corner", {
  451. description="Fumarolic Chimney Corner",
  452. tiles = {"nether_rack.png"},
  453. is_ground_content = true,
  454. groups = {cracky = 3, level = 2, fumarole=1},
  455. paramtype = "light",
  456. paramtype2 = "facedir",
  457. drawtype = "nodebox",
  458. node_box = {
  459. type = "fixed",
  460. fixed = {
  461. {-0.2500, -0.5000, 0.5000, 0.000, 0.5000, 0.000},
  462. {-0.5000, -0.5000, 0.2500, 0.000, 0.5000, 0.000},
  463. {-0.5000, -0.5000, 0.2500, 0.000, 0.000, -0.5000},
  464. {0.000, -0.5000, -0.5000, 0.5000, 0.000, 0.5000}
  465. }
  466. },
  467. selection_box = {
  468. type = 'fixed',
  469. fixed = {
  470. {-.5, -.5, -.5, .5, 0, .5},
  471. {0, 0, .5, -.5, .5, 0},
  472. }
  473. }
  474. })
  475. -- nether:airlike_darkness is an air node through which light does not propagate.
  476. -- Use of it should be avoided when possible as it has the appearance of a lighting bug.
  477. -- Fumarole decorations use it to stop the propagation of light from the lava below,
  478. -- since engine limitations mean any mesh or nodebox node will light up if it has lava
  479. -- below it.
  480. local airlike_darkness = {}
  481. for k,v in pairs(minetest.registered_nodes["air"]) do airlike_darkness[k] = v end
  482. airlike_darkness.paramtype = "none"
  483. minetest.register_node("nether:airlike_darkness", airlike_darkness)
  484. -- Crafting
  485. minetest.register_craft({
  486. output = "nether:brick 4",
  487. recipe = {
  488. {"nether:rack", "nether:rack"},
  489. {"nether:rack", "nether:rack"},
  490. }
  491. })
  492. minetest.register_craft({
  493. output = "nether:fence_nether_brick 6",
  494. recipe = {
  495. {"nether:brick", "nether:brick", "nether:brick"},
  496. {"nether:brick", "nether:brick", "nether:brick"},
  497. },
  498. })