Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - slotsFinished = {}
 - for fillIndex = 1, 16 do
 - slotsFinished[fillIndex] = false
 - end
 - function compactInv()
 - for checkSlot = 1, 16 do
 - if turtle.getItemCount(checkSlot) > 0 then
 - turtle.select(checkSlot)
 - for testSlot = checkSlot, 16 do
 - if turtle.compareTo(testSlot) then
 - turtle.select(testSlot)
 - turtle.transferTo(checkSlot, turtle.getItemCount(testSlot))
 - turtle.select(checkSlot)
 - end
 - end
 - end
 - end
 - end
 - function cleanInv(startSlot, stopSlot, stepSize)
 - if stepSize > 0 then
 - stepSize = 1
 - endOfInv = 1
 - elseif stepSize < 0 then
 - stepSize = -1
 - endOfInv = 16
 - else
 - stepSize = -1
 - endOfInv = 16
 - end
 - if startSlot > 16 then startSlot = 16 end
 - if startSlot < 1 then startSlot = 1 end
 - if stopSlot > 16 then stopSlot = 16 end
 - if stopSlot < 1 then stopSlot = 1 end
 - for checkSlot = startSlot, stopSlot, stepSize do
 - while turtle.getItemCount(checkSlot) > 0 do
 - moveSlot = endOfInv
 - turtle.select(checkSlot)
 - while not turtle.transferTo(moveSlot, turtle.getItemCount(checkSlot)) do
 - moveSlot = moveSlot + stepSize
 - end
 - if moveSlot == checkSlot then
 - break
 - end
 - end
 - end
 - end
 - function checkIfFull() --returns true if the inventory is full and needs to dropUp() the first slot to free a slot
 - if turtle.getItemCount(1) > 0 then
 - return true
 - else
 - return false
 - end
 - end
 - function getNextUnsorted()
 - for checkIndex = 1, 16 do
 - if not slotsFinished[checkIndex] then
 - return checkIndex -- returns the first unsorted slot
 - -- break -- should be unnecessary, but there just in case
 - end
 - end
 - return 0
 - end
 - function sortInv()
 - local droppedItem = false
 - if checkIfFull() then
 - turtle.select(1)
 - turtle.dropUp()
 - droppedItem = true
 - end
 - sortsMade = 0
 - while sortsMade <= 16 do
 - turtle.select(16)
 - openSlot = getNextUnsorted()
 - turtle.transferTo(openSlot, turtle.getItemCount(16))
 - slotsFinished[openSlot] = true
 - cleanInv(16, getNextUnsorted(), -1)
 - sortsMade = sortsMade + 1
 - for checkSlot = 16, openSlot, -1 do
 - if checkSlot == (getNextUnsorted()) then
 - break
 - end
 - turtle.select(openSlot)
 - if turtle.compareTo(checkSlot) then
 - turtle.select(checkSlot)
 - while turtle.getItemCount(checkSlot) > 0 do
 - moveSlot = openSlot + 1
 - while not turtle.transferTo(moveSlot, turtle.getItemCount(checkSlot)) do
 - moveSlot = moveSlot + 1
 - end
 - end
 - slotsFinished[moveSlot] = true
 - cleanInv(checkSlot, getNextUnsorted(), -1)
 - sortsMade = sortsMade + 1
 - checkSlot = 16
 - end
 - end
 - end
 - if droppedItem then
 - turtle.suckUp()
 - end
 - end
 - compactInv()
 - cleanInv(16, 1, -1)
 - sortInv()
 - cleanInv(1, 16, 1)
 - turtle.select(1)
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment