1 --nether teleporters are animation based
2 --the animation must finish before the teleport is initialized
4 local hud_id = nil --foreground (portal)
5 local hud_bg_id = nil --black background
6 local nether_id = nil --the nether incoming
7 local cool_off_timer = 0 --use this to stop players teleporting back and forth
9 local teleport_sound = nil
12 minetest.register_globalstep(function(dtime)
13 if not minetest.localplayer or not minetest.camera then
16 --use this for player cooloff timer also to not overload server
17 if cool_off_timer > 0 then
18 cool_off_timer = cool_off_timer - dtime
19 if cool_off_timer <= 0 then
24 local pos = minetest.localplayer:get_pos()
27 local node = minetest.get_node_or_nil(pos)
29 if node and node.name == "nether:portal" and cool_off_timer == 0 then
30 if init_sound == nil then
31 init_sound = minetest.sound_play("portal_initialize",{gain=0,pitch=math.random(70,90)/100})
32 minetest.sound_fade(init_sound, 0.34, 1)
34 if hud_bg_id == nil then
35 hud_bg_id = minetest.localplayer:hud_add({
36 hud_elem_type = "image", -- see HUD element types, default "text"
37 position = {x=0.5, y=0.5},
38 name = "", -- default ""
39 scale = {x=-100, y=-100}, -- default {x=0,y=0}
40 text = "darkness.png^[opacity:"..opacity, -- default ""
42 hud_id = minetest.localplayer:hud_add({
43 hud_elem_type = "image", -- see HUD element types, default "text"
44 position = {x=0.5, y=0.5},
45 name = "", -- default ""
46 scale = {x=-1, y=-1}, -- default {x=0,y=0}
47 text = "nether_portal_gui.png^[opacity:"..opacity, -- default ""
49 nether_id = minetest.localplayer:hud_add({
50 hud_elem_type = "image", -- see HUD element types, default "text"
51 position = {x=0.5, y=0.5},
52 name = "", -- default ""
53 scale = {x=0, y=0}, -- default {x=0,y=0}
54 text = "darkness.png^[opacity:"..opacity, -- default ""
57 --make the hud zoom in
58 local scale = minetest.localplayer:hud_get(hud_id).scale.x
60 scale = scale - ((scale/-(1/dtime))*2)
61 elseif scale < -100 then
64 opacity = -scale * 2.55
65 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
66 minetest.localplayer:hud_change(hud_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
68 minetest.localplayer:hud_change(hud_bg_id, "text", "darkness.png^[opacity:"..opacity)
70 minetest.localplayer:hud_change(nether_id, "text", "darkness.png^[opacity:"..opacity)
72 elseif hud_bg_id and hud_id then
75 minetest.sound_fade(init_sound, -0.25, 0)
77 teleport_sound = minetest.sound_play("portal_teleported",{gain=1,pitch=math.random(70,90)/100})
78 minetest.sound_fade(teleport_sound, -0.1, 0)
81 --player left portal before teleporting
82 if cool_off_timer == 0 then
83 --make the hud zoom out
84 local scale = minetest.localplayer:hud_get(hud_id).scale.x
86 scale = scale + ((scale/-(1/dtime))*2)
87 elseif scale > -1 then
90 opacity = -scale * 2.55
91 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
93 minetest.localplayer:hud_change(hud_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
95 minetest.localplayer:hud_change(hud_bg_id, "text", "darkness.png^[opacity:"..opacity)
97 minetest.localplayer:hud_change(nether_id, "text", "darkness.png^[opacity:"..opacity)
100 minetest.localplayer:hud_remove(hud_bg_id)
101 minetest.localplayer:hud_remove(hud_id)
102 minetest.localplayer:hud_remove(nether_id)
108 --teleport complete animation
109 elseif cool_off_timer > 0 then
110 local scale = minetest.localplayer:hud_get(nether_id).scale.x
111 if scale == 0 then scale = -1 end
113 scale = scale - ((scale/-(1/dtime))*2)
114 elseif scale < -100 then
118 opacity = (100+scale) * 2.55
119 minetest.localplayer:hud_change(nether_id, "scale", {x=scale,y=scale})
122 minetest.localplayer:hud_change(hud_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
124 minetest.localplayer:hud_change(hud_bg_id, "text", "darkness.png^[opacity:"..opacity)
126 minetest.localplayer:hud_change(nether_id, "text", "darkness.png^[opacity:"..opacity)
129 if scale == -100 then
130 minetest.localplayer:hud_remove(hud_bg_id)
131 minetest.localplayer:hud_remove(hud_id)
132 minetest.localplayer:hud_remove(nether_id)
141 elseif hud_bg_id and hud_id then
142 minetest.localplayer:hud_remove(hud_bg_id)
143 minetest.localplayer:hud_remove(hud_id)
144 minetest.localplayer:hud_remove(nether_id)
150 --initialize teleport command to server
151 if hud_bg_id and hud_id and cool_off_timer == 0 then
152 local scale = minetest.localplayer:hud_get(hud_id).scale.x
153 if scale == -100 then
154 nether:send_all("teleport me")
155 --can't use any portal for 6 seconds