]> git.lizzy.rs Git - crafter_client.git/blobdiff - init.lua
Fix rain to look better
[crafter_client.git] / init.lua
index 4d805008187fcb18c326e4af0b61ab4efee451c8..7bc309aef9f09d26dbab25e73a0bca9cf3540a42 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,95 +1,44 @@
---first we join the necessary channels so the mod can "listen" to what the server says
-local weather = minetest.mod_channel_join("weather_nodes")
-local weather_type = minetest.mod_channel_join("weather_type")
-local running_send = minetest.mod_channel_join("running_send")
-local running_receive = minetest.mod_channel_join("running_receive")
-
-
---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.."/weather_handling.lua")
-
---0 is nothing
---1 is up
---2 is down
---4 is left
---8 is right
---16 is jump
---32 is auxilary
---64 is sneak
---128 is left click
---256 is right click
-
---make the data from get_key_pressed usable
---Thanks Thou shalt use my mods!
-function minetest.get_control_bits(player)
-       local input = player:get_key_pressed()
-       local input_table = {}
-       --iterate through the table using the highest value first
-       local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"}
-       for index,data in pairs(keys) do
-               local modifier = math.pow(2, 9-index)
-               if input >= modifier then
-                       input_table[data] = true
-                       input = input - modifier
-               else
-                       input_table[data] = false
-               end
-       end
-       return(input_table)
+--declare globals
+weather_intake = nil
+weather = nil
+weather_type = nil
+running_send = nil
+player_movement_state = nil
+nether = 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")
 end
 
---double tap running
-
---set up our initial values
-local running = false
-local run_discharge_timer = 0
-local old_up = false
-
---attempt to tell the server to allow us to run
-local send_server_run_state = function(state)
-       running_send:send_all(state)
-end
-
---receive the server states
-minetest.register_on_modchannel_message(function(channel_name, sender, message)
-       if channel_name == "running_receive" then
-               running = (message == "true")
-       end
-end)
-
---check player's input on the "up" key
-minetest.register_globalstep(function(dtime)
-       local input = minetest.get_control_bits(minetest.localplayer)
-       
-       --reset the run flag
-       if running == true and (input.up == false or input.sneak == true or input.down == true) then
-               running = false
-               --print("running toggle off")
-               send_server_run_state("false")
-       end
-       
-       --half second window to double tap running
-       if run_discharge_timer > 0 then
-               run_discharge_timer = run_discharge_timer - dtime
-               if run_discharge_timer <= 0 then
-                       run_discharge_timer = 0
-               end
-               --initialize double tap run
-               if old_up == false and input.up == true then
-                       run_discharge_timer = 0
-                       running = true
-                       --print("running toggle on")
-                       send_server_run_state("true")
-               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 then
+               --good to begin
+               initialize_all()
+       else
+               --try again
+               minetest.after(0,function()
+                       recursive_startup_attempt()
+               end)
        end
-       --check if new input of walking forwards
-       if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
-               run_discharge_timer = 0.5
-       end
-       --save old value
-       old_up = input.up
-end)
-
+end
 
+--begin initial attempt
+recursive_startup_attempt()