From bdf6163564a72fe8a292a3e934d9908a25109017 Mon Sep 17 00:00:00 2001 From: oilboi Date: Fri, 24 Apr 2020 09:57:17 -0400 Subject: [PATCH] Add aether teleporting --- aether.lua | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 2 ++ 2 files changed, 97 insertions(+) create mode 100644 aether.lua diff --git a/aether.lua b/aether.lua new file mode 100644 index 0000000..8bdd8c3 --- /dev/null +++ b/aether.lua @@ -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) diff --git a/init.lua b/init.lua index 21cc13e..7bc309a 100644 --- 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 -- 2.44.0