cdp.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. -- Controled Demolition Pack. An explosive for getting rid of locked chests, doors, etc. on unclaimed land.
  2. cdp = cdp or {}
  3. cdp.modpath = minetest.get_modpath("tnt")
  4. function cdp.on_ignite(pos)
  5. local timer = minetest.get_node_timer(pos)
  6. if timer:is_started() then
  7. return
  8. end
  9. minetest.sound_play("tnt_ignite", {pos = pos})
  10. timer:start(5)
  11. end
  12. function cdp.on_timer(pos, elapsed)
  13. local remove = function(pos)
  14. if not minetest.test_protection(pos, "") then
  15. local node = minetest.get_node(pos)
  16. local ndef = minetest.registered_nodes[node.name]
  17. if ndef and ndef.on_blast then
  18. ndef.on_blast(pos, 1.0)
  19. end
  20. -- Might have already been removed by the `on_blast` callback,
  21. -- but just to make sure.
  22. minetest.remove_node(pos)
  23. end
  24. end
  25. -- Remove nodes adjacent to all 6 sides.
  26. local targets = {
  27. {x=pos.x+1, y=pos.y, z=pos.z},
  28. {x=pos.x-1, y=pos.y, z=pos.z},
  29. {x=pos.x, y=pos.y+1, z=pos.z},
  30. {x=pos.x, y=pos.y-1, z=pos.z},
  31. {x=pos.x, y=pos.y, z=pos.z+1},
  32. {x=pos.x, y=pos.y, z=pos.z-1},
  33. }
  34. for k, v in ipairs(targets) do
  35. remove(v)
  36. end
  37. -- Make sure to remove ourselves.
  38. minetest.remove_node(pos)
  39. -- Add an explosion effect with real damage.
  40. tnt.boom(pos, {
  41. radius = 3,
  42. ignore_protection = false,
  43. ignore_on_blast = false,
  44. damage_radius = 5,
  45. disable_drops = true,
  46. })
  47. end
  48. if not cdp.registered then
  49. minetest.register_node("tnt:controled_demolition_pack", {
  50. description = "Controled Low-Yield Demolition Pack\n\nUse to clear rubbish off land (e.g. doors, chests).\nDoes not work in protected zones.\nPlace directly next to rubbish, then ignite.",
  51. tiles = {"tnt_cdp_top.png", "tnt_cdp_bottom.png", "tnt_cdp_side.png"},
  52. is_ground_content = false,
  53. groups = utility.dig_groups("bigitem", {tnt = 1}),
  54. sounds = default.node_sound_wood_defaults(),
  55. on_ignite = function(...)
  56. return cdp.on_ignite(...)
  57. end,
  58. on_timer = function(...)
  59. return cdp.on_timer(...)
  60. end,
  61. })
  62. minetest.register_craft({
  63. output = "tnt:controled_demolition_pack",
  64. recipe = {
  65. {"", "moreores:tin_ingot", ""},
  66. {"moreores:tin_ingot", "tnt:tnt", "moreores:tin_ingot"},
  67. {"", "morechests:ironchest_public_closed", ""},
  68. },
  69. })
  70. -- Registered as reloadable in the init.lua file.
  71. cdp.registered = true
  72. end