functions.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. local function transform_visible(pos)
  2. local points
  3. local origin, northsouth = obsidian_gateway.get_origin_and_dir(pos)
  4. if origin then
  5. points = obsidian_gateway.door_positions(origin, northsouth)
  6. else
  7. -- Fallback to old behavior.
  8. local minp = vector.add(pos, {x=-2, y=-2, z=-2})
  9. local maxp = vector.add(pos, {x=2, y=2, z=2})
  10. local names = {"nether:portal_hidden"}
  11. local p2, counts = minetest.find_nodes_in_area(minp, maxp, names)
  12. if #p2 == 0 then
  13. return
  14. end
  15. points = p2
  16. end
  17. local plen = #points
  18. local ndef = minetest.registered_nodes["nether:portal_liquid"]
  19. for k = 1, plen, 1 do
  20. local tar = points[k]
  21. -- Note: must get the original param2 value from the node at this pos!
  22. local node = minetest.get_node(tar)
  23. if node.name == "nether:portal_hidden" then
  24. minetest.swap_node(tar, {
  25. name = "nether:portal_liquid",
  26. param2 = node.param2,
  27. })
  28. -- Manually run callback.
  29. ndef.on_construct(tar)
  30. end
  31. end
  32. ambiance.sound_play("nether_portal_ignite", pos, 1.0, 64)
  33. end
  34. local function transform_hidden(pos)
  35. local points
  36. local origin, northsouth = obsidian_gateway.get_origin_and_dir(pos)
  37. if origin then
  38. points = obsidian_gateway.door_positions(origin, northsouth)
  39. else
  40. -- Fallback to old behavior.
  41. local minp = vector.add(pos, {x=-2, y=-2, z=-2})
  42. local maxp = vector.add(pos, {x=2, y=2, z=2})
  43. local names = {"nether:portal_liquid"}
  44. local p2, counts = minetest.find_nodes_in_area(minp, maxp, names)
  45. if #p2 == 0 then
  46. return
  47. end
  48. points = p2
  49. end
  50. local plen = #points
  51. local ndef = minetest.registered_nodes["nether:portal_hidden"]
  52. for k = 1, plen, 1 do
  53. local tar = points[k]
  54. -- Note: must get the original param2 value from the node at this pos!
  55. local node = minetest.get_node(tar)
  56. if node.name == "nether:portal_liquid" then
  57. minetest.swap_node(tar, {
  58. name = "nether:portal_hidden",
  59. param2 = node.param2,
  60. })
  61. -- Manually run callback.
  62. ndef.on_construct(tar)
  63. end
  64. end
  65. ambiance.sound_play("nether_portal_extinguish", pos, 1.0, 64)
  66. end
  67. function nether.liquid_on_construct(pos)
  68. local meta = minetest.get_meta(pos)
  69. meta:set_int("time", os.time())
  70. local timer = minetest.get_node_timer(pos)
  71. timer:start(1)
  72. end
  73. function nether.liquid_on_destruct(pos)
  74. -- This is transient damage! The gate can be reactivated.
  75. obsidian_gateway.on_damage_gate(pos, true)
  76. end
  77. -- Timer function should execute once per second.
  78. function nether.liquid_on_timer(pos, elapsed)
  79. if math.random(1, 3) == 1 then
  80. ambiance.sound_play("nether_portal_ambient", pos, 1.0, 10)
  81. end
  82. local meta = minetest.get_meta(pos)
  83. local color = meta:get_string("color")
  84. if not color or color == "" then
  85. color = "purple"
  86. end
  87. local image = "nether_particle_anim3.png"
  88. local pref = hb4.nearest_player(pos)
  89. if pref then
  90. local dist = vector.distance(pref:get_pos(), pos)
  91. -- Player inside node? Show bubbles instead of sparks.
  92. if dist < 1 then
  93. image = "nether_particle_anim2.png"
  94. elseif dist > 10 then
  95. -- Player far from node? Swap to invisible form.
  96. transform_hidden(pos)
  97. return
  98. end
  99. end
  100. local d = 0.5
  101. minetest.add_particlespawner({
  102. amount = 5,
  103. time = 1.1,
  104. minpos = {x=pos.x-d, y=pos.y-d, z=pos.z-d},
  105. maxpos = {x=pos.x+d, y=pos.y+d, z=pos.z+d},
  106. minvel = {x=0, y=-d, z=0},
  107. maxvel = {x=0, y=d, z=0},
  108. minacc = {x=0, y=0, z=0},
  109. maxacc = {x=0, y=0, z=0},
  110. minexptime = 1.5,
  111. maxexptime = 2.5,
  112. minsize = 1,
  113. maxsize = 1.5,
  114. collisiondetection = true,
  115. collision_removal = true,
  116. texture = image .. "^[colorize:" .. color .. ":alpha",
  117. vertical = false,
  118. animation = {
  119. type = "vertical_frames",
  120. aspect_w = 7,
  121. aspect_h = 7,
  122. -- Disabled for now due to causing older clients to hang.
  123. --length = -1,
  124. length = 1.0,
  125. },
  126. glow = 14,
  127. })
  128. -- Keep running.
  129. return true
  130. end
  131. function nether.hidden_on_construct(pos)
  132. local timer = minetest.get_node_timer(pos)
  133. timer:start(0.5)
  134. end
  135. function nether.hidden_on_destruct(pos)
  136. -- This is transient damage! The gate can be reactivated.
  137. obsidian_gateway.on_damage_gate(pos, true)
  138. end
  139. -- Timer function should execute once per 1/2 second.
  140. function nether.hidden_on_timer(pos, elapsed)
  141. local pref = hb4.nearest_player(pos)
  142. if pref then
  143. -- Player near node? Swap to visible form.
  144. if vector.distance(pref:get_pos(), pos) < 8 then
  145. transform_visible(pos)
  146. return
  147. end
  148. end
  149. -- Keep running.
  150. return true
  151. end