mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Merge pull request 'Add 64 items to inventory when creative is on' (#1899) from NO11/MineClone2:inventory into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/1899
This commit is contained in:
commit
79e1e2fa8f
1 changed files with 34 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
local F = minetest.formspec_escape
|
||||
local C = minetest.colorize
|
||||
|
||||
-- Prepare player info table
|
||||
local players = {}
|
||||
|
@ -289,6 +290,19 @@ filtername["inv"] = S("Survival Inventory")
|
|||
bg["default"] = dark_bg
|
||||
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)
|
||||
--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]"
|
||||
end
|
||||
|
||||
local stack_size = get_stack_size(player)
|
||||
|
||||
-- Survival inventory slots
|
||||
main_list = "list[current_player;main;0,3.75;9,3;9]"..
|
||||
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
|
||||
"image_button[9,4;1,1;mcl_achievements_button.png;__mcl_achievements;]"..
|
||||
--"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
|
||||
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
|
||||
set_inv_search(string.lower(fields.search),player)
|
||||
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
|
||||
|
||||
if page then
|
||||
|
@ -667,3 +693,10 @@ minetest.register_on_joinplayer(function(player)
|
|||
init(player)
|
||||
mcl_inventory.set_creative_formspec(player, 0, 1, nil, false, "nix", "")
|
||||
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)
|
Loading…
Reference in a new issue