2
0

init.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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.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, not_in_creative_inventory = 1},
  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. not_in_creative_inventory = 1
  487. },
  488. sounds = default.node_sound_leaves_defaults(),
  489. on_timer = function(pos, elapsed)
  490. for dx = -1, 1 do
  491. for dz = -1, 1 do
  492. if math.abs(dx) + math.abs(dz) == 1 then
  493. for dy = -1, 1 do
  494. tnt.burn({
  495. x = pos.x + dx,
  496. y = pos.y + dy,
  497. z = pos.z + dz,
  498. })
  499. end
  500. end
  501. end
  502. end
  503. minetest.remove_node(pos)
  504. end,
  505. -- unaffected by explosions
  506. on_blast = function() end,
  507. on_construct = function(pos)
  508. minetest.sound_play("tnt_gunpowder_burning", {pos = pos,
  509. gain = 1.0}, true)
  510. minetest.get_node_timer(pos):start(1)
  511. end,
  512. })
  513. minetest.register_craft({
  514. output = "tnt:gunpowder 5",
  515. type = "shapeless",
  516. recipe = {"default:coal_lump", "default:gravel"}
  517. })
  518. minetest.register_craftitem("tnt:tnt_stick", {
  519. description = S("TNT Stick"),
  520. inventory_image = "tnt_tnt_stick.png",
  521. groups = {flammable = 5},
  522. })
  523. if enable_tnt then
  524. minetest.register_craft({
  525. output = "tnt:tnt_stick 2",
  526. recipe = {
  527. {"tnt:gunpowder", "", "tnt:gunpowder"},
  528. {"tnt:gunpowder", "default:paper", "tnt:gunpowder"},
  529. {"tnt:gunpowder", "", "tnt:gunpowder"},
  530. }
  531. })
  532. minetest.register_craft({
  533. output = "tnt:tnt",
  534. recipe = {
  535. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"},
  536. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"},
  537. {"tnt:tnt_stick", "tnt:tnt_stick", "tnt:tnt_stick"}
  538. }
  539. })
  540. minetest.register_abm({
  541. label = "TNT ignition",
  542. nodenames = {"group:tnt", "tnt:gunpowder"},
  543. neighbors = {"fire:basic_flame", "default:lava_source", "default:lava_flowing"},
  544. interval = 4,
  545. chance = 1,
  546. action = function(pos, node)
  547. tnt.burn(pos, node.name)
  548. end,
  549. })
  550. end
  551. function tnt.register_tnt(def)
  552. local name
  553. if not def.name:find(':') then
  554. name = "tnt:" .. def.name
  555. else
  556. name = def.name
  557. def.name = def.name:match(":([%w_]+)")
  558. end
  559. if not def.tiles then def.tiles = {} end
  560. local tnt_top = def.tiles.top or def.name .. "_top.png"
  561. local tnt_bottom = def.tiles.bottom or def.name .. "_bottom.png"
  562. local tnt_side = def.tiles.side or def.name .. "_side.png"
  563. local tnt_burning = def.tiles.burning or def.name .. "_top_burning_animated.png"
  564. if not def.damage_radius then def.damage_radius = def.radius * 2 end
  565. if enable_tnt then
  566. minetest.register_node(":" .. name, {
  567. description = def.description,
  568. tiles = {tnt_top, tnt_bottom, tnt_side},
  569. is_ground_content = false,
  570. groups = {dig_immediate = 2, mesecon = 2, tnt = 1, flammable = 5},
  571. sounds = default.node_sound_wood_defaults(),
  572. after_place_node = function(pos, placer)
  573. if placer:is_player() then
  574. local meta = minetest.get_meta(pos)
  575. meta:set_string("owner", placer:get_player_name())
  576. end
  577. end,
  578. on_punch = function(pos, node, puncher)
  579. if puncher:get_wielded_item():get_name() == "default:torch" then
  580. minetest.swap_node(pos, {name = name .. "_burning"})
  581. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  582. minetest.log("action", puncher:get_player_name() ..
  583. " ignites " .. node.name .. " at " ..
  584. minetest.pos_to_string(pos))
  585. end
  586. end,
  587. on_blast = function(pos, intensity)
  588. minetest.after(0.1, function()
  589. tnt.boom(pos, def)
  590. end)
  591. end,
  592. mesecons = {effector =
  593. {action_on =
  594. function(pos)
  595. tnt.boom(pos, def)
  596. end
  597. }
  598. },
  599. on_burn = function(pos)
  600. minetest.swap_node(pos, {name = name .. "_burning"})
  601. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  602. end,
  603. on_ignite = function(pos, igniter)
  604. minetest.swap_node(pos, {name = name .. "_burning"})
  605. minetest.registered_nodes[name .. "_burning"].on_construct(pos)
  606. end,
  607. })
  608. end
  609. minetest.register_node(":" .. name .. "_burning", {
  610. tiles = {
  611. {
  612. name = tnt_burning,
  613. animation = {
  614. type = "vertical_frames",
  615. aspect_w = 16,
  616. aspect_h = 16,
  617. length = 1,
  618. }
  619. },
  620. tnt_bottom, tnt_side
  621. },
  622. light_source = 5,
  623. drop = "",
  624. sounds = default.node_sound_wood_defaults(),
  625. groups = {falling_node = 1, not_in_creative_inventory = 1},
  626. on_timer = function(pos, elapsed)
  627. tnt.boom(pos, def)
  628. end,
  629. -- unaffected by explosions
  630. on_blast = function() end,
  631. on_construct = function(pos)
  632. minetest.sound_play("tnt_ignite", {pos = pos}, true)
  633. minetest.get_node_timer(pos):start(4)
  634. minetest.check_for_falling(pos)
  635. end,
  636. })
  637. end
  638. tnt.register_tnt({
  639. name = "tnt:tnt",
  640. description = S("TNT"),
  641. radius = tnt_radius,
  642. })