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 --stop bunnyhopping on land
84 if bunny_hop == true and vel == 0 and oldvel < 0 then
88 --check if need to tell server to bunnyhop
89 if running == true and vel > 0 and input.jump == true and bunny_hop == false then
90 send_server_movement_state("2")
92 elseif bunny_hop == false then
93 if running == true then
94 send_server_movement_state("1")
96 elseif sneak == true then
97 send_server_movement_state("3")
100 send_server_movement_state("0")
107 --set the sneak state
108 if sneak == true and old_sneak == false then
109 send_server_movement_state("3")
110 elseif input.sneak == false and old_sneak == true then
112 send_server_movement_state("0")
115 --half second window to double tap running
116 if run_discharge_timer > 0 then
117 run_discharge_timer = run_discharge_timer - dtime
118 if run_discharge_timer <= 0 then
119 run_discharge_timer = 0
121 --initialize double tap run
122 if old_up == false and input.up == true then
123 run_discharge_timer = 0
125 --print("running toggle on")
126 send_server_movement_state("1")
129 --check if new input of walking forwards
130 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
131 run_discharge_timer = 0.5
135 old_sneak = input.sneak