From 17cb0683aa748394a5efc27efd9caa22069ea03b Mon Sep 17 00:00:00 2001 From: Serhii Mozhaiskyi Date: Sun, 6 Feb 2022 19:30:32 +0200 Subject: [PATCH] add hotbar mod --- .../minestead_hotbar/depends.txt | 1 + MineStead_modpack/minestead_hotbar/init.lua | 50 ++++++++++++++++++ .../minestead_hotbar/textures/gui_hb_bg_1.png | Bin 0 -> 295 bytes 3 files changed, 51 insertions(+) create mode 100644 MineStead_modpack/minestead_hotbar/depends.txt create mode 100644 MineStead_modpack/minestead_hotbar/init.lua create mode 100644 MineStead_modpack/minestead_hotbar/textures/gui_hb_bg_1.png diff --git a/MineStead_modpack/minestead_hotbar/depends.txt b/MineStead_modpack/minestead_hotbar/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/MineStead_modpack/minestead_hotbar/depends.txt @@ -0,0 +1 @@ +default diff --git a/MineStead_modpack/minestead_hotbar/init.lua b/MineStead_modpack/minestead_hotbar/init.lua new file mode 100644 index 0000000..0012496 --- /dev/null +++ b/MineStead_modpack/minestead_hotbar/init.lua @@ -0,0 +1,50 @@ +local mod_storage = minetest.get_mod_storage() + +local function validate_size(s) + local size = s and tonumber(s) or 8 + return math.floor(0.5 + math.max(1, math.min(size, 32))) +end + +local hotbar_size_default = 8 + +local base_img = "gui_hb_bg_1.png" +local imgref_len = string.len(base_img) + 8 -- accounts for the stuff in the string.format() below. + +local img = {} +for i = 0, 31 do + img[i+1] = string.format(":%04i,0=%s", i*64, base_img) +end +local hb_img = table.concat(img) + +local function set_hotbar_size(player, s) + local hotbar_size = validate_size(s) + player:hud_set_hotbar_itemcount(hotbar_size) + player:hud_set_hotbar_selected_image("gui_hotbar_selected.png") + player:hud_set_hotbar_image("[combine:"..(hotbar_size*64).."x64"..string.sub(hb_img, 1, hotbar_size*imgref_len)) + return hotbar_size +end + +minetest.register_on_joinplayer(function(player) + minetest.after(0.5,function() + local size = mod_storage:get_int(player:get_player_name()) + if size == 0 then + size = hotbar_size_default + end + set_hotbar_size(player, size) + end) +end) + +minetest.register_chatcommand("hotbar", { + params = "[size]", + description = "Sets the size of your hotbar, from 1 to 32 slots, default 8", + privs = { hotbar = true }, + func = function(name, slots) + local size = set_hotbar_size(minetest.get_player_by_name(name), slots) + minetest.chat_send_player(name, "[_] Hotbar size set to " ..size.. ".") + mod_storage:set_int(name, size) + end, +}) + +minetest.register_privilege("hotbar", { + description = "Allows to set hotbar size" +}) diff --git a/MineStead_modpack/minestead_hotbar/textures/gui_hb_bg_1.png b/MineStead_modpack/minestead_hotbar/textures/gui_hb_bg_1.png new file mode 100644 index 0000000000000000000000000000000000000000..2e53a5b5ed7105f55a6d78e0dc8d58980eab347a GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=?>t=`Ln>~)y}gn5kbyw!!*Y$h z6_=LSW_?Rw;Gbf|oXYTR!7HECpyaevWbNx)Dh}r&kH570`j3+d=p0Hw?$h