1 --first we join the necessary channels so the mod can "listen" to what the server says
2 local weather = minetest.mod_channel_join("weather_nodes")
3 local weather_type = minetest.mod_channel_join("weather_type")
4 local running_send = minetest.mod_channel_join("running_send")
5 local running_receive = minetest.mod_channel_join("running_receive")
8 --we load everything seperately because it's easier to work on individual files than have everything jammed into one file
9 --not into seperate mods because that is unnecessary and cumbersome
10 local path = minetest.get_modpath("crafter_client")
11 dofile(path.."/weather_handling.lua")
24 --make the data from get_key_pressed usable
25 --Thanks Thou shalt use my mods!
26 function minetest.get_control_bits(player)
27 local input = player:get_key_pressed()
28 local input_table = {}
29 --iterate through the table using the highest value first
30 local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"}
31 for index,data in pairs(keys) do
32 local modifier = math.pow(2, 9-index)
33 if input >= modifier then
34 input_table[data] = true
35 input = input - modifier
37 input_table[data] = false
45 --set up our initial values
47 local run_discharge_timer = 0
50 --attempt to tell the server to allow us to run
51 local send_server_run_state = function(state)
52 running_send:send_all(state)
55 --receive the server states
56 minetest.register_on_modchannel_message(function(channel_name, sender, message)
57 if channel_name == "running_receive" then
58 running = (message == "true")
62 --check player's input on the "up" key
63 minetest.register_globalstep(function(dtime)
64 local input = minetest.get_control_bits(minetest.localplayer)
67 if running == true and (input.up == false or input.sneak == true or input.down == true) then
69 --print("running toggle off")
70 send_server_run_state("false")
73 --half second window to double tap running
74 if run_discharge_timer > 0 then
75 run_discharge_timer = run_discharge_timer - dtime
76 if run_discharge_timer <= 0 then
77 run_discharge_timer = 0
79 --initialize double tap run
80 if old_up == false and input.up == true then
81 run_discharge_timer = 0
83 --print("running toggle on")
84 send_server_run_state("true")
87 --check if new input of walking forwards
88 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
89 run_discharge_timer = 0.5