init.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. torchmelt = torchmelt or {}
  2. torchmelt.modpath = minetest.get_modpath("torchmelt")
  3. torchmelt.min_time = 15
  4. torchmelt.max_time = 80
  5. function torchmelt.start_melting(pos)
  6. local snow = minetest.find_node_near(pos, 2, snow.get_names())
  7. if snow then
  8. local air = minetest.find_node_near(pos, 1, "air")
  9. if air then
  10. minetest.set_node(air, {name="torchmelt:melter"})
  11. end
  12. end
  13. end
  14. function torchmelt.on_construct(pos)
  15. minetest.get_node_timer(pos):start(math.random(torchmelt.min_time, torchmelt.max_time))
  16. end
  17. local function torch_melt(pos)
  18. -- Perform the melting from the position of the heat source.
  19. local heat = minetest.find_node_near(pos, 1, "group:melt_around")
  20. if not heat then
  21. return false
  22. end
  23. local minp = vector.subtract(heat, 1)
  24. local maxp = vector.add(heat, 1)
  25. local snow = minetest.find_nodes_in_area(minp, maxp, snow.get_names())
  26. if #snow > 0 then
  27. -- Remove a random snow node.
  28. local p = snow[math.random(1, #snow)]
  29. minetest.remove_node(p)
  30. minetest.check_for_falling(p)
  31. return true
  32. end
  33. return false
  34. end
  35. function torchmelt.on_timer(pos, elapsed)
  36. --minetest.chat_send_player("MustTest", "# Server: Torchmelt @ " .. minetest.pos_to_string(pos) .. "!")
  37. if torch_melt(pos) then
  38. minetest.get_node_timer(pos):start(math.random(torchmelt.min_time, torchmelt.max_time))
  39. else
  40. --minetest.chat_send_player("MustTest", "# Server: Removed node @ " .. minetest.pos_to_string(pos) .. "!")
  41. minetest.get_node_timer(pos):stop()
  42. minetest.remove_node(pos) -- Remove the utility node.
  43. end
  44. end
  45. if not torchmelt.registered then
  46. minetest.register_node("torchmelt:melter", {
  47. drawtype = "airlike",
  48. description = "Torch Heat Source (Please Report to Admin)",
  49. paramtype = "light",
  50. sunlight_propagates = true,
  51. walkable = false,
  52. pointable = false,
  53. groups = {immovable = 1},
  54. climbable = false,
  55. buildable_to = true,
  56. floodable = true,
  57. drop = "",
  58. on_construct = function(...)
  59. return torchmelt.on_construct(...)
  60. end,
  61. on_timer = function(...)
  62. return torchmelt.on_timer(...)
  63. end,
  64. on_finish_collapse = function(pos, node)
  65. minetest.remove_node(pos)
  66. end,
  67. on_collapse_to_entity = function(pos, node)
  68. -- Do nothing.
  69. end,
  70. })
  71. local c = "torchmelt:core"
  72. local f = torchmelt.modpath .. "/init.lua"
  73. reload.register_file(c, f, false)
  74. torchmelt.registered = true
  75. end