mirror of
https://github.com/minetest-mods/technic.git
synced 2025-03-23 21:00:28 +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 m = st:get_metadata()
|
||||||
local k = string.format("%s %05d %s", n, w, m)
|
local k = string.format("%s %05d %s", n, w, m)
|
||||||
if not typecnt[k] then
|
if not typecnt[k] then
|
||||||
typecnt[k] = {
|
typecnt[k] = st:to_string()
|
||||||
name = n,
|
|
||||||
wear = w,
|
|
||||||
metadata = m,
|
|
||||||
stack_max = st:get_stack_max(),
|
|
||||||
count = 0,
|
|
||||||
}
|
|
||||||
table.insert(typekeys, k)
|
table.insert(typekeys, k)
|
||||||
end
|
end
|
||||||
typecnt[k].count = typecnt[k].count + st:get_count()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(typekeys)
|
table.sort(typekeys)
|
||||||
local outlist = {}
|
local outlist = {}
|
||||||
for _, k in ipairs(typekeys) do
|
for _, k in ipairs(typekeys) do
|
||||||
local tc = typecnt[k]
|
table.insert(outlist, ItemStack(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
|
|
||||||
end
|
end
|
||||||
if #outlist > #inlist then return end
|
if #outlist > #inlist then return end
|
||||||
while #outlist < #inlist do
|
while #outlist < #inlist do
|
||||||
@ -305,7 +288,7 @@ function technic.chests:definition(name, data)
|
|||||||
on_receive_fields = get_receive_fields(name, data),
|
on_receive_fields = get_receive_fields(name, data),
|
||||||
on_metadata_inventory_move = self.on_inv_move,
|
on_metadata_inventory_move = self.on_inv_move,
|
||||||
on_metadata_inventory_put = self.on_inv_put,
|
on_metadata_inventory_put = self.on_inv_put,
|
||||||
on_metadata_inventory_take = self.on_inv_take,
|
on_metadata_inventory_take = self.on_inv_take,
|
||||||
on_blast = function(pos)
|
on_blast = function(pos)
|
||||||
local drops = {}
|
local drops = {}
|
||||||
default.get_inventory_drops(pos, "main", drops)
|
default.get_inventory_drops(pos, "main", drops)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user