]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add nether teleportation
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 19 Apr 2020 10:05:53 +0000 (06:05 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 19 Apr 2020 10:05:53 +0000 (06:05 -0400)
init.lua
nether [new file with mode: 0644]
nether.lua [new file with mode: 0644]

index ef4653dfaf9b1e683e52ecb3b874a1576c4d62d5..5fc6c1d5ab42cd17e4333f4b07b0d765a4831ab2 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -5,6 +5,8 @@ weather_type = minetest.mod_channel_join("weather_type")
 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")
+
 
 function initialize_all()
        --first we tell the server we're ready
@@ -18,6 +20,7 @@ function initialize_all()
        dofile(path.."/player_input.lua")
        dofile(path.."/weather_handling.lua")
        dofile(path.."/environment_effects.lua")
+       dofile(path.."/nether.lua")
 end
 
 --we must delay initialization until the player's camera exists in the world
diff --git a/nether b/nether
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
+++ b/nether
@@ -0,0 +1 @@
+
diff --git a/nether.lua b/nether.lua
new file mode 100644 (file)
index 0000000..7489fe3
--- /dev/null
@@ -0,0 +1,96 @@
+--nether teleporters are animation based
+--the animation must finish before the teleport is initialized
+
+local hud_id = nil --foreground (portal)
+local hud_bg_id = nil --black background
+local cool_off_timer = 0 --use this to stop players teleporting back and forth
+local init_sound = nil
+local teleport_sound = nil
+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 cool_off_timer > 0 then
+               cool_off_timer = cool_off_timer - dtime
+               if cool_off_timer <= 0 then
+                       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 == "nether:portal" and cool_off_timer == 0 then
+               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 = "darkness.png",    -- default ""
+                       })
+                       hud_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=-1, y=-1}, -- default {x=0,y=0}
+                               text = "nether_portal_gui.png",    -- default ""
+                       })
+                       init_sound = minetest.sound_play("portal_initialize",{gain=0,pitch=math.random(70,90)/100})
+                       minetest.sound_fade(init_sound, 0.34, 1)
+                       
+               else
+                       --make the hud zoom in
+                       
+                       local scale = minetest.localplayer:hud_get(hud_id).scale.x
+                       if scale > -100 then
+                               scale = scale - ((scale/-(1/dtime))*2)
+                       elseif scale < -100 then        
+                               scale = -100
+                       end
+                       minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
+               end
+       elseif hud_bg_id and hud_id then
+               --play spooky sounds
+               if init_sound then
+                       minetest.sound_fade(init_sound, -0.25, 0)
+                       init_sound = nil
+                       teleport_sound = minetest.sound_play("portal_teleported",{gain=1,pitch=math.random(70,90)/100})
+                       minetest.sound_fade(teleport_sound, -0.1, 0)
+                       teleport_sound = nil
+               end
+               --make the hud zoom out
+               local scale = minetest.localplayer:hud_get(hud_id).scale.x
+               if scale < -1 then
+                       scale = scale + ((scale/-(1/dtime))*2)
+               elseif scale > -1 then  
+                       scale = -1
+               end
+               minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
+               
+               if scale == -1 then
+                       minetest.localplayer:hud_remove(hud_bg_id)
+                       minetest.localplayer:hud_remove(hud_id)
+                       hud_bg_id = nil
+                       hud_id = nil
+               end
+       elseif hud_bg_id and hud_id then
+               minetest.localplayer:hud_remove(hud_bg_id)
+               minetest.localplayer:hud_remove(hud_id)
+               hud_bg_id = nil
+               hud_id = nil
+       end
+       
+       --initialize teleport command to server
+       if hud_bg_id and hud_id and cool_off_timer == 0 then
+               local scale = minetest.localplayer:hud_get(hud_id).scale.x
+               if scale == -100 then
+                       nether:send_all("teleport me")
+                       --can't use any portal for 6 seconds
+                       cool_off_timer = 6
+               end
+       end
+end)