1 local minetest,math,name = minetest,math,minetest.localplayer:get_name()
2 local nether = minetest.mod_channel_join(name..":nether_teleporters")
4 --nether teleporters are animation based
5 --the animation must finish before the teleport is initialized
6 local hud_bg_id = nil --aether portal bg
7 local nether_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 nether_cool_off_timer > 0 then
18 nether_cool_off_timer = nether_cool_off_timer - dtime
19 if nether_cool_off_timer <= 0 then
20 nether_cool_off_timer = 0
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 nether_cool_off_timer == 0 then
30 if init_sound == nil then
31 init_sound = minetest.sound_play("portal_initialize",{gain=0})
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 = "nether_portal_gui.png^[opacity:"..opacity, -- default ""
43 elseif opacity < 255 then
44 --make the hud fade in
45 opacity = opacity + (dtime*100)
47 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
50 --play heavenly sounds
52 if init_sound and node and node.name == "nether:portal" then
53 minetest.sound_fade(init_sound, -0.4, 0)
55 teleport_sound = minetest.sound_play("portal_teleported",{gain=1})
56 minetest.sound_fade(teleport_sound, -0.1, 0)
60 --player left portal before teleporting
61 if nether_cool_off_timer == 0 then
62 opacity = opacity - (dtime*100)
63 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
66 minetest.sound_fade(init_sound, -0.4, 0)
71 minetest.localplayer:hud_remove(hud_bg_id)
75 --teleport complete animation
76 elseif nether_cool_off_timer > 0 then
78 opacity = opacity - (dtime*100)
79 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
82 minetest.localplayer:hud_remove(hud_bg_id)
90 minetest.localplayer:hud_remove(hud_bg_id)
95 --initialize teleport command to server
96 if hud_bg_id and nether_cool_off_timer == 0 then
97 if opacity >= 255 then
98 nether:send_all("teleport me")
99 --can't use any portal for 7 seconds
100 nether_cool_off_timer = 6 --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;)
101 minetest.after(1,function()
102 local after_newpos = minetest.localplayer:get_pos().y
103 if after_newpos < -10000 and after_newpos > -20000 then
106 minetest.sound_fade(current_song,-0.4,0)
109 minetest.after(math.random(3,5)+math.random(),function()
110 if after_newpos < -10000 and after_newpos > -20000 then
111 --backup in case server lags out
113 minetest.sound_fade(current_song,-0.4,0)
115 local song = 90000+math.random(0,1)
117 song_playing = song_table[song].name
118 current_song = minetest.sound_play(song_table[song].name,{gain=song_volume})
123 elseif song_playing and (song_index == 90000 or song_index == 90001) then
124 minetest.sound_fade(current_song,-0.4,0)