Fix sscsm.get_player_control() on MT 5.4.0-dev.

This further bloats sscsm_init.lua to ensure the LMB/RMB fields are 
equal to dig/place.
This commit is contained in:
luk3yx 2020-08-26 21:55:30 +12:00
parent f91e4cc9f9
commit e7bc9aafca
2 changed files with 29 additions and 10 deletions

View File

@ -130,6 +130,8 @@ SSCSMs can access most functions on [client_lua_api.txt](https://github.com/mine
- `sscsm.get_player_control()`: Alternative for
`minetest.localplayer:get_control()` that works with Minetest 5.2.0 and
below.
- The `LMB` and `RMB` fields are deprecated and will probably be removed in
the future, use `dig` and `place` instead.
- `sscsm.every(interval, func, ...)`: Calls `func` every `interval` seconds
with any extra parameters specified. Use `minetest.register_globalstep`
instead if `interval` is `0`.

View File

@ -133,22 +133,39 @@ end
-- A proper get_player_control didn't exist before Minetest 5.3.0.
if minetest.localplayer.get_control then
-- Preserve API compatibility
if minetest.localplayer:get_control().LMB == nil then
-- MT 5.4+
function sscsm.get_player_control()
return minetest.localplayer:get_control()
local c = minetest.localplayer:get_control()
c.LMB, c.RMB = c.dig, c.place
return c
end
else
-- MT 5.3
function sscsm.get_player_control()
local c = minetest.localplayer:get_control()
c.dig, c.place = c.LMB, c.RMB
return c
end
end
else
-- MT 5.0 to 5.2
local floor = math.floor
function sscsm.get_player_control()
local n = minetest.localplayer:get_key_pressed()
return {
up = n % 2 == 1,
down = math.floor(n / 2) % 2 == 1,
left = math.floor(n / 4) % 2 == 1,
right = math.floor(n / 8) % 2 == 1,
jump = math.floor(n / 16) % 2 == 1,
aux1 = math.floor(n / 32) % 2 == 1,
sneak = math.floor(n / 64) % 2 == 1,
LMB = math.floor(n / 128) % 2 == 1,
RMB = math.floor(n / 256) % 2 == 1,
down = floor(n / 2) % 2 == 1,
left = floor(n / 4) % 2 == 1,
right = floor(n / 8) % 2 == 1,
jump = floor(n / 16) % 2 == 1,
aux1 = floor(n / 32) % 2 == 1,
sneak = floor(n / 64) % 2 == 1,
LMB = floor(n / 128) % 2 == 1,
RMB = floor(n / 256) % 2 == 1,
dig = floor(n / 128) % 2 == 1,
place = floor(n / 256) % 2 == 1,
}
end