diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..191625f --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Changes the hotbar slots number. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..58febd6 --- /dev/null +++ b/init.lua @@ -0,0 +1,111 @@ +-- Minetest Mod: hotbar +-- Version: 0.1.0 +-- Licence(s): see the attached license.txt file +-- Author: aristotle, a builder on the Red Cat Creative Server +-- +-- This mod allows the player to set his/her own hotbar slots number +-- by adding a new command. +-- +-- hotbar [size] +-- +-- By itself, hotbar types the hotbar slots number in the chat; +-- when it is followed by a number in the correct range that is [4,16], +-- the command accordingly sets the new slots number. +-- +-- Features: +-- - It permanently stores the user's preference by setting and retrieving +-- the "hotbar_slots" key in the configuration file. +-- +-- Changelog: +-- - The hotbar is now correctly shown even when there are no items in it. +-- +-- FYI +-- The potential range of the hotbar slots number is [1,16]: the next update +-- will cover it too. :D +-- +-- For now this is all folks: happy builds and explorations! :) +-- aristotle + +local hb = {} +hb.min = 4 +hb.max = 16 +hb.default = 16 +hb.setting ="hotbar_slots" +hb.current = minetest.setting_get(hb.setting) or hb.default -- The first time +hb.image = {} +hb.image.selected = "hotbar_slot_selected.png" +hb.image.bg = {nil, nil, nil, + "hotbar_slots_bg_4.png", + "hotbar_slots_bg_5.png", + "hotbar_slots_bg_6.png", + "hotbar_slots_bg_7.png", + "hotbar_slots_bg_8.png", + "hotbar_slots_bg_9.png", + "hotbar_slots_bg_10.png", + "hotbar_slots_bg_11.png", + "hotbar_slots_bg_12.png", + "hotbar_slots_bg_13.png", + "hotbar_slots_bg_14.png", + "hotbar_slots_bg_15.png", + "hotbar_slots_bg_16.png"} + +function hb.show_min() + minetest.chat_send_player(name, "[_] The minimum slots number is " .. hb.min .. ".") +end + +function hb.show_max() + minetest.chat_send_player(name, "[_] The maximum slots number is " .. hb.max .. ".") +end + +function hb.resize(size) + local new_size = tonumber(size) + return hb.image.bg[new_size] +end + +function hb.set(name, slots) + local player = minetest.get_player_by_name(name) + if slots < hb.min then + hb.show_min() + return + end + if slots > hb.max then + hb.show_max() + return + end + player:hud_set_hotbar_itemcount(slots) + player:hud_set_hotbar_selected_image(hb.image.selected) + player:hud_set_hotbar_image(hb.resize(slots)) + minetest.setting_set(hb.setting, slots) -- automatically converted into a string + hb.current = slots + minetest.chat_send_player(name, "[_] Hotbar slots number set to " .. slots .. ".") +end + +function hb.show(name, slots) + minetest.chat_send_player(name, "[_] Hotbar slots: " .. slots) +end + +function hb.command(name, slots) + local new_slots = tonumber(slots) + if not new_slots then + hb.show(name, hb.current) + return + end + + hb.set(name, new_slots) +end + +minetest.register_on_joinplayer(function(player) + player:hud_set_hotbar_itemcount(hb.current) + minetest.after(0.5,function() + player:hud_set_hotbar_selected_image(hb.image.selected) + player:hud_set_hotbar_image(hb.resize(hb.current)) + end) +end) + +minetest.register_chatcommand("hotbar", { + params = "[size]", + description = "If size is passed then it sets your hotbar slots number in the range [4,16], else it displays the current slots number.", + func = hb.command, +}) + + diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..7651649 --- /dev/null +++ b/license.txt @@ -0,0 +1,11 @@ +Textures: +CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/) +Attribution: aristotle and VanessaE + +Code: +License: MIT (https://opensource.org/licenses/MIT) +By aristotle, a builder on the Red Cat Creative Server + +History: +The concept and the original images come from VanessaE's +dreambuilder_mp_extras mod deployed as part of the Dreambuilder modpack. diff --git a/textures/hotbar_slot_selected.png b/textures/hotbar_slot_selected.png new file mode 100644 index 0000000..abb75cc Binary files /dev/null and b/textures/hotbar_slot_selected.png differ diff --git a/textures/hotbar_slots_bg_10.png b/textures/hotbar_slots_bg_10.png new file mode 100644 index 0000000..22afc9d Binary files /dev/null and b/textures/hotbar_slots_bg_10.png differ diff --git a/textures/hotbar_slots_bg_11.png b/textures/hotbar_slots_bg_11.png new file mode 100644 index 0000000..1e2c3eb Binary files /dev/null and b/textures/hotbar_slots_bg_11.png differ diff --git a/textures/hotbar_slots_bg_12.png b/textures/hotbar_slots_bg_12.png new file mode 100644 index 0000000..ee9afe2 Binary files /dev/null and b/textures/hotbar_slots_bg_12.png differ diff --git a/textures/hotbar_slots_bg_13.png b/textures/hotbar_slots_bg_13.png new file mode 100644 index 0000000..2daee6a Binary files /dev/null and b/textures/hotbar_slots_bg_13.png differ diff --git a/textures/hotbar_slots_bg_14.png b/textures/hotbar_slots_bg_14.png new file mode 100644 index 0000000..03b5bfd Binary files /dev/null and b/textures/hotbar_slots_bg_14.png differ diff --git a/textures/hotbar_slots_bg_15.png b/textures/hotbar_slots_bg_15.png new file mode 100644 index 0000000..bef88a6 Binary files /dev/null and b/textures/hotbar_slots_bg_15.png differ diff --git a/textures/hotbar_slots_bg_16.png b/textures/hotbar_slots_bg_16.png new file mode 100644 index 0000000..44011b5 Binary files /dev/null and b/textures/hotbar_slots_bg_16.png differ diff --git a/textures/hotbar_slots_bg_4.png b/textures/hotbar_slots_bg_4.png new file mode 100644 index 0000000..db057bf Binary files /dev/null and b/textures/hotbar_slots_bg_4.png differ diff --git a/textures/hotbar_slots_bg_5.png b/textures/hotbar_slots_bg_5.png new file mode 100644 index 0000000..82965d2 Binary files /dev/null and b/textures/hotbar_slots_bg_5.png differ diff --git a/textures/hotbar_slots_bg_6.png b/textures/hotbar_slots_bg_6.png new file mode 100644 index 0000000..ebdf59b Binary files /dev/null and b/textures/hotbar_slots_bg_6.png differ diff --git a/textures/hotbar_slots_bg_7.png b/textures/hotbar_slots_bg_7.png new file mode 100644 index 0000000..519fada Binary files /dev/null and b/textures/hotbar_slots_bg_7.png differ diff --git a/textures/hotbar_slots_bg_8.png b/textures/hotbar_slots_bg_8.png new file mode 100644 index 0000000..4f77e12 Binary files /dev/null and b/textures/hotbar_slots_bg_8.png differ diff --git a/textures/hotbar_slots_bg_9.png b/textures/hotbar_slots_bg_9.png new file mode 100644 index 0000000..6ba4950 Binary files /dev/null and b/textures/hotbar_slots_bg_9.png differ