summaryrefslogtreecommitdiff
path: root/unified_inventory/bags.lua
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-08-11 18:39:55 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-08-11 18:39:55 -0400
commit92f49e3096dc37b9b802994d287c47dc7f583c24 (patch)
tree9480515a27630d8009dffb87de93124966fb1015 /unified_inventory/bags.lua
parentf9cae7314e08fbeeef509c5c6ca095822fec1747 (diff)
downloaddreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.gz
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.bz2
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.xz
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.zip
updated boost_cart, plantlife, castle, homedecor, fake_fire,
glooptest, quartz, unified_inventory, inbox, mesecons, and worldedit mods
Diffstat (limited to 'unified_inventory/bags.lua')
-rw-r--r--unified_inventory/bags.lua103
1 files changed, 65 insertions, 38 deletions
diff --git a/unified_inventory/bags.lua b/unified_inventory/bags.lua
index 3b86544..7e925db 100644
--- a/unified_inventory/bags.lua
+++ b/unified_inventory/bags.lua
@@ -4,16 +4,17 @@
-- License: GPLv3
local S = unified_inventory.gettext
+local F = unified_inventory.fgettext
unified_inventory.register_page("bags", {
get_formspec = function(player)
local player_name = player:get_player_name()
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
- formspec = formspec.."label[0,0;"..S("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.."label[0,0;"..F("Bags").."]"
+ formspec = formspec.."button[0,2;2,0.5;bag1;"..F("Bag 1").."]"
+ formspec = formspec.."button[2,2;2,0.5;bag2;"..F("Bag 2").."]"
+ formspec = formspec.."button[4,2;2,0.5;bag3;"..F("Bag 3").."]"
+ formspec = formspec.."button[6,2;2,0.5;bag4;"..F("Bag 4").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag1;0.5,1;1,1;]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag2;2.5,1;1,1;]"
@@ -36,7 +37,7 @@ unified_inventory.register_button("bags", {
local stack = player:get_inventory():get_stack("bag1", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
- formspec = formspec.."label[0,0;Bag 1]"
+ formspec = formspec.."label[0,0;"..F("Bag 1").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag1contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag1contents]"
@@ -57,7 +58,7 @@ unified_inventory.register_button("bags", {
local stack = player:get_inventory():get_stack("bag2", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
- formspec = formspec.."label[0,0;Bag 2]"
+ formspec = formspec.."label[0,0;"..F("Bag 2").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag2contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag2contents]"
@@ -78,7 +79,7 @@ unified_inventory.register_button("bags", {
local stack = player:get_inventory():get_stack("bag3", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
- formspec = formspec.."label[0,0;Bag 3]"
+ formspec = formspec.."label[0,0;"..F("Bag 3").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag3contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag3contents]"
@@ -99,7 +100,7 @@ unified_inventory.register_button("bags", {
local stack = player:get_inventory():get_stack("bag4", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
- formspec = formspec.."label[0,0;Bag 4]"
+ formspec = formspec.."label[0,0;"..F("Bag 4").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag4contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag4contents]"
@@ -144,11 +145,36 @@ minetest.register_on_joinplayer(function(player)
player:get_inventory():set_stack(listname, index, nil)
end,
allow_put = function(inv, listname, index, stack, player)
- if stack:get_definition().groups.bagslots then
- return 1
- else
- return 0
+ local new_slots = stack:get_definition().groups.bagslots
+ if new_slots then
+ local player_inv = player:get_inventory()
+ local old_slots = player_inv:get_size(listname.."contents")
+
+ if new_slots >= old_slots then
+ return 1
+ else
+ -- using a smaller bag, make sure it fits
+ local old_list = player_inv:get_list(listname.."contents")
+ local new_list = {}
+ local slots_used = 0
+ local use_new_list = false
+
+ for i, v in ipairs(old_list) do
+ if v and not v:is_empty() then
+ slots_used = slots_used + 1
+ use_new_list = i > new_slots
+ new_list[slots_used] = v
+ end
+ end
+ if new_slots >= slots_used then
+ if use_new_list then
+ player_inv:set_list(listname.."contents", new_list)
+ end
+ return 1
+ end
+ end
end
+ return 0
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname.."contents") then
@@ -189,30 +215,31 @@ minetest.register_tool("unified_inventory:bag_large", {
})
-- register bag crafts
-minetest.register_craft({
- output = "unified_inventory:bag_small",
- recipe = {
- {"", "farming:cotton", ""},
- {"group:wool", "group:wool", "group:wool"},
- {"group:wool", "group:wool", "group:wool"},
- },
-})
-
-minetest.register_craft({
- output = "unified_inventory:bag_medium",
- recipe = {
- {"", "", ""},
- {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
- {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
- },
-})
+if minetest.get_modpath("farming") ~= nil then
+ minetest.register_craft({
+ output = "unified_inventory:bag_small",
+ recipe = {
+ {"", "farming:cotton", ""},
+ {"group:wool", "group:wool", "group:wool"},
+ {"group:wool", "group:wool", "group:wool"},
+ },
+ })
-minetest.register_craft({
- output = "unified_inventory:bag_large",
- recipe = {
- {"", "", ""},
- {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
- {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
- },
-})
+ minetest.register_craft({
+ output = "unified_inventory:bag_medium",
+ recipe = {
+ {"", "", ""},
+ {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
+ {"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
+ },
+ })
+ minetest.register_craft({
+ output = "unified_inventory:bag_large",
+ recipe = {
+ {"", "", ""},
+ {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
+ {"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
+ },
+ })
+end