3 --set up our initial values
7 local run_discharge_timer = 0
10 local old_sneak = false
11 local bunny_hop = false
12 local old_bunny_hop = false
25 --make the data from get_key_pressed usable
26 --Thanks Thou shalt use my mods!
27 function minetest.get_control_bits(player)
28 local input = player:get_key_pressed()
29 local input_table = {}
30 --iterate through the table using the highest value first
31 local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"}
32 for index,data in pairs(keys) do
33 local modifier = math.pow(2, 9-index)
34 if input >= modifier then
35 input_table[data] = true
36 input = input - modifier
38 input_table[data] = false
46 --attempt to tell the server to allow us to run
47 local send_server_movement_state = function(state)
48 player_movement_state:send_all(state)
52 --receive the server states
53 minetest.register_on_modchannel_message(function(channel_name, sender, message)
54 if channel_name == "player.player_movement_state" then
59 --check player's input on the "up" key
60 minetest.register_globalstep(function(dtime)
62 if not minetest.localplayer then
66 --save this for the 5.3.0 version
67 --local input = minetest.localplayer:get_control()
68 local input = minetest.get_control_bits(minetest.localplayer)
69 local vel = minetest.localplayer:get_velocity()
70 local oldvel = minetest.localplayer:get_last_velocity()
72 --cancel running if the player bumps into something
75 if running == true and ((vel.x == 0 and oldvel.x ~= 0) or (vel.z == 0 and oldvel.z ~= 0)) then
78 run_discharge_timer = 0
84 if running == true and (input.up == false or input.sneak == true or input.down == true) then
91 --check if need to tell server to bunnyhop
92 if running == true and vel.y > 0 and input.jump == true and bunny_hop == false then
98 if bunny_hop == true and input.jump == false and running == true and vel.y == 0 then
104 --half second window to double tap running
105 if run_discharge_timer > 0 then
106 run_discharge_timer = run_discharge_timer - dtime
107 if run_discharge_timer <= 0 then
108 run_discharge_timer = 0
110 --initialize double tap run
111 if old_up == false and input.up == true and vel.x ~= 0 and vel.z ~= 0 then
112 run_discharge_timer = 0
119 --check if new input of walking forwards
120 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
121 run_discharge_timer = 0.2
124 --add this here so the player can sneak
125 if input.sneak == true then
126 run_discharge_timer = 0
133 --set the sneak state
134 if sneak == true and old_sneak == false then
136 elseif input.sneak == false and old_sneak == true then
141 --only send if state has changed
142 if state ~= old_state then
143 send_server_movement_state(tostring(state))
148 old_sneak = input.sneak
149 old_bunny_hop = bunny_hop