diff options
author | ShadowNinja <noreply@gmail.com> | 2013-09-28 18:15:37 -0400 |
---|---|---|
committer | ShadowNinja <noreply@gmail.com> | 2013-09-28 18:15:37 -0400 |
commit | f974fd8c2c8532179edea54643fb10fa4091f322 (patch) | |
tree | 8c70a55274d7f97b6fd9effe5227bef015e0a8e0 /bags.lua | |
parent | e3d391d63f8d6409bdded5c80fe1f5f2de442595 (diff) |
Update
Diffstat (limited to 'bags.lua')
-rw-r--r-- | bags.lua | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -3,6 +3,61 @@ -- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com> -- License: GPLv3 +unified_inventory.register_page("bags", { + get_formspec = function(player, formspec) + local player_name = player:get_player_name() + formspec = formspec .. "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]" + formspec = formspec.."label[0,0;Bags]" + formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]" + formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]" + formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]" + formspec = formspec.."button[6,2;2,0.5;bag4;Bag 4]" + formspec = formspec.."list[detached:"..player_name.."_bags;bag1;0.5,1;1,1;]" + formspec = formspec.."list[detached:"..player_name.."_bags;bag2;2.5,1;1,1;]" + formspec = formspec.."list[detached:"..player_name.."_bags;bag3;4.5,1;1,1;]" + formspec = formspec.."list[detached:"..player_name.."_bags;bag4;6.5,1;1,1;]" + return formspec + end, +}) + +unified_inventory.register_button("bags", { + type = "image", + image = "ui_bags_icon.png", +}) + +for i = 1, 4 do + unified_inventory.register_page("bag"..i, { + get_formspec = function(player, formspec) + local stack = player:get_inventory():get_stack("bag"..i, 1) + local image = stack:get_definition().inventory_image + formspec = formspec.."image[7,0;1,1;"..image.."]" + formspec = formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]" + local slots = stack:get_definition().groups.bagslots + if slots == 8 then + formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]" + elseif slots == 16 then + formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]" + elseif slots == 24 then + formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]" + end + return formspec + end, + }) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + for i = 1, 4 do + if fields["bag"..i] then + local stack = player:get_inventory():get_stack("bag"..i, 1) + if not stack:get_definition().groups.bagslots then + return + end + unified_inventory.set_inventory_formspec(player, "bag"..i) + return + end + end +end) + minetest.register_on_joinplayer(function(player) local player_inv = player:get_inventory() local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{ @@ -22,7 +77,7 @@ minetest.register_on_joinplayer(function(player) end end, allow_take = function(inv, listname, index, stack, player) - if player:get_inventory():is_empty(listname.."contents")==true then + if player:get_inventory():is_empty(listname.."contents") then return stack:get_count() else return 0 |