Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Turtle compactInventory
- --by SukaiPoppuGo
- --Stack items in first slots of an inventory
- --Example #1:
- -- os.loadAPI("APIFileName.lua")
- -- APIFileName.compactInventory()
- --
- --Example #2: (compact stacks, but do not moving items near the first slot)
- -- os.loadAPI("APIFileName.lua")
- -- APIFileName.compactInventory(true)
- --
- local function _select(slot)
- if slot ~= turtle.getSelectedSlot() then
- turtle.select(slot)
- end
- end
- function compactInventory(finish)
- finish = finish or false
- for slot=16,2,-1 do
- if turtle.getItemCount(slot) > 0 then
- for toSlot=1,16 do
- --print(slot, "->", toSlot)
- if slot > toSlot
- and turtle.getItemSpace(toSlot) > 0
- and (_select(slot) or true)
- and (turtle.compareTo(toSlot) or turtle.getItemCount(toSlot) == 0)
- and turtle.transferTo(toSlot)
- and turtle.getItemCount(slot) == 0 then
- break
- end
- end
- end
- end
- if not finish then
- compactInventory(true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement