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 player_movement_state = minetest.mod_channel_join("player.player_movement_state")
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 local old_sneak = false
53 --attempt to tell the server to allow us to run
54 local send_server_movement_state = function(state)
55 player_movement_state:send_all(state)
58 --receive the server states
59 minetest.register_on_modchannel_message(function(channel_name, sender, message)
60 if channel_name == "player.player_movement_state" then
65 --check player's input on the "up" key
66 minetest.register_globalstep(function(dtime)
67 local input = minetest.get_control_bits(minetest.localplayer)
68 local vel = minetest.localplayer:get_velocity().y
69 local oldvel = minetest.localplayer:get_last_velocity().y
72 if running == true and (input.up == false or input.sneak == true or input.down == true) then
75 send_server_movement_state("0")
78 --add this here so the player can sneak
79 if input.sneak == true then
83 if bunny_hop_timer > 0 then
84 bunny_hop_timer = bunny_hop_timer - dtime
85 if bunny_hop_timer <= 0 then
88 print(bunny_hop_timer)
91 --check if need to tell server to bunnyhop
92 if running == true and vel > 0 and bunny_hop_timer == 0 then
93 send_server_movement_state("2")
95 elseif bunny_hop_timer == 0 then
97 if running == true then
98 send_server_movement_state("1")
100 elseif sneak == true then
101 send_server_movement_state("3")
104 send_server_movement_state("0")
111 --set the sneak state
112 if sneak == true and old_sneak == false then
113 send_server_movement_state("3")
114 elseif input.sneak == false and old_sneak == true then
116 send_server_movement_state("0")
119 --half second window to double tap running
120 if run_discharge_timer > 0 then
121 run_discharge_timer = run_discharge_timer - dtime
122 if run_discharge_timer <= 0 then
123 run_discharge_timer = 0
125 --initialize double tap run
126 if old_up == false and input.up == true then
127 run_discharge_timer = 0
129 --print("running toggle on")
130 send_server_movement_state("1")
133 --check if new input of walking forwards
134 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
135 run_discharge_timer = 0.5
139 old_sneak = input.sneak