aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_localplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_localplayer.cpp')
-rw-r--r--src/script/lua_api/l_localplayer.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 33fa27c8b..2efb976c7 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -128,11 +128,11 @@ int LuaLocalPlayer::l_is_in_liquid_stable(lua_State *L)
return 1;
}
-int LuaLocalPlayer::l_get_liquid_viscosity(lua_State *L)
+int LuaLocalPlayer::l_get_move_resistance(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
- lua_pushinteger(L, player->liquid_viscosity);
+ lua_pushinteger(L, player->move_resistance);
return 1;
}
@@ -223,16 +223,22 @@ int LuaLocalPlayer::l_get_control(lua_State *L)
};
lua_createtable(L, 0, 12);
- set("up", c.up);
- set("down", c.down);
- set("left", c.left);
- set("right", c.right);
- set("jump", c.jump);
- set("aux1", c.aux1);
+ set("jump", c.jump);
+ set("aux1", c.aux1);
set("sneak", c.sneak);
- set("zoom", c.zoom);
- set("dig", c.dig);
+ set("zoom", c.zoom);
+ set("dig", c.dig);
set("place", c.place);
+ // Player movement in polar coordinates and non-binary speed
+ lua_pushnumber(L, c.movement_speed);
+ lua_setfield(L, -2, "movement_speed");
+ lua_pushnumber(L, c.movement_direction);
+ lua_setfield(L, -2, "movement_direction");
+ // Provide direction keys to ensure compatibility
+ set("up", c.direction_keys & (1 << 0));
+ set("down", c.direction_keys & (1 << 1));
+ set("left", c.direction_keys & (1 << 2));
+ set("right", c.direction_keys & (1 << 3));
return 1;
}
@@ -369,10 +375,11 @@ int LuaLocalPlayer::l_hud_change(lua_State *L)
if (!element)
return 0;
+ HudElementStat stat;
void *unused;
- read_hud_change(L, element, &unused);
+ bool ok = read_hud_change(L, stat, element, &unused);
- lua_pushboolean(L, true);
+ lua_pushboolean(L, ok);
return 1;
}
@@ -446,7 +453,7 @@ void LuaLocalPlayer::Register(lua_State *L)
lua_pop(L, 1); // Drop metatable
- luaL_openlib(L, 0, methods, 0); // fill methodtable
+ luaL_register(L, nullptr, methods); // fill methodtable
lua_pop(L, 1); // Drop methodtable
}
@@ -461,7 +468,6 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, is_touching_ground),
luamethod(LuaLocalPlayer, is_in_liquid),
luamethod(LuaLocalPlayer, is_in_liquid_stable),
- luamethod(LuaLocalPlayer, get_liquid_viscosity),
luamethod(LuaLocalPlayer, is_climbing),
luamethod(LuaLocalPlayer, swimming_vertical),
luamethod(LuaLocalPlayer, get_physics_override),
@@ -483,5 +489,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
luamethod(LuaLocalPlayer, hud_change),
luamethod(LuaLocalPlayer, hud_get),
+ luamethod(LuaLocalPlayer, get_move_resistance),
+
{0, 0}
};