init.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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_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. if def.tiles and type(def.tiles[1]) == "string" then
  218. texture = def.tiles[1]
  219. end
  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, gain = 1.0}, 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.CONTENT_AIR
  269. local c_ignore = minetest.CONTENT_IGNORE
  270. if enable_tnt then
  271. c_tnt = minetest.get_content_id("tnt:tnt")
  272. else
  273. c_tnt = c_tnt_burning -- tnt is not registered if disabled
  274. end
  275. -- make sure we still have explosion even when centre node isnt tnt related
  276. if explode_center then
  277. count = 1
  278. end
  279. for z = pos.z - 2, pos.z + 2 do
  280. for y = pos.y - 2, pos.y + 2 do
  281. local vi = a:index(pos.x - 2, y, z)
  282. for x = pos.x - 2, pos.x + 2 do
  283. local cid = data[vi]
  284. if cid == c_tnt or cid == c_tnt_boom or cid == c_tnt_burning then
  285. count = count + 1
  286. data[vi] = c_air
  287. end
  288. vi = vi + 1
  289. end
  290. end
  291. end
  292. vm1:set_data(data)
  293. vm1:write_to_map()
  294. -- recalculate new radius
  295. radius = math.floor(radius * math.pow(count, 1/3))
  296. -- perform the explosion
  297. local vm = VoxelManip()
  298. local pr = PseudoRandom(os.time())
  299. p1 = vector.subtract(pos, radius)
  300. p2 = vector.add(pos, radius)
  301. minp, maxp = vm:read_from_map(p1, p2)
  302. a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
  303. data = vm:get_data()
  304. local drops = {}
  305. local on_blast_queue = {}
  306. local on_construct_queue = {}
  307. basic_flame_on_construct = minetest.registered_nodes["fire:basic_flame"].on_construct
  308. local c_fire = minetest.get_content_id("fire:basic_flame")
  309. for z = -radius, radius do
  310. for y = -radius, radius do
  311. local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
  312. for x = -radius, radius do
  313. local r = vector.length(vector.new(x, y, z))
  314. if (radius * radius) / (r * r) >= (pr:next(80, 125) / 100) then
  315. local cid = data[vi]
  316. local p = {x = pos.x + x, y = pos.y + y, z = pos.z + z}
  317. if cid ~= c_air and cid ~= c_ignore then
  318. data[vi] = destroy(drops, p, cid, c_air, c_fire,
  319. on_blast_queue, on_construct_queue,
  320. ignore_protection, ignore_on_blast, owner)
  321. end
  322. end
  323. vi = vi + 1
  324. end
  325. end
  326. end
  327. vm:set_data(data)
  328. vm:write_to_map()
  329. vm:update_map()
  330. vm:update_liquids()
  331. -- call check_single_for_falling for everything within 1.5x blast radius
  332. for y = -radius * 1.5, radius * 1.5 do
  333. for z = -radius * 1.5, radius * 1.5 do
  334. for x = -radius * 1.5, radius * 1.5 do
  335. local rad = {x = x, y = y, z = z}
  336. local s = vector.add(pos, rad)
  337. local r = vector.length(rad)
  338. if r / radius < 1.4 then
  339. minetest.check_single_for_falling(s)
  340. end
  341. end
  342. end
  343. end
  344. for _, queued_data in pairs(on_blast_queue) do
  345. local dist = math.max(1, vector.distance(queued_data.pos, pos))
  346. local intensity = (radius * radius) / (dist * dist)
  347. local node_drops = queued_data.on_blast(queued_data.pos, intensity)
  348. if node_drops then
  349. for _, item in pairs(node_drops) do
  350. add_drop(drops, item)
  351. end
  352. end
  353. end
  354. for _, queued_data in pairs(on_construct_queue) do
  355. queued_data.fn(queued_data.pos)
  356. end
  357. minetest.log("action", "TNT owned by " .. owner .. " detonated at " ..
  358. minetest.pos_to_string(pos) .. " with radius " .. radius)
  359. return drops, radius
  360. end
  361. function tnt.boom(pos, def)
  362. def = def or {}
  363. def.radius = def.radius or 1
  364. def.damage_radius = def.damage_radius or def.radius * 2
  365. local meta = minetest.get_meta(pos)
  366. local owner = meta:get_string("owner")
  367. if not def.explode_center and def.ignore_protection ~= true then
  368. minetest.set_node(pos, {name = "tnt:boom"})
  369. end
  370. local sound = def.sound or "tnt_explode"
  371. minetest.sound_play(sound, {pos = pos, gain = 2.5,
  372. max_hear_distance = math.min(def.radius * 20, 128)}, true)
  373. local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection,
  374. def.ignore_on_blast, owner, def.explode_center)
  375. -- append entity drops
  376. local damage_radius = (radius / math.max(1, def.radius)) * def.damage_radius
  377. entity_physics(pos, damage_radius, drops)
  378. if not def.disable_drops then
  379. eject_drops(drops, pos, radius)
  380. end
  381. add_effects(pos, radius, drops)
  382. minetest.log("action", "A TNT explosion occurred at " .. minetest.pos_to_string(pos) ..
  383. " with radius " .. radius)
  384. end
  385. minetest.register_node("tnt:boom", {
  386. drawtype = "airlike",
  387. inventory_image = "tnt_boom.png",
  388. wield_image = "tnt_boom.png",
  389. light_source = default.LIGHT_MAX,
  390. walkable = false,
  391. drop = "",
  392. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  393. -- unaffected by explosions
  394. on_blast = function() end,
  395. })
  396. minetest.register_node("tnt:gunpowder", {
  397. description = S("Gun Powder"),
  398. drawtype = "raillike",
  399. paramtype = "light",
  400. is_ground_content = false,
  401. sunlight_propagates = true,
  402. walkable = false,
  403. tiles = {
  404. "tnt_gunpowder_straight.png",
  405. "tnt_gunpowder_curved.png",
  406. "tnt_gunpowder_t_junction.png",
  407. "tnt_gunpowder_crossing.png"
  408. },
  409. inventory_image = "tnt_gunpowder_inventory.png",
  410. wield_image = "tnt_gunpowder_inventory.png",
  411. selection_box = {
  412. type = "fixed",
  413. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  414. },
  415. groups = {dig_immediate = 2, attached_node = 1, flammable = 5,
  416. connect_to_raillike = minetest.raillike_group("gunpowder")},
  417. sounds = default.node_sound_leaves_defaults(),
  418. on_punch = function(pos, node, puncher)
  419. if puncher:get_wielded_item():get_name() == "default:torch" then
  420. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  421. default.log_player_action(puncher, "ignites tnt:gunpowder at", pos)
  422. end
  423. end,
  424. on_blast = function(pos, intensity)
  425. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  426. end,
  427. on_burn = function(pos)
  428. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  429. end,
  430. on_ignite = function(pos, igniter)
  431. minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
  432. end,
  433. })
  434. minetest.register_node("tnt:gunpowder_burning", {
  435. drawtype = "raillike",
  436. paramtype = "light",
  437. sunlight_propagates = true,
  438. walkable = false,
  439. light_source = 5,
  440. tiles = {{
  441. name = "tnt_gunpowder_burning_straight_animated.png",
  442. animation = {
  443. type = "vertical_frames",
  444. aspect_w = 16,
  445. aspect_h = 16,
  446. length = 1,
  447. }
  448. },
  449. {
  450. name = "tnt_gunpowder_burning_curved_animated.png",
  451. animation = {
  452. type = "vertical_frames",
  453. aspect_w = 16,
  454. aspect_h = 16,
  455. length = 1,
  456. }
  457. },
  458. {
  459. name = "tnt_gunpowder_burning_t_junction_animated.png",
  460. animation = {
  461. type = "vertical_frames",
  462. aspect_w = 16,
  463. aspect_h = 16,
  464. length = 1,
  465. }
  466. },
  467. {
  468. name = "tnt_gunpowder_burning_crossing_animated.png",
  469. animation = {
  470. type = "vertical_frames",
  471. aspect_w = 16,
  472. aspect_h = 16,
  473. length = 1,
  474. }
  475. }},
  476. selection_box = {
  477. type = "fixed",
  478. fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
  479. },
  480. drop = "",
  481. groups = {
  482. dig_immediate = 2,
  483. attached_node = 1,
  484. connect_to_raillike = minetest.raillike_group("gunpowder"),
  485. not_in_creative_inventory = 1
  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 = 1.0}, 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 and 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. default.log_player_action(puncher, "ignites", node.name, "at", pos)
  582. end
  583. end,
  584. on_blast = function(pos, intensity)
  585. minetest.after(0.1, function()
  586. tnt.boom(pos, def)
  587. end)
  588. end,
  589. mesecons = {effector =
  590. {action_on =
  591. function(pos)
  592. tnt.boom(pos, def)
  593. end
  594. }
  595. },
  596. on_burn = function(pos)
  597. minetest.swap_node(pos, {name = name .. "_burning"})
  598. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  599. end,
  600. on_ignite = function(pos, igniter)
  601. minetest.swap_node(pos, {name = name .. "_burning"})
  602. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  603. end,
  604. })
  605. end
  606. minetest.register_node(":" .. name .. "_burning", {
  607. tiles = {
  608. {
  609. name = tnt_burning,
  610. animation = {
  611. type = "vertical_frames",
  612. aspect_w = 16,
  613. aspect_h = 16,
  614. length = 1,
  615. }
  616. },
  617. tnt_bottom, tnt_side
  618. },
  619. light_source = 5,
  620. drop = "",
  621. sounds = default.node_sound_wood_defaults(),
  622. groups = {falling_node = 1, not_in_creative_inventory = 1},
  623. on_timer = function(pos, elapsed)
  624. tnt.boom(pos, def)
  625. end,
  626. -- unaffected by explosions
  627. on_blast = function() end,
  628. on_construct = function(pos)
  629. minetest.sound_play("tnt_ignite", {pos = pos}, true)
  630. minetest.get_node_timer(pos):start(4)
  631. minetest.check_for_falling(pos)
  632. end,
  633. })
  634. end
  635. tnt.register_tnt({
  636. name = "tnt:tnt",
  637. description = S("TNT"),
  638. radius = tnt_radius,
  639. })