mirror of
https://github.com/minetest-mods/technic.git
synced 2025-02-14 03:00:23 +01:00
chests: fix sort_inventory function
This commit is contained in:
parent
a84b5f3b28
commit
6077f960c2
@ -137,32 +137,15 @@ local function sort_inventory(inv)
|
||||
local m = st:get_metadata()
|
||||
local k = string.format("%s %05d %s", n, w, m)
|
||||
if not typecnt[k] then
|
||||
typecnt[k] = {
|
||||
name = n,
|
||||
wear = w,
|
||||
metadata = m,
|
||||
stack_max = st:get_stack_max(),
|
||||
count = 0,
|
||||
}
|
||||
typecnt[k] = st:to_string()
|
||||
table.insert(typekeys, k)
|
||||
end
|
||||
typecnt[k].count = typecnt[k].count + st:get_count()
|
||||
end
|
||||
end
|
||||
table.sort(typekeys)
|
||||
local outlist = {}
|
||||
for _, k in ipairs(typekeys) do
|
||||
local tc = typecnt[k]
|
||||
while tc.count > 0 do
|
||||
local c = math.min(tc.count, tc.stack_max)
|
||||
table.insert(outlist, ItemStack({
|
||||
name = tc.name,
|
||||
wear = tc.wear,
|
||||
metadata = tc.metadata,
|
||||
count = c,
|
||||
}))
|
||||
tc.count = tc.count - c
|
||||
end
|
||||
table.insert(outlist, ItemStack(typecnt[k]))
|
||||
end
|
||||
if #outlist > #inlist then return end
|
||||
while #outlist < #inlist do
|
||||
|
Loading…
Reference in New Issue
Block a user