12 --make the data from get_key_pressed usable
13 --Thanks Thou shalt use my mods!
14 function minetest.get_control_bits(player)
15 local input = player:get_key_pressed()
16 local input_table = {}
17 --iterate through the table using the highest value first
18 local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"}
19 for index,data in pairs(keys) do
20 local modifier = math.pow(2, 9-index)
21 if input >= modifier then
22 input_table[data] = true
23 input = input - modifier
25 input_table[data] = false
33 --set up our initial values
37 local run_discharge_timer = 0
40 local old_sneak = false
41 local bunny_hop = false
42 local old_bunny_hop = false
44 --attempt to tell the server to allow us to run
45 local send_server_movement_state = function(state)
46 player_movement_state:send_all(state)
50 --receive the server states
51 minetest.register_on_modchannel_message(function(channel_name, sender, message)
52 if channel_name == "player.player_movement_state" then
57 --check player's input on the "up" key
58 minetest.register_globalstep(function(dtime)
60 if not minetest.localplayer then
64 local input = minetest.get_control_bits(minetest.localplayer)
65 local vel = minetest.localplayer:get_velocity()
66 --local oldvel = minetest.localplayer:get_last_velocity()
68 --cancel running if the player bumps into something
69 --this doesn't work because the engine's collision detection is messed up
72 if running == true and ((vel.x == 0 and oldvel.x ~= 0) or (vel.z == 0 and oldvel.z ~= 0)) then
75 run_discharge_timer = 0
81 if running == true and (input.up == false or input.sneak == true or input.down == true) then
88 --check if need to tell server to bunnyhop
89 if running == true and vel.y > 0 and input.jump == true and bunny_hop == false then
95 if bunny_hop == true and input.jump == false and running == true and vel.y == 0 then
101 --half second window to double tap running
102 if run_discharge_timer > 0 then
103 run_discharge_timer = run_discharge_timer - dtime
104 if run_discharge_timer <= 0 then
105 run_discharge_timer = 0
107 --initialize double tap run
108 if old_up == false and input.up == true then
109 run_discharge_timer = 0
116 --check if new input of walking forwards
117 if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then
118 run_discharge_timer = 0.2
121 --add this here so the player can sneak
122 if input.sneak == true then
123 run_discharge_timer = 0
130 --set the sneak state
131 if sneak == true and old_sneak == false then
133 elseif input.sneak == false and old_sneak == true then
138 --only send if state has changed
139 if state ~= old_state then
140 send_server_movement_state(tostring(state))
145 old_sneak = input.sneak
146 old_bunny_hop = bunny_hop