]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add in better sleeping
authoroilboi <47129783+oilboi@users.noreply.github.com>
Thu, 25 Jun 2020 08:50:19 +0000 (04:50 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Thu, 25 Jun 2020 08:50:19 +0000 (04:50 -0400)
init.lua
sleeping.lua [new file with mode: 0644]
version_send.lua

index 5d645fba7a2be57d90abb38588bd282b1e1e4164..72e2c05afc89d42d97f81242d6c6eb4d6142b5df 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -24,6 +24,7 @@ function initialize_all()
        dofile(path.."/version_send.lua")
        dofile(path.."/colored_names/colored_names.lua")
        dofile(path.."/fire_handling.lua")
+       dofile(path.."/sleeping.lua")
 end
 
 --we must delay initialization until the player exists in the world
@@ -42,18 +43,3 @@ end
 
 --begin initial attempt
 recursive_startup_attempt()
-
---leave mod channels on shutdown
---[[
-minetest.register_on_shutdown(function()
-       weather_intake = nil
-       weather = nil
-       weather_type = nil
-       player_movement_state = nil
-       nether = nil
-       aether = nil
-       name = nil
-       version_channel = nil
-       fire_handling_channel = nil
-end)
-]]--
\ No newline at end of file
diff --git a/sleeping.lua b/sleeping.lua
new file mode 100644 (file)
index 0000000..48681ff
--- /dev/null
@@ -0,0 +1,51 @@
+local minetest,name = minetest,minetest.localplayer:get_name()
+local sleep_channel = minetest.mod_channel_join(name..":sleep_channel")
+local sleeping = 0
+local sleep_fade = 0
+local sleep_id = nil
+
+minetest.register_on_modchannel_message(function(channel_name, sender, message)
+       if sender == "" and channel_name == name..":sleep_channel" then
+        sleeping = tonumber(message)
+       end
+end)
+
+
+
+minetest.register_globalstep(function(dtime)
+    if sleeping == 0 and sleep_fade == 0 then
+        if sleep_id then
+            sleep_id = nil
+        end
+        return
+    elseif sleeping == 1 and sleep_fade < 255 then
+        if not sleep_id then
+            sleep_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 = "sleep.png^[opacity:"..sleep_fade,
+            })
+        else
+            sleep_fade = sleep_fade + (dtime*100)
+            if sleep_fade >= 255 then
+                sleep_fade = 255
+                sleep_channel:send_all("true")
+            end
+            minetest.localplayer:hud_change(sleep_id, "text", "sleep.png^[opacity:"..sleep_fade)
+        end
+    elseif sleeping == 0 and sleep_fade > 0 then
+        if sleep_id then
+            sleep_fade = sleep_fade - (dtime*500)
+            if sleep_fade < 0 then
+                sleep_fade = 0
+            end
+            minetest.localplayer:hud_change(sleep_id, "text", "sleep.png^[opacity:"..sleep_fade)
+            if sleep_fade == 0 then
+                minetest.localplayer:hud_remove(sleep_id)
+                sleep_id = nil
+            end
+        end
+    end
+end)
\ No newline at end of file
index e12a3dc5190d63a6e118fc11f7ba063950fc91a1..e7c7549b5235fa86443bbf69d531080ad4ad0774 100644 (file)
@@ -1,5 +1,5 @@
 local minetest,name = minetest,minetest.localplayer:get_name()
 local version_channel = minetest.mod_channel_join(name..":client_version_channel")
 minetest.after(2,function() -- this needs a few seconds for the mod channel to open up
-    version_channel:send_all("0.05010")
+    version_channel:send_all("0.05011")
 end)
\ No newline at end of file