1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +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

@ -84,3 +84,25 @@ local function run_player_add_pos_tests(player)
end
unittests.register("test_player_add_pos", run_player_add_pos_tests, {player=true})
--
-- Hotbar selection clamp
--
local function run_player_hotbar_clamp_tests(player)
local inv = player:get_inventory()
local old_inv_size = inv:get_size("main")
local old_inv_list = inv:get_list("main") -- Avoid accidentally removing item
local old_bar_size = player:hud_get_hotbar_itemcount()
inv:set_size("main", 5)
player:hud_set_hotbar_itemcount(2)
assert(player:hud_get_hotbar_itemcount() == 2)
player:hud_set_hotbar_itemcount(6)
assert(player:hud_get_hotbar_itemcount() == 5)
inv:set_size("main", old_inv_size)
inv:set_list("main", old_inv_list)
player:hud_set_hotbar_itemcount(old_bar_size)
end
unittests.register("test_player_hotbar_clamp", run_player_hotbar_clamp_tests, {player=true})