1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Clamp hotbar selection to slots that exist (#14869)

This commit is contained in:
1F616EMO~nya 2024-08-12 21:35:13 +08:00 committed by GitHub
parent 39c2af9710
commit 98e51a0159
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 51 additions and 11 deletions

View file

@ -2188,12 +2188,14 @@ void Game::processItemSelection(u16 *new_playeritem)
{
LocalPlayer *player = client->getEnv().getLocalPlayer();
*new_playeritem = player->getWieldIndex();
u16 max_item = player->getMaxHotbarItemcount();
if (max_item == 0)
return;
max_item -= 1;
/* Item selection using mouse wheel
*/
*new_playeritem = player->getWieldIndex();
u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE - 1,
player->hud_hotbar_itemcount - 1);
s32 wheel = input->getMouseWheel();
if (!m_enable_hotbar_mouse_wheel)
wheel = 0;

View file

@ -783,7 +783,7 @@ void Hud::drawHotbar(u16 playeritem)
v2s32 centerlowerpos(m_displaycenter.X, m_screensize.Y);
s32 hotbar_itemcount = player->hud_hotbar_itemcount;
s32 hotbar_itemcount = player->getMaxHotbarItemcount();
s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2);
v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3);