Update .wielded command to output the entire itemstring; add LocalPlayer:get_hotbar_size

This commit is contained in:
Elias Fleckenstein 2021-03-10 17:50:34 +01:00
parent 1669682324
commit 7613d9bfe6
3 changed files with 23 additions and 9 deletions

View File

@ -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
})

View File

@ -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}
};

View File

@ -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);