init.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. -- tnt/init.lua
  2. tnt = {}
  3. -- Load support for MT game translation.
  4. local S = minetest.get_translator("tnt")
  5. -- Default to enabled when in singleplayer
  6. local enable_tnt = minetest.settings:get_bool("enable_tnt")
  7. if enable_tnt == nil then
  8. enable_tnt = minetest.is_singleplayer()
  9. end
  10. -- loss probabilities array (one in X will be lost)
  11. local loss_prob = {}
  12. loss_prob["default:cobble"] = 3
  13. loss_prob["default:dirt"] = 4
  14. local tnt_radius = tonumber(minetest.settings:get("tnt_radius") or 3)
  15. -- Fill a list with data for content IDs, after all nodes are registered
  16. local cid_data = {}
  17. minetest.register_on_mods_loaded(function()
  18. for name, def in pairs(minetest.registered_nodes) do
  19. cid_data[minetest.get_content_id(name)] = {
  20. name = name,
  21. drops = def.drops,
  22. flammable = def.groups.flammable,
  23. on_blast = def.on_blast,
  24. }
  25. end
  26. end)
  27. local function rand_pos(center, pos, radius)
  28. local def
  29. local reg_nodes = minetest.registered_nodes
  30. local i = 0
  31. repeat
  32. -- Give up and use the center if this takes too long
  33. if i > 4 then
  34. pos.x, pos.z = center.x, center.z
  35. break
  36. end
  37. pos.x = center.x + math.random(-radius, radius)
  38. pos.z = center.z + math.random(-radius, radius)
  39. def = reg_nodes[minetest.get_node(pos).name]
  40. i = i + 1
  41. until def and not def.walkable
  42. end
  43. local function eject_drops(drops, pos, radius)
  44. local drop_pos = vector.new(pos)
  45. for _, item in pairs(drops) do
  46. local count = math.min(item:get_count(), item:get_stack_max())
  47. while count > 0 do
  48. local take = math.max(1,math.min(radius * radius,
  49. count,
  50. item:get_stack_max()))
  51. rand_pos(pos, drop_pos, radius)
  52. local dropitem = ItemStack(item)
  53. dropitem:set_count(take)
  54. local obj = minetest.add_item(drop_pos, dropitem)
  55. if obj then
  56. obj:get_luaentity().collect = true
  57. obj:set_acceleration({x = 0, y = -10, z = 0})
  58. obj:set_velocity({x = math.random(-3, 3),
  59. y = math.random(0, 10),
  60. z = math.random(-3, 3)})
  61. end
  62. count = count - take
  63. end
  64. end
  65. end
  66. local function add_drop(drops, item)
  67. item = ItemStack(item)
  68. local name = item:get_name()
  69. if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
  70. return
  71. end
  72. local drop = drops[name]
  73. if drop == nil then
  74. drops[name] = item
  75. else
  76. drop:set_count(drop:get_count() + item:get_count())
  77. end
  78. end
  79. local basic_flame_on_construct -- cached value
  80. local function destroy(drops, npos, cid, c_air, c_fire,
  81. on_blast_queue, on_construct_queue,
  82. ignore_protection, ignore_on_blast, owner)
  83. if not ignore_protection and minetest.is_protected(npos, owner) then
  84. return cid
  85. end
  86. local def = cid_data[cid]
  87. if not def then
  88. return c_air
  89. elseif not ignore_on_blast and def.on_blast then
  90. on_blast_queue[#on_blast_queue + 1] = {
  91. pos = vector.new(npos),
  92. on_blast = def.on_blast
  93. }
  94. return cid
  95. elseif def.flammable then
  96. on_construct_queue[#on_construct_queue + 1] = {
  97. fn = basic_flame_on_construct,
  98. pos = vector.new(npos)
  99. }
  100. return c_fire
  101. else
  102. local node_drops = minetest.get_node_drops(def.name, "")
  103. for _, item in pairs(node_drops) do
  104. add_drop(drops, item)
  105. end
  106. return c_air
  107. end
  108. end
  109. local function calc_velocity(pos1, pos2, old_vel, power)
  110. -- Avoid errors caused by a vector of zero length
  111. if vector.equals(pos1, pos2) then
  112. return old_vel
  113. end
  114. local vel = vector.direction(pos1, pos2)
  115. vel = vector.normalize(vel)
  116. vel = vector.multiply(vel, power)
  117. -- Divide by distance
  118. local dist = vector.distance(pos1, pos2)
  119. dist = math.max(dist, 1)
  120. vel = vector.divide(vel, dist)
  121. -- Add old velocity
  122. vel = vector.add(vel, old_vel)
  123. -- randomize it a bit
  124. vel = vector.add(vel, {
  125. x = math.random() - 0.5,
  126. y = math.random() - 0.5,
  127. z = math.random() - 0.5,
  128. })
  129. -- Limit to terminal velocity
  130. dist = vector.length(vel)
  131. if dist > 250 then
  132. vel = vector.divide(vel, dist / 250)
  133. end
  134. return vel
  135. end
  136. local function entity_physics(pos, radius, drops)
  137. local objs = minetest.get_objects_inside_radius(pos, radius)
  138. for _, obj in pairs(objs) do
  139. local obj_pos = obj:get_pos()
  140. local dist = math.max(1, vector.distance(pos, obj_pos))
  141. local damage = (4 / dist) * radius
  142. if obj:is_player() then
  143. local dir = vector.normalize(vector.subtract(obj_pos, pos))
  144. local moveoff = vector.multiply(dir, 2 / dist * radius)
  145. obj:add_player_velocity(moveoff)
  146. obj:set_hp(obj:get_hp() - damage)
  147. else
  148. local luaobj = obj:get_luaentity()
  149. -- object might have disappeared somehow
  150. if luaobj then
  151. local do_damage = true
  152. local do_knockback = true
  153. local entity_drops = {}
  154. local objdef = minetest.registered_entities[luaobj.name]
  155. if objdef and objdef.on_blast then
  156. do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
  157. end
  158. if do_knockback then
  159. local obj_vel = obj:get_velocity()
  160. obj:set_velocity(calc_velocity(pos, obj_pos,
  161. obj_vel, radius * 10))
  162. end
  163. if do_damage then
  164. if not obj:get_armor_groups().immortal then
  165. obj:punch(obj, 1.0, {
  166. full_punch_interval = 1.0,
  167. damage_groups = {fleshy = damage},
  168. }, nil)
  169. end
  170. end
  171. for _, item in pairs(entity_drops) do
  172. add_drop(drops, item)
  173. end
  174. end
  175. end
  176. end
  177. end
  178. local function add_effects(pos, radius, drops)
  179. minetest.add_particle({
  180. pos = pos,
  181. velocity = vector.new(),
  182. acceleration = vector.new(),
  183. expirationtime = 0.4,
  184. size = radius * 10,
  185. collisiondetection = false,
  186. vertical = false,
  187. texture = "tnt_boom.png",
  188. glow = 15,
  189. })
  190. minetest.add_particlespawner({
  191. amount = 64,
  192. time = 0.5,
  193. minpos = vector.subtract(pos, radius / 2),
  194. maxpos = vector.add(pos, radius / 2),
  195. minvel = {x = -10, y = -10, z = -10},
  196. maxvel = {x = 10, y = 10, z = 10},
  197. minacc = vector.new(),
  198. maxacc = vector.new(),
  199. minexptime = 1,
  200. maxexptime = 2.5,
  201. minsize = radius * 3,
  202. maxsize = radius * 5,
  203. texture = "tnt_smoke.png",
  204. })
  205. -- we just dropped some items. Look at the items entities and pick
  206. -- one of them to use as texture
  207. local texture = "tnt_blast.png" --fallback texture
  208. local node
  209. local most = 0
  210. for name, stack in pairs(drops) do
  211. local count = stack:get_count()
  212. if count > most then
  213. most = count
  214. local def = minetest.registered_nodes[name]
  215. if def then
  216. node = { name = name }
  217. end
  218. if def and def.tiles and def.tiles[1] then
  219. texture = def.tiles[1]
  220. end
  221. end
  222. end
  223. minetest.add_particlespawner({
  224. amount = 64,
  225. time = 0.1,
  226. minpos = vector.subtract(pos, radius / 2),
  227. maxpos = vector.add(pos, radius / 2),
  228. minvel = {x = -3, y = 0, z = -3},
  229. maxvel = {x = 3, y = 5, z = 3},
  230. minacc = {x = 0, y = -10, z = 0},
  231. maxacc = {x = 0, y = -10, z = 0},
  232. minexptime = 0.8,
  233. maxexptime = 2.0,
  234. minsize = radius * 0.33,
  235. maxsize = radius,
  236. texture = texture,
  237. -- ^ only as fallback for clients without support for `node` parameter
  238. node = node,
  239. collisiondetection = true,
  240. })
  241. end
  242. function tnt.burn(pos, nodename)
  243. local name = nodename or minetest.get_node(pos).name
  244. local def = minetest.registered_nodes[name]
  245. if not def then
  246. return
  247. elseif def.on_ignite then
  248. def.on_ignite(pos)
  249. elseif minetest.get_item_group(name, "tnt") > 0 then
  250. minetest.swap_node(pos, {name = name .. "_burning"})
  251. minetest.sound_play("tnt_ignite", {pos = pos}, true)
  252. minetest.get_node_timer(pos):start(1)
  253. end
  254. end
  255. local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner, explode_center)
  256. pos = vector.round(pos)
  257. -- scan for adjacent TNT nodes first, and enlarge the explosion
  258. local vm1 = VoxelManip()
  259. local p1 = vector.subtract(pos, 2)
  260. local p2 = vector.add(pos, 2)
  261. local minp, maxp = vm1:read_from_map(p1, p2)
  262. local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
  263. local data = vm1:get_data()
  264. local count = 0
  265. local c_tnt
  266. local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning")
  267. local c_tnt_boom = minetest.get_content_id("tnt:boom")
  268. local c_air = minetest.get_content_id("air")
  269. if enable_tnt then
  270. c_tnt = minetest.get_content_id("tnt:tnt")
  271. else
  272. c_tnt = c_tnt_burning -- tnt is not registered if disabled
  273. end
  274. -- make sure we still have explosion even when centre node isnt tnt related
  275. if explode_center then
  276. count = 1
  277. end
  278. for z = pos.z - 2, pos.z + 2 do
  279. for y = pos.y - 2, pos.y + 2 do
  280. local vi = a:index(pos.x - 2, y, z)
  281. for x = pos.x - 2, pos.x + 2 do
  282. local cid = data[vi]
  283. if cid == c_tnt or cid == c_tnt_boom or cid == c_tnt_burning then
  284. count = count + 1
  285. data[vi] = c_air
  286. end
  287. vi = vi + 1
  288. end
  289. end
  290. end
  291. vm1:set_data(data)
  292. vm1:write_to_map()
  293. -- recalculate new radius
  294. radius = math.floor(radius * math.pow(count, 1/3))
  295. -- perform the explosion
  296. local vm = VoxelManip()
  297. local pr = PseudoRandom(os.time())
  298. p1 = vector.subtract(pos, radius)
  299. p2 = vector.add(pos, radius)
  300. minp, maxp = vm:read_from_map(p1, p2)
  301. a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
  302. data = vm:get_data()
  303. local drops = {}
  304. local on_blast_queue = {}
  305. local on_construct_queue = {}
  306. basic_flame_on_construct = minetest.registered_nodes["fire:basic_flame"].on_construct
  307. local c_fire = minetest.get_content_id("fire:basic_flame")
  308. for z = -radius, radius do
  309. for y = -radius, radius do
  310. local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
  311. for x = -radius, radius do
  312. local r = vector.length(vector.new(x, y, z))
  313. if (radius * radius) / (r * r) >= (pr:next(80, 125) / 100) then
  314. local cid = data[vi]
  315. local p = {x = pos.x + x, y = pos.y + y, z = pos.z + z}
  316. if cid ~= c_air then
  317. data[vi] = destroy(drops, p, cid, c_air, c_fire,
  318. on_blast_queue, on_construct_queue,
  319. ignore_protection, ignore_on_blast, owner)
  320. end
  321. end
  322. vi = vi + 1
  323. end
  324. end
  325. end
  326. vm:set_data(data)
  327. vm:write_to_map()
  328. vm:update_map()
  329. vm:update_liquids()
  330. -- call check_single_for_falling for everything within 1.5x blast radius
  331. for y = -radius * 1.5, radius * 1.5 do
  332. for z = -radius * 1.5, radius * 1.5 do
  333. for x = -radius * 1.5, radius * 1.5 do
  334. local rad = {x = x, y = y, z = z}
  335. local s = vector.add(pos, rad)
  336. local r = vector.length(rad)
  337. if r / radius < 1.4 then
  338. minetest.check_single_for_falling(s)
  339. end
  340. end
  341. end
  342. end
  343. for _, queued_data in pairs(on_blast_queue) do
  344. local dist = math.max(1, vector.distance(queued_data.pos, pos))
  345. local intensity = (radius * radius) / (dist * dist)
  346. local node_drops = queued_data.on_blast(queued_data.pos, intensity)
  347. if node_drops then
  348. for _, item in pairs(node_drops) do
  349. add_drop(drops, item)
  350. end
  351. end
  352. end
  353. for _, queued_data in pairs(on_construct_queue) do
  354. queued_data.fn(queued_data.pos)
  355. end
  356. minetest.log("action", "TNT owned by " .. owner .. " detonated at " ..
  357. minetest.pos_to_string(pos) .. " with radius " .. radius)
  358. return drops, radius
  359. end
  360. function tnt.boom(pos, def)
  361. def = def or {}
  362. def.radius = def.radius or 1
  363. def.damage_radius = def.damage_radius or def.radius * 2
  364. local meta = minetest.get_meta(pos)
  365. local owner = meta:get_string("owner")
  366. if not def.explode_center and def.ignore_protection ~= true then
  367. minetest.set_node(pos, {name = "tnt:boom"})
  368. end
  369. local sound = def.sound or "tnt_explode"
  370. minetest.sound_play(sound, {pos = pos, gain = 2.5,
  371. max_hear_distance = math.min(def.radius * 20, 128)}, true)
  372. local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection,
  373. def.ignore_on_blast, owner, def.explode_center)
  374. -- append entity drops
  375. local damage_radius = (radius / math.max(1, def.radius)) * def.damage_radius
  376. entity_physics(pos, damage_radius, drops)
  377. if not def.disable_drops then
  378. eject_drops(drops, pos, radius)
  379. end
  380. add_effects(pos, radius, drops)
  381. minetest.log("action", "A TNT explosion occurred at " .. minetest.pos_to_string(pos) ..
  382. " with radius " .. radius)
  383. end
  384. minetest.register_node("tnt:boom", {
  385. drawtype = "airlike",
  386. inventory_image = "tnt_boom.png",
  387. wield_image = "tnt_boom.png",
  388. light_source = default.LIGHT_MAX,
  389. walkable = false,
  390. drop = "",
  391. groups = {dig_immediate = 3},
  392. -- unaffected by explosions
  393. on_blast = function() end,
  394. })
  395. minetest.register_node("tnt:gunpowder", {
  396. description = S("Gun Powder"),
  397. drawtype = "raillike",
  398. paramtype = "light",
  399. is_ground_content = false,
  400. sunlight_propagates = true,
  401. walkable = false,
  402. tiles = {
  403. "tnt_gunpowder_straight.png",
  404. "tnt_gunpowder_curved.png",
  405. "tnt_gunpowder_t_junction.png",
  406. "tnt_gunpowder_crossing.png"
  407. },
  408. inventory_image = "tnt_gunpowder_inventory.png",
  409. wield_image = "tnt_gunpowder_inventory.png",
  410. selection_box = {
  411. type = "fixed",
  412. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  413. },
  414. groups = {dig_immediate = 2, attached_node = 1, flammable = 5,
  415. connect_to_raillike = minetest.raillike_group("gunpowder")},
  416. sounds = default.node_sound_leaves_defaults(),
  417. on_punch = function(pos, node, puncher)
  418. if puncher:get_wielded_item():get_name() == "default:torch" then
  419. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  420. minetest.log("action", puncher:get_player_name() ..
  421. " ignites tnt:gunpowder at " ..
  422. minetest.pos_to_string(pos))
  423. end
  424. end,
  425. on_blast = function(pos, intensity)
  426. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  427. end,
  428. on_burn = function(pos)
  429. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  430. end,
  431. on_ignite = function(pos, igniter)
  432. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  433. end,
  434. })
  435. minetest.register_node("tnt:gunpowder_burning", {
  436. drawtype = "raillike",
  437. paramtype = "light",
  438. sunlight_propagates = true,
  439. walkable = false,
  440. light_source = 5,
  441. tiles = {{
  442. name = "tnt_gunpowder_burning_straight_animated.png",
  443. animation = {
  444. type = "vertical_frames",
  445. aspect_w = 16,
  446. aspect_h = 16,
  447. length = 1,
  448. }
  449. },
  450. {
  451. name = "tnt_gunpowder_burning_curved_animated.png",
  452. animation = {
  453. type = "vertical_frames",
  454. aspect_w = 16,
  455. aspect_h = 16,
  456. length = 1,
  457. }
  458. },
  459. {
  460. name = "tnt_gunpowder_burning_t_junction_animated.png",
  461. animation = {
  462. type = "vertical_frames",
  463. aspect_w = 16,
  464. aspect_h = 16,
  465. length = 1,
  466. }
  467. },
  468. {
  469. name = "tnt_gunpowder_burning_crossing_animated.png",
  470. animation = {
  471. type = "vertical_frames",
  472. aspect_w = 16,
  473. aspect_h = 16,
  474. length = 1,
  475. }
  476. }},
  477. selection_box = {
  478. type = "fixed",
  479. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  480. },
  481. drop = "",
  482. groups = {
  483. dig_immediate = 2,
  484. attached_node = 1,
  485. connect_to_raillike = minetest.raillike_group("gunpowder")
  486. },
  487. sounds = default.node_sound_leaves_defaults(),
  488. on_timer = function(pos, elapsed)
  489. for dx = -1, 1 do
  490. for dz = -1, 1 do
  491. if math.abs(dx) + math.abs(dz) == 1 then
  492. for dy = -1, 1 do
  493. tnt.burn({
  494. x = pos.x + dx,
  495. y = pos.y + dy,
  496. z = pos.z + dz,
  497. })
  498. end
  499. end
  500. end
  501. end
  502. minetest.remove_node(pos)
  503. end,
  504. -- unaffected by explosions
  505. on_blast = function() end,
  506. on_construct = function(pos)
  507. minetest.sound_play("tnt_gunpowder_burning", {pos = pos,
  508. gain = 2}, true)
  509. minetest.get_node_timer(pos):start(1)
  510. end,
  511. })
  512. minetest.register_craft({
  513. output = "tnt:gunpowder 5",
  514. type = "shapeless",
  515. recipe = {"default:coal_lump", "default:gravel"}
  516. })
  517. minetest.register_craftitem("tnt:tnt_stick", {
  518. description = S("TNT Stick"),
  519. inventory_image = "tnt_tnt_stick.png",
  520. groups = {flammable = 5},
  521. })
  522. if enable_tnt then
  523. minetest.register_craft({
  524. output = "tnt:tnt_stick 2",
  525. recipe = {
  526. {"tnt:gunpowder", "", "tnt:gunpowder"},
  527. {"tnt:gunpowder", "default:paper", "tnt:gunpowder"},
  528. {"tnt:gunpowder", "", "tnt:gunpowder"},
  529. }
  530. })
  531. minetest.register_craft({
  532. output = "tnt:tnt",
  533. recipe = {
  534. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"},
  535. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"},
  536. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"}
  537. }
  538. })
  539. minetest.register_abm({
  540. label = "TNT ignition",
  541. nodenames = {"group:tnt", "tnt:gunpowder"},
  542. neighbors = {"fire:basic_flame", "default:lava_source", "default:lava_flowing"},
  543. interval = 4,
  544. chance = 1,
  545. action = function(pos, node)
  546. tnt.burn(pos, node.name)
  547. end,
  548. })
  549. end
  550. function tnt.register_tnt(def)
  551. local name
  552. if not def.name:find(':') then
  553. name = "tnt:" .. def.name
  554. else
  555. name = def.name
  556. def.name = def.name:match(":([%w_]+)")
  557. end
  558. if not def.tiles then def.tiles = {} end
  559. local tnt_top = def.tiles.top or def.name .. "_top.png"
  560. local tnt_bottom = def.tiles.bottom or def.name .. "_bottom.png"
  561. local tnt_side = def.tiles.side or def.name .. "_side.png"
  562. local tnt_burning = def.tiles.burning or def.name .. "_top_burning_animated.png"
  563. if not def.damage_radius then def.damage_radius = def.radius * 2 end
  564. if enable_tnt then
  565. minetest.register_node(":" .. name, {
  566. description = def.description,
  567. tiles = {tnt_top, tnt_bottom, tnt_side},
  568. is_ground_content = false,
  569. groups = {dig_immediate = 2, mesecon = 2, tnt = 1, flammable = 5},
  570. sounds = default.node_sound_wood_defaults(),
  571. after_place_node = function(pos, placer)
  572. if placer:is_player() then
  573. local meta = minetest.get_meta(pos)
  574. meta:set_string("owner", placer:get_player_name())
  575. end
  576. end,
  577. on_punch = function(pos, node, puncher)
  578. if puncher:get_wielded_item():get_name() == "default:torch" then
  579. minetest.swap_node(pos, {name = name .. "_burning"})
  580. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  581. minetest.log("action", puncher:get_player_name() ..
  582. " ignites " .. node.name .. " at " ..
  583. minetest.pos_to_string(pos))
  584. end
  585. end,
  586. on_blast = function(pos, intensity)
  587. minetest.after(0.1, function()
  588. tnt.boom(pos, def)
  589. end)
  590. end,
  591. mesecons = {effector =
  592. {action_on =
  593. function(pos)
  594. tnt.boom(pos, def)
  595. end
  596. }
  597. },
  598. on_burn = function(pos)
  599. minetest.swap_node(pos, {name = name .. "_burning"})
  600. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  601. end,
  602. on_ignite = function(pos, igniter)
  603. minetest.swap_node(pos, {name = name .. "_burning"})
  604. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  605. end,
  606. })
  607. end
  608. minetest.register_node(":" .. name .. "_burning", {
  609. tiles = {
  610. {
  611. name = tnt_burning,
  612. animation = {
  613. type = "vertical_frames",
  614. aspect_w = 16,
  615. aspect_h = 16,
  616. length = 1,
  617. }
  618. },
  619. tnt_bottom, tnt_side
  620. },
  621. light_source = 5,
  622. drop = "",
  623. sounds = default.node_sound_wood_defaults(),
  624. groups = {falling_node = 1},
  625. on_timer = function(pos, elapsed)
  626. tnt.boom(pos, def)
  627. end,
  628. -- unaffected by explosions
  629. on_blast = function() end,
  630. on_construct = function(pos)
  631. minetest.sound_play("tnt_ignite", {pos = pos}, true)
  632. minetest.get_node_timer(pos):start(4)
  633. minetest.check_for_falling(pos)
  634. end,
  635. })
  636. end
  637. tnt.register_tnt({
  638. name = "tnt:tnt",
  639. description = S("TNT"),
  640. radius = tnt_radius,
  641. })