#include "l_localplayer.h"
#include "l_internal.h"
+#include "lua_api/l_item.h"
#include "script/common/c_converter.h"
#include "client/localplayer.h"
#include "hud.h"
#include "common/c_content.h"
+#include "client/content_cao.h"
LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m)
{
return 1;
}
+// get_wield_index(self)
+int LuaLocalPlayer::l_get_wield_index(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ lua_pushinteger(L, player->getWieldIndex());
+ return 1;
+}
+
+// get_wielded_item(self)
+int LuaLocalPlayer::l_get_wielded_item(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+
+ ItemStack selected_item;
+ player->getWieldedItem(&selected_item, nullptr);
+ LuaItemStack::create(L, selected_item);
+ return 1;
+}
+
int LuaLocalPlayer::l_is_attached(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
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;
}
return 1;
}
+// get_physics_override(self)
int LuaLocalPlayer::l_get_physics_override(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
lua_pushboolean(L, player->physics_override_sneak_glitch);
lua_setfield(L, -2, "sneak_glitch");
- return 1;
-}
-
-int LuaLocalPlayer::l_get_override_pos(lua_State *L)
-{
- LocalPlayer *player = getobject(L, 1);
+ lua_pushboolean(L, player->physics_override_new_move);
+ lua_setfield(L, -2, "new_move");
- push_v3f(L, player->getPosition());
return 1;
}
return 1;
}
-int LuaLocalPlayer::l_get_key_pressed(lua_State *L)
+// get_control(self)
+int LuaLocalPlayer::l_get_control(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
+ const PlayerControl &c = player->getPlayerControl();
+
+ auto set = [L] (const char *name, bool value) {
+ lua_pushboolean(L, value);
+ lua_setfield(L, -2, name);
+ };
+
+ lua_createtable(L, 0, 12);
+ set("jump", c.jump);
+ set("aux1", c.aux1);
+ set("sneak", c.sneak);
+ set("zoom", c.zoom);
+ set("dig", c.dig);
+ set("place", c.place);
+ // Player movement in polar coordinates and non-binary speed
+ set("movement_speed", c.movement_speed);
+ set("movement_direction", c.movement_direction);
+ // Provide direction keys to ensure compatibility
+ set("up", player->keyPressed & (1 << 0)); // Up, down, left, and right were removed in favor of
+ set("down", player->keyPressed & (1 << 1)); // analog direction indicators and are therefore not
+ set("left", player->keyPressed & (1 << 2)); // available as booleans anymore. The corresponding values
+ set("right", player->keyPressed & (1 << 3)); // can still be read from the keyPressed bits though.
- lua_pushinteger(L, player->last_keyPressed);
return 1;
}
+// get_breath(self)
int LuaLocalPlayer::l_get_breath(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
return 1;
}
+// get_pos(self)
int LuaLocalPlayer::l_get_pos(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
return 1;
}
+// get_movement_acceleration(self)
int LuaLocalPlayer::l_get_movement_acceleration(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
return 1;
}
+// get_movement_speed(self)
int LuaLocalPlayer::l_get_movement_speed(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
return 1;
}
+// get_movement(self)
int LuaLocalPlayer::l_get_movement(lua_State *L)
{
LocalPlayer *player = getobject(L, 1);
return 1;
}
+// get_armor_groups(self)
+int LuaLocalPlayer::l_get_armor_groups(lua_State *L)
+{
+ LocalPlayer *player = getobject(L, 1);
+ push_groups(L, player->getCAO()->getGroups());
+ return 1;
+}
// hud_add(self, form)
int LuaLocalPlayer::l_hud_add(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;
}
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
}
luamethod(LuaLocalPlayer, get_velocity),
luamethod(LuaLocalPlayer, get_hp),
luamethod(LuaLocalPlayer, get_name),
+ luamethod(LuaLocalPlayer, get_wield_index),
+ luamethod(LuaLocalPlayer, get_wielded_item),
luamethod(LuaLocalPlayer, is_attached),
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),
- luamethod(LuaLocalPlayer, get_override_pos),
+ // TODO: figure our if these are useful in any way
luamethod(LuaLocalPlayer, get_last_pos),
luamethod(LuaLocalPlayer, get_last_velocity),
luamethod(LuaLocalPlayer, get_last_look_horizontal),
luamethod(LuaLocalPlayer, get_last_look_vertical),
- luamethod(LuaLocalPlayer, get_key_pressed),
+ //
+ luamethod(LuaLocalPlayer, get_control),
luamethod(LuaLocalPlayer, get_breath),
luamethod(LuaLocalPlayer, get_pos),
luamethod(LuaLocalPlayer, get_movement_acceleration),
luamethod(LuaLocalPlayer, get_movement_speed),
luamethod(LuaLocalPlayer, get_movement),
+ luamethod(LuaLocalPlayer, get_armor_groups),
luamethod(LuaLocalPlayer, hud_add),
luamethod(LuaLocalPlayer, hud_remove),
luamethod(LuaLocalPlayer, hud_change),
luamethod(LuaLocalPlayer, hud_get),
+ luamethod(LuaLocalPlayer, get_move_resistance),
+
{0, 0}
};