Skip to content

Instantly share code, notes, and snippets.

@MEXAHOTABOP
Created January 17, 2019 19:52
Show Gist options
  • Save MEXAHOTABOP/704a4fdcc6229738e66d5dca3a3f7b0d to your computer and use it in GitHub Desktop.
Save MEXAHOTABOP/704a4fdcc6229738e66d5dca3a3f7b0d to your computer and use it in GitHub Desktop.
comp = require("component")
trans = comp.transposer
function sort_chest(side)
local chest_size = trans.getInventorySize(side)
for i = chest_size, 2, -1 do
local item = trans.getStackInSlot(side,i)
if item ~= nil and item.size < item.maxSize then
local target_count = item.size
for j = i - 1, 1, -1 do
local target_item = trans.getStackInSlot(side,j)
if target_item ~= nil and item.label == target_item.label and target_item.size < target_item.maxSize then
local to_drop = target_item.maxSize - target_item.size
if to_drop > target_count then to_drop = target_count end
trans.transferItem(side, side, to_drop,i, j)
target_count = target_count - to_drop
if target_count == 0 then break end
end
end
end
end
end
sort_chest(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment