Try to fix mahmutelmas06's reported bug

This commit is contained in:
Wuzzy 2016-11-12 21:51:32 +01:00
parent 42da48502e
commit c9ef53904a

106
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