Merge pull request 'Add 64 items to inventory when creative is on' (#1899) from NO11/MineClone2:inventory into master

Reviewed-on: MineClone2/MineClone2#1899
This commit is contained in:
iliekprogrammar 2021-11-13 19:12:26 +00:00
commit 79e1e2fa8f
1 changed files with 34 additions and 1 deletions

View File

@ -1,5 +1,6 @@
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape local F = minetest.formspec_escape
local C = minetest.colorize
-- Prepare player info table -- Prepare player info table
local players = {} local players = {}
@ -289,6 +290,19 @@ filtername["inv"] = S("Survival Inventory")
bg["default"] = dark_bg bg["default"] = dark_bg
end]] end]]
local function get_stack_size(player)
return player:get_meta():get_int("mcl_inventory:switch_stack")
end
local function set_stack_size(player, n)
player:get_meta():set_int("mcl_inventory:switch_stack", n)
end
minetest.register_on_joinplayer(function (player)
if get_stack_size(player) == 0 then
set_stack_size(player, 64)
end
end)
function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size, show, page, filter) function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size, show, page, filter)
--reset_menu_item_bg() --reset_menu_item_bg()
@ -349,6 +363,8 @@ function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size,
armor_slot_imgs = armor_slot_imgs .. "image[5.5,2.75;1,1;mcl_inventory_empty_armor_slot_boots.png]" armor_slot_imgs = armor_slot_imgs .. "image[5.5,2.75;1,1;mcl_inventory_empty_armor_slot_boots.png]"
end end
local stack_size = get_stack_size(player)
-- Survival inventory slots -- Survival inventory slots
main_list = "list[current_player;main;0,3.75;9,3;9]".. main_list = "list[current_player;main;0,3.75;9,3;9]"..
mcl_formspec.get_itemslot_bg(0,3.75,9,3).. mcl_formspec.get_itemslot_bg(0,3.75,9,3)..
@ -376,7 +392,11 @@ function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size,
-- achievements button -- achievements button
"image_button[9,4;1,1;mcl_achievements_button.png;__mcl_achievements;]".. "image_button[9,4;1,1;mcl_achievements_button.png;__mcl_achievements;]"..
--"style_type[image_button;border=;bgimg=;bgimg_pressed=]".. --"style_type[image_button;border=;bgimg=;bgimg_pressed=]"..
"tooltip[__mcl_achievements;"..F(S("Achievements")).."]" "tooltip[__mcl_achievements;"..F(S("Achievements")).."]"..
-- switch stack size button
"image_button[9,5;1,1;default_apple.png;__switch_stack;]"..
"label[9.4,5.4;".. F(C("#FFFFFF", stack_size ~= 1 and stack_size or "")) .."]"..
"tooltip[__switch_stack;"..F(S("Switch stack size")).."]"
-- For shortcuts -- For shortcuts
listrings = listrings .. listrings = listrings ..
@ -544,6 +564,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.search and not fields.creative_next and not fields.creative_prev then elseif fields.search and not fields.creative_next and not fields.creative_prev then
set_inv_search(string.lower(fields.search),player) set_inv_search(string.lower(fields.search),player)
page = "nix" page = "nix"
elseif fields.__switch_stack then
local switch = 1
if get_stack_size(player) == 1 then
switch = 64
end
set_stack_size(player, switch)
end end
if page then if page then
@ -667,3 +693,10 @@ minetest.register_on_joinplayer(function(player)
init(player) init(player)
mcl_inventory.set_creative_formspec(player, 0, 1, nil, false, "nix", "") mcl_inventory.set_creative_formspec(player, 0, 1, nil, false, "nix", "")
end) end)
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
if minetest.is_creative_enabled(player:get_player_name()) and action == "put" and inventory_info.listname == "main" and get_stack_size(player) == 64 then
local stack = inventory_info.stack
player:get_inventory():set_stack("main", inventory_info.index, stack:get_name() .. " " .. stack:get_stack_max())
end
end)