]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add aether teleporting
authoroilboi <oil.boi.minetest@gmail.com>
Fri, 24 Apr 2020 13:57:17 +0000 (09:57 -0400)
committeroilboi <oil.boi.minetest@gmail.com>
Fri, 24 Apr 2020 13:57:17 +0000 (09:57 -0400)
aether.lua [new file with mode: 0644]
init.lua

diff --git a/aether.lua b/aether.lua
new file mode 100644 (file)
index 0000000..8bdd8c3
--- /dev/null
@@ -0,0 +1,95 @@
+--nether teleporters are animation based
+--the animation must finish before the teleport is initialized
+local hud_bg_id = nil --aether portal bg
+local aether_cool_off_timer = 0 --use this to stop players teleporting back and forth
+local init_sound = nil
+local teleport_sound = nil
+local opacity = 0
+
+minetest.register_globalstep(function(dtime)
+       if not minetest.localplayer or not minetest.camera then
+               return
+       end
+       --use this for player cooloff timer also to not overload server
+       if aether_cool_off_timer > 0 then
+               aether_cool_off_timer = aether_cool_off_timer - dtime
+               if aether_cool_off_timer <= 0 then
+                       aether_cool_off_timer = 0
+               end
+       end
+       
+       local pos = minetest.localplayer:get_pos()
+       pos.y = pos.y + 0.1
+       
+       local node = minetest.get_node_or_nil(pos)
+       
+       if node and node.name == "aether:portal" and aether_cool_off_timer == 0 then
+               if init_sound == nil then
+                       init_sound = minetest.sound_play("aether_teleport",{gain=0})
+                       minetest.sound_fade(init_sound, 0.34, 1)
+               end
+               if hud_bg_id == nil then
+                       hud_bg_id = minetest.localplayer:hud_add({
+                               hud_elem_type = "image", -- see HUD element types, default "text"
+                               position = {x=0.5, y=0.5},
+                               name = "",    -- default ""
+                               scale = {x=-100, y=-100}, -- default {x=0,y=0}
+                               text = "aether_portal_gui.png^[opacity:"..opacity,    -- default ""
+                       })
+                       
+               elseif opacity < 255 then
+                       --make the hud fade in
+                       opacity = opacity + 1.5
+                       
+                       minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)                  
+               end
+       elseif hud_bg_id then
+               --play heavenly sounds
+               
+               if init_sound then
+                       minetest.sound_fade(init_sound, -0.4, 0)
+                       init_sound = nil
+                       teleport_sound = minetest.sound_play("aether_teleport_complete",{gain=1})
+                       minetest.sound_fade(teleport_sound, -0.1, 0)
+                       teleport_sound = nil
+               end
+               
+               --player left portal before teleporting
+               if aether_cool_off_timer == 0 then
+                       opacity = opacity  - 1.5                        
+                       minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
+                       
+                       if opacity <= 0 then
+                               minetest.localplayer:hud_remove(hud_bg_id)
+                               hud_bg_id = nil
+                               opacity = 0
+                       end
+               --teleport complete animation
+               elseif aether_cool_off_timer > 0 then
+               
+                       opacity = opacity  - 1.5                        
+                       minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
+                       
+                       if opacity <= 0 then
+                               minetest.localplayer:hud_remove(hud_bg_id)
+                               hud_bg_id = nil
+                               opacity = 0
+                       end
+               else
+                       init_sound = nil
+               end
+       elseif hud_bg_id then
+               minetest.localplayer:hud_remove(hud_bg_id)
+               hud_bg_id = nil
+               opacity = 0
+       end
+       
+       --initialize teleport command to server
+       if hud_bg_id and aether_cool_off_timer == 0 then
+               if opacity == 255 then
+                       aether:send_all("teleport me")
+                       --can't use any portal for 7 seconds
+                       aether_cool_off_timer = 7  --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;)
+               end
+       end
+end)
index 21cc13ed592be96fb2c9c6849203cc3dbfb14fad..7bc309aef9f09d26dbab25e73a0bca9cf3540a42 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -14,6 +14,7 @@ function initialize_all()
        running_send = minetest.mod_channel_join("running_send")
        player_movement_state = minetest.mod_channel_join("player.player_movement_state")
        nether = minetest.mod_channel_join("nether_teleporters")
+       aether = minetest.mod_channel_join("aether_teleporters")
                
        --next we load everything seperately because it's easier to work on individual files than have everything jammed into one file
        --not into seperate mods because that is unnecessary and cumbersome
@@ -22,6 +23,7 @@ function initialize_all()
        dofile(path.."/weather_handling.lua")
        dofile(path.."/environment_effects.lua")
        dofile(path.."/nether.lua")
+       dofile(path.."/aether.lua")
 end
 
 --we must delay initialization until the player exists in the world