Add setting for inventory-size (i4_inventory_size)

Also removes the “legacy inventory” user-setting,
and defaults to 32 for inventory size.
I feel that the individual players shouldn’t be
able to tweak their inventory-size, that’s a
server-level sort of setting.
This commit is contained in:
Jaidyn Ann 2024-01-15 12:51:04 -06:00
parent 80ab1f0a3c
commit 4c8688190a
8 changed files with 53 additions and 34 deletions

View File

@ -30,9 +30,10 @@ These mods have menus built-into i4:
## Configuration
There is currently only one [`minetest.conf`](https://wiki.minetest.net/Minetest.conf) setting used by i4:
There is currently two [`minetest.conf`](https://wiki.minetest.net/Minetest.conf) settings used by i4:
* `i4_progressive_mode = false` — A discovery-based system, where the crafting guide only displays recipes whose components you have held before.
* `i4_inventory_size = 32` — Players inventory-size. Defaults to 32 (or 36, if i3 was previously in use). Only accepted values are 32 and 36.
## Notes

View File

@ -1,11 +1,21 @@
-- This is a placeholder mod, to mimic i3s presence for mods that test for mods
-- that test for it using modpath or some other mechanism.
-- i4 is compatible with i3, mods can use the global tables i3 or i4.
-- This is a placeholder mod, to mimic i3s presence for mods that test for it.
-- It also migrates data from i3 to i4.
local storage = core.get_mod_storage("i3")
local data = core.deserialize(storage:get_string"data") or {}
if data and not i4.imported then
-- i3 stores all user-data in a mod-data table; we copy it verbatim to i4.
i4.data = data
-- By default, i4s inventory-size is 32; i3s, however, is 36. i4 will
-- default to 36 at init-time if data was imported from i3. But since were
-- only importing now (and i4 has already been initialized), we need to do
-- it ourselves this time.
if not i4.settings.inventory_size then
i4.settings.inventory_size = 36
end
-- Mark data as imported, so we dont go through this song-and-dance again.
i4.imported = true
end

View File

@ -27,6 +27,7 @@ i4 = {
damage_enabled = core.settings:get_bool"enable_damage",
progressive_mode = core.settings:get_bool"i4_progressive_mode" or core.settings:get_bool"i3_progressive_mode",
inventory_size = tonumber(core.settings:get"i4_inventory_size") or (storage:get_int"imported_from_i3" and 36),
},
categories = {
@ -52,7 +53,7 @@ i4 = {
wielditem_hud = true,
ignore_hotbar = true,
reverse_sorting = true,
legacy_inventory = true,
hotbar_len = true,
},
default_data = {
@ -60,6 +61,7 @@ i4 = {
font_size = 0,
collapse = true,
inv_compress = true,
hotbar_len = 8,
},
files = {

View File

@ -228,7 +228,7 @@ local function init_data(player, info)
data.lang_code = get_lang_code(info)
data.fs_version = info.formspec_version
update_inv_size(player, data)
update_inv_size(player, data, i4.settings.inventory_size)
core.after(0, set_fs, player)
end
@ -237,17 +237,19 @@ local function save_data(player_name)
local _data = copy(i4.data)
for name, v in pairs(_data) do
for dat in pairs(v) do
if not i4.saves[dat] then
_data[name][dat] = nil
for dat in pairs(v) do
if not i4.saves[dat] then
_data[name][dat] = nil
if player_name and i4.data[player_name] then
i4.data[player_name][dat] = nil -- To free up some memory
if player_name and i4.data[player_name] then
i4.data[player_name][dat] = nil -- To free up some memory
end
end
end
end
end
-- This seems like as good a point as any to save whether or not we
-- imported data from i3.
storage:set_string("data", slz(_data))
if i4.imported then
storage:set_int("imported_from_i3", 1)
@ -262,6 +264,7 @@ insert(core.registered_on_joinplayers, 1, function(player)
return outdated(name)
end
init_data(player, info)
init_bags(player)
init_hud(player)

View File

@ -674,27 +674,27 @@ local function get_detached_inv(name, player_name)
}
end
local function update_inv_size(player, data)
data.hotbar_len = data.legacy_inventory and 8 or 9
data.inv_size = 4 * data.hotbar_len
-- Change a players inventory-size to new_size.
local function update_inv_size(player, data, new_size)
data.hotbar_len = new_size / 4
local inv = player:get_inventory()
local inv_size = inv:get_size("main")
-- Drop items that cant fit in new inventory size.
if inv_size > data.inv_size then
if inv_size > new_size then
sort_inventory(player, data)
for i = data.inv_size + 1, inv_size, 1 do
for i = new_size + 1, inv_size, 1 do
minetest.item_drop(inv:get_stack("main", i), player, player:get_pos())
end
end
inv:set_size("main", data.inv_size)
inv:set_size("main", new_size)
player:hud_set_hotbar_itemcount(data.hotbar_len)
core.after(0, function()
player:hud_set_hotbar_image(data.legacy_inventory and "gui_hotbar.png" or "i3_hotbar.png")
local hotbar_img = data.hotbar_len == 8 and "gui_hotbar.png" or data.hotbar_len == 9 and "i3_hotbar.png"
player:hud_set_hotbar_image(hotbar_img)
end)
end

View File

@ -40,9 +40,7 @@ local function inv_fields(player, data, fields)
data[str] = true
end
if str == "legacy_inventory" then
update_inv_size(player, data)
elseif str == "collapse" then
if str == "collapse" then
search(data)
end

View File

@ -636,7 +636,6 @@ local function settings_footer_fs(player, data, fs)
elseif show_style then
checkbox(2.6, 9.95, "cb_hide_tabs", "Hide tabs", tostring(data.hide_tabs))
checkbox(2.6, 10.4, "cb_legacy_inventory", "Legacy inventory", tostring(data.legacy_inventory))
checkbox(2.6, 10.85, "cb_wielditem_hud", "HUD description", tostring(data.wielditem_hud))
if not recipe_filter_set() then
@ -652,8 +651,6 @@ local function settings_footer_fs(player, data, fs)
fs("tooltip[cb_hide_tabs;%s;#32333899;#fff]",
ES"Enable this option to change the style of the right panel")
fs("tooltip[cb_legacy_inventory;%s;#32333899;#fff]",
ES"Enable this option to set the classic inventory size in Minetest")
fs("tooltip[cb_wielditem_hud;%s;#32333899;#fff]",
ES"Enable this option to show the wielded item description in your HUD")
fs("tooltip[cb_collapse;%s;#32333899;#fff]",
@ -720,11 +717,11 @@ local function get_footer(fs, data, player)
end
local function get_slots(fs, data, player)
local legacy_inventory = data.legacy_inventory
local inv_size = player:get_inventory():get_size("main")
local hotbar_len = data.hotbar_len
local inv_x = legacy_inventory and 0.23 or 0.22
local inv_y = legacy_inventory and 6.7 or 6.9
local spacing = legacy_inventory and 0.25 or 0.1
local inv_x = (inv_size == 32 and 0.23) or (inv_size == 36 and 0.22)
local inv_y = (inv_size == 32 and 6.7) or (inv_size == 36 and 6.9)
local spacing = (inv_size == 32 and 0.25) or (inv_size == 36 and 0.1)
local size = 1
fs"style_type[box;colors=#77777710,#77777710,#777,#777]"
@ -736,10 +733,12 @@ local function get_slots(fs, data, player)
fs("style_type[list;size=%f;spacing=%f]", size, spacing)
fs("list[current_player;main;%f,%f;%u,1;]", inv_x, inv_y, hotbar_len)
fs("style_type[list;size=%f;spacing=%f,%f]", size, spacing, legacy_inventory and 0.15 or spacing)
fs("style_type[list;size=%f;spacing=%f,%f]", size, spacing,
(inv_size == 32 and 0.15) or (inv_size == 36 and spacing))
fs("list[current_player;main;%f,%f;%u,%u;%u]", inv_x, inv_y + (legacy_inventory and 1.25 or 1.15),
hotbar_len, data.inv_size / hotbar_len, hotbar_len)
fs("list[current_player;main;%f,%f;%u,%u;%u]", inv_x, inv_y
+ ((inv_size == 32 and 1.25) or (inv_size == 36 and 1.15)),
hotbar_len, inv_size / hotbar_len, hotbar_len)
fs"listring[current_player;craft]listring[current_player;main]"
@ -748,8 +747,9 @@ end
local function get_inventory_fs(player, data, fs)
local props = player:get_properties()
local inv_size = player:get_inventory():get_size("main")
local ctn_len = 5.7
local ctn_hgt = data.legacy_inventory and 6.1 or 6.3
local ctn_hgt = (inv_size == 32 and 6.1) or (inv_size == 36 and 6.3)
local yoffset = 0
if props.mesh ~= "" then

View File

@ -1,2 +1,7 @@
# The progressive mode shows recipes you can craft from items you ever had in your inventory.
i4_progressive_mode (Learn crafting recipes progressively) bool false
# This sets users inventory-size. For now, the only accepted values are 32 and 36.
# If this is value is lowered, any players that might lose items will have their items
# dropped on the ground.
i4_inventory_size (Change the size of players inventory) int 32