From c9ef53904ad529d9f0c7d8ff9a431d2beeaa4a22 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 12 Nov 2016 21:51:32 +0100 Subject: [PATCH] Try to fix mahmutelmas06's reported bug --- init.lua | 106 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/init.lua b/init.lua index b9d4898..16828cf 100644 --- a/init.lua +++ b/init.lua @@ -59,40 +59,42 @@ minetest.register_on_joinplayer(function(player) if mod_ui or mod_bags then inventory_icon.hudids[name].bags = {} local bags_inv = minetest.get_inventory({type = "detached", name = name.."_bags"}) - for i=1,4 do - local bag = bags_inv:get_stack("bag"..i, 1) - local scale, text, icon - if bag:is_empty() then - scale = { x = 0, y = 0 } - text = "" - icon = "bags_small.png^[resize:32x32" - else - scale = { x = 1, y = 1 } - local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents") - text = S("@1/@2", occupied, size) - icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image) - if occupied >= size then - icon = icon .. "^" .. inventory_icon.COLORIZE_STRING + if bags_inv then + for i=1,4 do + local bag = bags_inv:get_stack("bag"..i, 1) + local scale, text, icon + if bag:is_empty() then + scale = { x = 0, y = 0 } + text = "" + icon = "bags_small.png^[resize:32x32" + else + scale = { x = 1, y = 1 } + local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents") + text = S("@1/@2", occupied, size) + icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image) + if occupied >= size then + icon = icon .. "^" .. inventory_icon.COLORIZE_STRING + end end + inventory_icon.hudids[name].bags[i] = {} + inventory_icon.hudids[name].bags[i].icon = player:hud_add({ + hud_elem_type = "image", + position = {x=1,y=1}, + scale = scale, + size = { x=32, y=32 }, + offset = {x=-36,y=-32 -40*i}, + text = icon, + }) + inventory_icon.hudids[name].bags[i].text = player:hud_add({ + hud_elem_type = "text", + position = {x=1,y=1}, + scale = scale, + offset = {x=-36,y=-20 -40*i}, + alignment = {x=0,y=0}, + number = 0xFFFFFF, + text = text, + }) end - inventory_icon.hudids[name].bags[i] = {} - inventory_icon.hudids[name].bags[i].icon = player:hud_add({ - hud_elem_type = "image", - position = {x=1,y=1}, - scale = scale, - size = { x=32, y=32 }, - offset = {x=-36,y=-32 -40*i}, - text = icon, - }) - inventory_icon.hudids[name].bags[i].text = player:hud_add({ - hud_elem_type = "text", - position = {x=1,y=1}, - scale = scale, - offset = {x=-36,y=-20 -40*i}, - alignment = {x=0,y=0}, - number = 0xFFFFFF, - text = text, - }) end end end) @@ -119,27 +121,29 @@ minetest.register_globalstep(function(dtime) if mod_ui or mod_bags then local bags_inv = minetest.get_inventory({type = "detached", name = playername.."_bags"}) - for i=1,4 do - local bag = bags_inv:get_stack("bag"..i, 1) - local scale, text, icon - if bag:is_empty() then - scale = { x = 0, y = 0 } - text = "" - icon = "bags_small.png^[resize:32x32" - else - scale = { x = 1, y = 1 } - local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents") - text = S("@1/@2", occupied, size) - icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image) - if occupied >= size then - icon = icon .. "^" .. inventory_icon.COLORIZE_STRING + if bags_inv then + for i=1,4 do + local bag = bags_inv:get_stack("bag"..i, 1) + local scale, text, icon + if bag:is_empty() then + scale = { x = 0, y = 0 } + text = "" + icon = "bags_small.png^[resize:32x32" + else + scale = { x = 1, y = 1 } + local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents") + text = S("@1/@2", occupied, size) + icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image) + if occupied >= size then + icon = icon .. "^" .. inventory_icon.COLORIZE_STRING + end end - end - player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon) - player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "scale", scale) + player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon) + player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "scale", scale) - player:hud_change(inventory_icon.hudids[playername].bags[i].text, "text", text) - player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale) + player:hud_change(inventory_icon.hudids[playername].bags[i].text, "text", text) + player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale) + end end end end