From 3470687be0af7254aca478ead1e9c72757edf070 Mon Sep 17 00:00:00 2001 From: orwell Date: Tue, 27 May 2025 21:17:10 +0200 Subject: Add CH dependencies temporarily. Before merge to master should remove them again and split out util functions (e.g. formspec lib) --- ch_core/hotbar.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ch_core/hotbar.lua (limited to 'ch_core/hotbar.lua') diff --git a/ch_core/hotbar.lua b/ch_core/hotbar.lua new file mode 100644 index 0000000..054210f --- /dev/null +++ b/ch_core/hotbar.lua @@ -0,0 +1,49 @@ +ch_core.open_submod("hotbar") + +function ch_core.predmety_na_liste(player, jako_pole) + local result = {} + if not player then + return result + end + local inv = player:get_inventory() + if not inv then + return result + end + local hotbar = inv:get_list("main") + if not hotbar then + return result + end + local hotbar_length = player:hud_get_hotbar_itemcount() + + if not hotbar_length then + hotbar_length = 8 + elseif hotbar_length > 32 then + hotbar_length = 32 + elseif hotbar_length < 1 then + hotbar_length = 1 + end + + if jako_pole then + for i = 1, hotbar_length, 1 do + local name = hotbar[i]:get_name() + if name and name ~= "" then + local t = result[name] + if t then + table.insert(t, i) + else + result[name] = {i} + end + end + end + else + for i = hotbar_length, 1, -1 do + local name = hotbar[i]:get_name() + if name and name ~= "" then + result[name] = i + end + end + end + return result +end + +ch_core.close_submod("hotbar") -- cgit v1.2.3