init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ice = ice or {}
  2. ice.modpath = minetest.get_modpath("ice")
  3. if minetest.get_modpath("reload") then
  4. local c = "ice:core"
  5. local f = ice.modpath .. "/init.lua"
  6. if not reload.file_registered(c) then
  7. reload.register_file(c, f, false)
  8. end
  9. end
  10. -- May be used as argument to math.random().
  11. function ice.minmax_time()
  12. return ice.min_time, ice.max_time
  13. end
  14. ice.min_time = 40
  15. ice.max_time = 300
  16. function ice.on_ice_notify(pos, other)
  17. --minetest.chat_send_player("MustTest", "# Server: Ice notify @ " .. minetest.pos_to_string(pos) .. "!")
  18. local timer = minetest.get_node_timer(pos)
  19. --if not timer:is_started() then
  20. timer:start(math.random(ice.minmax_time()))
  21. --end
  22. end
  23. -- Here is where we calculate the ice freeze/melt logic.
  24. function ice.on_ice_timer(pos, elapsed)
  25. --minetest.chat_send_player("MustTest", "# Server: Icemelt @ " .. minetest.pos_to_string(pos) .. "!")
  26. local nn = minetest.get_node(pos).name
  27. if nn == "default:ice" then
  28. -- Transform thick, opaque ice to thin ice.
  29. if minetest.find_node_near(pos, 1, "group:melt_around") then
  30. minetest.add_node(pos, {name="ice:thin_ice"})
  31. return
  32. end
  33. elseif nn == "ice:thin_ice" then
  34. -- Melt thin ice to liquid.
  35. local minp = {x=pos.x-1, y=pos.y-1, z=pos.z-1}
  36. local maxp = {x=pos.x+1, y=pos.y+1, z=pos.z+1}
  37. local warm = minetest.find_nodes_in_area(minp, maxp, "group:melt_around")
  38. local heat = minetest.find_nodes_in_area(minp, maxp, {"group:flame", "group:hot"})
  39. if #warm >= 3 or #heat > 0 then
  40. minetest.add_node(pos, {name="default:water_source"})
  41. minetest.check_for_falling(pos)
  42. return
  43. end
  44. -- Turn thin ice opaque again.
  45. local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
  46. if snow.is_snow(above) or above == "default:snowblock" then
  47. minetest.add_node(pos, {name="default:ice"})
  48. return
  49. end
  50. end
  51. end
  52. if not ice.registered then
  53. minetest.register_node("ice:thin_ice", {
  54. drawtype = "glasslike",
  55. description = "Clear Ice\n\nThis can be made to melt.\nApply heat for results.",
  56. tiles = {"ice_thin_ice.png"},
  57. use_texture_alpha = true,
  58. is_ground_content = true, -- Don't interfere with cavegen.
  59. paramtype = "light",
  60. groups = utility.dig_groups("ice", {
  61. ice = 1, melts = 1, cold = 1,
  62. want_notify = 1,
  63. slippery = 5,
  64. }),
  65. --_melts_to = "default:water_source",
  66. sounds = default.node_sound_glass_defaults(),
  67. -- Can be called by lavamelt ABM.
  68. on_melt = function(pos, other)
  69. minetest.remove_node(pos)
  70. end,
  71. -- Hack to notify self.
  72. on_construct = function(pos)
  73. minetest.get_node_timer(pos):start(math.random(ice.minmax_time()))
  74. end,
  75. on_notify = function(...)
  76. return ice.on_ice_notify(...)
  77. end,
  78. on_timer = function(...)
  79. return ice.on_ice_timer(...)
  80. end,
  81. })
  82. ice.registered = true
  83. end