]> git.lizzy.rs Git - crafter_client.git/blobdiff - init.lua
Finally fix client not initializing fully, randomly :)
[crafter_client.git] / init.lua
index 263784097edb263990146b7f4a9662244c06a20c..7c52e45332207dc9cf9369a92c50ed69a7f5cb58 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,40 +1,48 @@
---first we join the necessary channels so the mod can "listen" to what the server says
-weather = minetest.mod_channel_join("weather_nodes")
-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")
+--declare globals
+weather_intake = nil
+weather = nil
+weather_type = nil
+running_send = nil
+player_movement_state = nil
+nether = nil
+aether = nil
+run = nil
 
+function initialize_all()
+       --declare globals for now
+       weather_intake = minetest.mod_channel_join("weather_intake")
+       weather = minetest.mod_channel_join("weather_nodes")
+       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")
+       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
+       local path = minetest.get_modpath("crafter_client")
+       dofile(path.."/player_input.lua")
+       dofile(path.."/weather_handling.lua")
+       dofile(path.."/environment_effects.lua")
+       dofile(path.."/nether.lua")
+       dofile(path.."/aether.lua")
+       dofile(path.."/waila.lua")
+       dofile(path.."/music_handling.lua")
+end
 
---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
-local path = minetest.get_modpath("crafter_client")
-dofile(path.."/player_input.lua")
-dofile(path.."/weather_handling.lua")
-
-local old_node
-local in_water = false
-local old_in_water = false
-minetest.register_globalstep(function(dtime)
-       if not minetest.localplayer then
-               return
-       end
-       
-       local vel = minetest.localplayer:get_velocity().y
-       local pos = minetest.localplayer:get_pos()
-       
-       local node = minetest.get_node_or_nil(pos)
-       if node then
-               local name = node.name
-               if name == "main:water" or name == "main:water_flowing" then
-                       in_water = true
-                       if in_water == true and old_in_water == false and vel < 0 then
-                               minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
-                       end
-               else
-                       in_water = false
-               end
+--we must delay initialization until the player exists in the world
+local function recursive_startup_attempt()
+       local ready_to_go = minetest.localplayer
+       if ready_to_go and minetest.get_node_or_nil(minetest.localplayer:get_pos()) then
+               --good to begin
+               initialize_all()
+       else
+               --try again
+               minetest.after(0,function()
+                       recursive_startup_attempt()
+               end)
        end
-       
-       old_node = node
-       old_in_water = in_water
-end)
+end
+
+--begin initial attempt
+recursive_startup_attempt()