Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - --pastebin:VCNreRFK
 - --file:tsort
 - local t = turtle
 - local offset = 0
 - local sleepTime = 10
 - local function dropAt(pos)
 - for i = 1, pos + offset do
 - t.forward()
 - end
 - t.select(16)
 - local dropped = t.dropDown()
 - local curCount = t.getItemCount(pos)
 - if curCount > 1 then
 - t.select(pos)
 - t.dropDown(curCount - 1)
 - end
 - for i = 1, pos + offset do
 - t.back()
 - end
 - return dropped
 - end
 - local function pickItem()
 - t.select(16)
 - local current = t.getItemCount(16)
 - if current > 0 then
 - return true
 - end
 - for i = 1, 15 do
 - local slotCount = t.getItemCount(i)
 - if slotCount > 1 then
 - t.select(i)
 - t.transferTo(16, slotCount-1)
 - return true
 - end
 - end
 - return t.suckDown()
 - end
 - local function sortItem()
 - print("Sorting item")
 - local matchFound = false
 - local dropped = false
 - for i = 1, 15 do
 - if (t.compareTo(i)) then
 - matchFound = true
 - dropped = dropAt(i)
 - break
 - end
 - end
 - if (not matchFound) then
 - t.dropUp()
 - end
 - if (matchFound and not dropped) then
 - t.dropUp()
 - end
 - end
 - local function detectItems()
 - print("Detecting items...")
 - t.turnRight()
 - t.forward()
 - t.turnLeft()
 - t.forward()
 - t.down()
 - t.down()
 - t.turnLeft()
 - t.forward()
 - t.turnRight()
 - for i = 1, 15 do
 - t.select(i)
 - if t.getItemCount(i) == 0 then
 - t.suckUp()
 - end
 - if (i < 15) then
 - t.forward()
 - end
 - end
 - for i = 1, 14 do
 - t.back()
 - end
 - t.turnRight()
 - t.forward()
 - t.up()
 - t.up()
 - t.back()
 - t.turnLeft()
 - t.back()
 - print("Item detection complete.")
 - end
 - function main()
 - detectItems()
 - while (true) do
 - local hasItem = true
 - while (hasItem) do
 - local hasItem = pickItem()
 - if (hasItem) then
 - sortItem()
 - end
 - end
 - sleep(sleepTime)
 - end
 - end
 - main()
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment