diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua index 0da3dab1b..e947c564f 100644 --- a/builtin/client/chatcommands.lua +++ b/builtin/client/chatcommands.lua @@ -69,7 +69,7 @@ core.register_chatcommand("teleport", { core.register_chatcommand("wielded", { description = "Print itemstring of wieleded item", func = function() - return true, core.localplayer:get_wielded_item():get_name() + return true, core.localplayer:get_wielded_item():to_string() end }) diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 3f4147227..747657016 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -66,10 +66,10 @@ int LuaLocalPlayer::l_get_velocity(lua_State *L) int LuaLocalPlayer::l_set_velocity(lua_State *L) { LocalPlayer *player = getobject(L, 1); - + v3f pos = checkFloatPos(L, 2); player->setSpeed(pos); - + return 0; } @@ -89,7 +89,7 @@ int LuaLocalPlayer::l_set_yaw(lua_State *L) g_game->cam_view.camera_yaw = yaw; g_game->cam_view_target.camera_yaw = yaw; } - + return 0; } @@ -109,7 +109,7 @@ int LuaLocalPlayer::l_set_pitch(lua_State *L) g_game->cam_view.camera_pitch = pitch; g_game->cam_view_target.camera_pitch = pitch; } - + return 0; } @@ -144,7 +144,7 @@ int LuaLocalPlayer::l_set_wield_index(lua_State *L) { LocalPlayer *player = getobject(L, 1); u32 index = luaL_checkinteger(L, 2) - 1; - + player->setWieldIndex(index); g_game->processItemSelection(&g_game->runData.new_playeritem); ItemStack selected_item, hand_item; @@ -226,7 +226,7 @@ int LuaLocalPlayer::l_get_physics_override(lua_State *L) LocalPlayer *player = getobject(L, 1); push_physics_override(L, player->physics_override_speed, player->physics_override_jump, player->physics_override_gravity, player->physics_override_sneak, player->physics_override_sneak_glitch, player->physics_override_new_move); - + return 1; } @@ -234,7 +234,7 @@ int LuaLocalPlayer::l_get_physics_override(lua_State *L) int LuaLocalPlayer::l_set_physics_override(lua_State *L) { LocalPlayer *player = getobject(L, 1); - + player->physics_override_speed = getfloatfield_default( L, 2, "speed", player->physics_override_speed); player->physics_override_jump = getfloatfield_default( @@ -331,7 +331,7 @@ int LuaLocalPlayer::l_get_pos(lua_State *L) int LuaLocalPlayer::l_set_pos(lua_State *L) { LocalPlayer *player = getobject(L, 1); - + v3f pos = checkFloatPos(L, 2); player->setPosition(pos); getClient(L)->sendPlayerPos(); @@ -476,6 +476,7 @@ int LuaLocalPlayer::l_hud_get(lua_State *L) return 1; } +// get_object(self) int LuaLocalPlayer::l_get_object(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -487,6 +488,15 @@ int LuaLocalPlayer::l_get_object(lua_State *L) return 1; } +// get_hotbar_size(self) +int LuaLocalPlayer::l_get_hotbar_size(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + lua_pushnumber(L, player->hud_hotbar_itemcount); + + return 1; +} + LuaLocalPlayer *LuaLocalPlayer::checkobject(lua_State *L, int narg) { luaL_checktype(L, narg, LUA_TUSERDATA); @@ -585,6 +595,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = { luamethod(LuaLocalPlayer, hud_change), luamethod(LuaLocalPlayer, hud_get), luamethod(LuaLocalPlayer, get_object), + luamethod(LuaLocalPlayer, get_hotbar_size), {0, 0} }; diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index 33e23d178..bb5a294ca 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -65,6 +65,9 @@ private: // get_wielded_item(self) static int l_get_wielded_item(lua_State *L); + // get_hotbar_size(self) + static int l_get_hotbar_size(lua_State *L); + static int l_is_attached(lua_State *L); static int l_is_touching_ground(lua_State *L); static int l_is_in_liquid(lua_State *L);