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:
parent
80ab1f0a3c
commit
4c8688190a
|
@ -30,9 +30,10 @@ These mods have menus built-into i4:
|
||||||
|
|
||||||
|
|
||||||
## Configuration
|
## 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_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
|
## Notes
|
||||||
|
|
16
i3/init.lua
16
i3/init.lua
|
@ -1,11 +1,21 @@
|
||||||
-- This is a placeholder mod, to mimic i3’s presence for mods that test for mods
|
-- This is a placeholder mod, to mimic i3’s presence for mods that test for it.
|
||||||
-- that test for it using modpath or some other mechanism.
|
-- It also migrates data from i3 to i4.
|
||||||
-- i4 is compatible with i3, mods can use the global tables i3 or i4.
|
|
||||||
|
|
||||||
local storage = core.get_mod_storage("i3")
|
local storage = core.get_mod_storage("i3")
|
||||||
local data = core.deserialize(storage:get_string"data") or {}
|
local data = core.deserialize(storage:get_string"data") or {}
|
||||||
|
|
||||||
if data and not i4.imported then
|
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
|
i4.data = data
|
||||||
|
|
||||||
|
-- By default, i4’s inventory-size is 32; i3’s, however, is 36. i4 will
|
||||||
|
-- default to 36 at init-time if data was imported from i3. But since we’re
|
||||||
|
-- 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 don’t go through this song-and-dance again.
|
||||||
i4.imported = true
|
i4.imported = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,7 @@ i4 = {
|
||||||
|
|
||||||
damage_enabled = core.settings:get_bool"enable_damage",
|
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",
|
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 = {
|
categories = {
|
||||||
|
@ -52,7 +53,7 @@ i4 = {
|
||||||
wielditem_hud = true,
|
wielditem_hud = true,
|
||||||
ignore_hotbar = true,
|
ignore_hotbar = true,
|
||||||
reverse_sorting = true,
|
reverse_sorting = true,
|
||||||
legacy_inventory = true,
|
hotbar_len = true,
|
||||||
},
|
},
|
||||||
|
|
||||||
default_data = {
|
default_data = {
|
||||||
|
@ -60,6 +61,7 @@ i4 = {
|
||||||
font_size = 0,
|
font_size = 0,
|
||||||
collapse = true,
|
collapse = true,
|
||||||
inv_compress = true,
|
inv_compress = true,
|
||||||
|
hotbar_len = 8,
|
||||||
},
|
},
|
||||||
|
|
||||||
files = {
|
files = {
|
||||||
|
|
|
@ -228,7 +228,7 @@ local function init_data(player, info)
|
||||||
data.lang_code = get_lang_code(info)
|
data.lang_code = get_lang_code(info)
|
||||||
data.fs_version = info.formspec_version
|
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)
|
core.after(0, set_fs, player)
|
||||||
end
|
end
|
||||||
|
@ -248,6 +248,8 @@ local function save_data(player_name)
|
||||||
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))
|
storage:set_string("data", slz(_data))
|
||||||
if i4.imported then
|
if i4.imported then
|
||||||
storage:set_int("imported_from_i3", 1)
|
storage:set_int("imported_from_i3", 1)
|
||||||
|
@ -262,6 +264,7 @@ insert(core.registered_on_joinplayers, 1, function(player)
|
||||||
return outdated(name)
|
return outdated(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
init_data(player, info)
|
init_data(player, info)
|
||||||
init_bags(player)
|
init_bags(player)
|
||||||
init_hud(player)
|
init_hud(player)
|
||||||
|
|
|
@ -674,27 +674,27 @@ local function get_detached_inv(name, player_name)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_inv_size(player, data)
|
-- Change a player’s inventory-size to new_size.
|
||||||
data.hotbar_len = data.legacy_inventory and 8 or 9
|
local function update_inv_size(player, data, new_size)
|
||||||
data.inv_size = 4 * data.hotbar_len
|
data.hotbar_len = new_size / 4
|
||||||
|
|
||||||
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local inv_size = inv:get_size("main")
|
local inv_size = inv:get_size("main")
|
||||||
-- Drop items that can’t fit in new inventory size.
|
-- Drop items that can’t fit in new inventory size.
|
||||||
if inv_size > data.inv_size then
|
if inv_size > new_size then
|
||||||
sort_inventory(player, data)
|
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())
|
minetest.item_drop(inv:get_stack("main", i), player, player:get_pos())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
inv:set_size("main", data.inv_size)
|
inv:set_size("main", new_size)
|
||||||
|
|
||||||
player:hud_set_hotbar_itemcount(data.hotbar_len)
|
player:hud_set_hotbar_itemcount(data.hotbar_len)
|
||||||
|
|
||||||
core.after(0, function()
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,7 @@ local function inv_fields(player, data, fields)
|
||||||
data[str] = true
|
data[str] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if str == "legacy_inventory" then
|
if str == "collapse" then
|
||||||
update_inv_size(player, data)
|
|
||||||
elseif str == "collapse" then
|
|
||||||
search(data)
|
search(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -636,7 +636,6 @@ local function settings_footer_fs(player, data, fs)
|
||||||
|
|
||||||
elseif show_style then
|
elseif show_style then
|
||||||
checkbox(2.6, 9.95, "cb_hide_tabs", "Hide tabs", tostring(data.hide_tabs))
|
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))
|
checkbox(2.6, 10.85, "cb_wielditem_hud", "HUD description", tostring(data.wielditem_hud))
|
||||||
|
|
||||||
if not recipe_filter_set() then
|
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]",
|
fs("tooltip[cb_hide_tabs;%s;#32333899;#fff]",
|
||||||
ES"Enable this option to change the style of the right panel")
|
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]",
|
fs("tooltip[cb_wielditem_hud;%s;#32333899;#fff]",
|
||||||
ES"Enable this option to show the wielded item description in your HUD")
|
ES"Enable this option to show the wielded item description in your HUD")
|
||||||
fs("tooltip[cb_collapse;%s;#32333899;#fff]",
|
fs("tooltip[cb_collapse;%s;#32333899;#fff]",
|
||||||
|
@ -720,11 +717,11 @@ local function get_footer(fs, data, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_slots(fs, data, player)
|
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 hotbar_len = data.hotbar_len
|
||||||
local inv_x = legacy_inventory and 0.23 or 0.22
|
local inv_x = (inv_size == 32 and 0.23) or (inv_size == 36 and 0.22)
|
||||||
local inv_y = legacy_inventory and 6.7 or 6.9
|
local inv_y = (inv_size == 32 and 6.7) or (inv_size == 36 and 6.9)
|
||||||
local spacing = legacy_inventory and 0.25 or 0.1
|
local spacing = (inv_size == 32 and 0.25) or (inv_size == 36 and 0.1)
|
||||||
local size = 1
|
local size = 1
|
||||||
|
|
||||||
fs"style_type[box;colors=#77777710,#77777710,#777,#777]"
|
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("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("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),
|
fs("list[current_player;main;%f,%f;%u,%u;%u]", inv_x, inv_y
|
||||||
hotbar_len, data.inv_size / hotbar_len, hotbar_len)
|
+ ((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]"
|
fs"listring[current_player;craft]listring[current_player;main]"
|
||||||
|
|
||||||
|
@ -748,8 +747,9 @@ end
|
||||||
|
|
||||||
local function get_inventory_fs(player, data, fs)
|
local function get_inventory_fs(player, data, fs)
|
||||||
local props = player:get_properties()
|
local props = player:get_properties()
|
||||||
|
local inv_size = player:get_inventory():get_size("main")
|
||||||
local ctn_len = 5.7
|
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
|
local yoffset = 0
|
||||||
|
|
||||||
if props.mesh ~= "" then
|
if props.mesh ~= "" then
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
# The progressive mode shows recipes you can craft from items you ever had in your inventory.
|
# 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
|
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
|
||||||
|
|
Ŝarĝante…
Reference in New Issue