Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- error("Requires turtle api")
- end
- function fixSide(aSide)
- if aSide == nil then
- aSide = ""
- end
- aSide = string.lower(aSide)
- if aSide == "top" or aSide == "t" or aSide == "up" or aSide == "u"then
- aSide = "t"
- elseif aSide == "front" or aSide == "f" then
- aSide = "f"
- elseif aSide == "bottom" or aSide == "b" or aSide == "down" or aSide == "d" then
- aSide = "b"
- elseif aSide == "none" or aSide == "n" then
- aSide = "n"
- elseif aSide == "rtop" or aSide == "rt" or aSide == "rup" or aSide == "ru"then
- aSide = "rt"
- elseif aSide == "rfront" or aSide == "rf" then
- aSide = "rf"
- elseif aSide == "rbottom" or aSide == "rb" or aSide == "rdown" or aSide == "rd" then
- aSide = "rd"
- elseif aSide == "rright" or aSide == "rr" then
- aSide = "rr"
- elseif aSide == "rleft" or aSide == "rl" then
- aSide = "rl"
- elseif aSide == "rback" or aSide == "rbk" then
- aSide = "rb"
- --attack options
- elseif aSide == "atop" or aSide == "at" or aSide == "aup" or aSide == "au"then
- aSide = "at"
- elseif aSide == "afront" or aSide == "af" then
- aSide = "af"
- elseif aSide == "abottom" or aSide == "ab" or aSide == "adown" or aSide == "ad" then
- aSide = "ad"
- --dig options
- elseif aSide == "dtop" or aSide == "dt" or aSide == "dup" or aSide == "du"then
- aSide = "dt"
- elseif aSide == "dfront" or aSide == "df" then
- aSide = "df"
- elseif aSide == "dbottom" or aSide == "db" or aSide == "ddown" or aSide == "dd" then
- aSide = "dd"
- --place options
- elseif aSide == "ptop" or aSide == "pt" or aSide == "pup" or aSide == "pu"then
- aSide = "pt"
- elseif aSide == "pfront" or aSide == "pf" then
- aSide = "pf"
- elseif aSide == "pbottom" or aSide == "pb" or aSide == "pdown" or aSide == "pd" then
- aSide = "pd"
- --craft options
- elseif aSide == "ctop" or aSide == "ct" or aSide == "cup" or aSide == "cu"then
- aSide = "ct"
- elseif aSide == "cfront" or aSide == "cf" then
- aSide = "cf"
- elseif aSide == "cbottom" or aSide == "cb" or aSide == "cdown" or aSide == "cd" then
- aSide = "cd"
- else
- aSide = nil
- end
- return aSide
- end
- function displaySide(aSide)
- if aSide == nil then
- aSide = ""
- end
- aSide = string.lower(aSide)
- if aSide == "t" then
- aSide = "top"
- elseif aSide == "f" then
- aSide = "front"
- elseif aSide == "b" then
- aSide = "bottom"
- elseif aSide == "n" then
- aSide = "none"
- elseif aSide == "rt" then
- aSide = "redstone pulse top"
- elseif aSide == "rf" then
- aSide = "redstone pulse front"
- elseif aSide == "rd" then
- aSide = "redstone pulse down"
- elseif aSide == "rr" then
- aSide = "redstone pulse right"
- elseif aSide == "rl" then
- aSide = "redstone pulse left"
- elseif aSide == "rb" then
- aSide = "redstone pulse back"
- elseif aSide == "pt" then
- aSide = "place top"
- elseif aSide == "pf" then
- aSide = "place front"
- elseif aSide == "pd" then
- aSide = "place down"
- elseif aSide == "dt" then
- aSide = "dig top"
- elseif aSide == "df" then
- aSide = "dig front"
- elseif aSide == "dd" then
- aSide = "dig down"
- elseif aSide == "ct" then
- aSide = "craft top"
- elseif aSide == "cf" then
- aSide = "craft front"
- elseif aSide == "cd" then
- aSide = "craft down"
- else
- aSide = "unknown (" .. aSide .. ")"
- end
- return aSide
- end
- function isEmpty()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if nCount == 0 then
- --print( "No more Items to drop." )
- return true
- end
- return false
- end
- function flashSide(aSide)
- --print("Flash " .. aSide .. " On ")
- redstone.setOutput(aSide, true)
- sleep(0.2)
- --print("Flash " .. aSide .. " Off ")
- redstone.setOutput(aSide, false)
- sleep(0.2)
- end
- function loadSlot(slotNo, sDir)
- if sDir == "n" then
- return true
- end
- if sDir == "t" then
- res = turtle.suckUp()
- elseif sDir == "f" then
- res = turtle.suck()
- elseif sDir == "b" then
- res = turtle.suckDown()
- elseif sDir == "rt" then
- turtle.select(slotNo)
- flashSide("top")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rd" then
- turtle.select(slotNo)
- flashSide("bottom")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rf" then
- turtle.select(slotNo)
- flashSide("front")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rb" then
- turtle.select(slotNo)
- flashSide("back")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rl" then
- turtle.select(slotNo)
- flashSide("left")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rf" then
- turtle.select(slotNo)
- flashSide("right")
- res = (turtle.getItemCount(slotNo) ~= 0)
- --Attack Options
- elseif sDir == "at" then
- turtle.select(slotNo)
- res = turtle.attackUp()
- elseif sDir == "ad" then
- turtle.select(slotNo)
- res = turtle.attackDown()
- elseif sDir == "af" then
- turtle.select(slotNo)
- res = turtle.attack()
- --Dig Options
- elseif sDir == "dt" then
- turtle.select(slotNo)
- res = turtle.digUp()
- elseif sDir == "dd" then
- turtle.select(slotNo)
- res = turtle.digDown()
- elseif sDir == "df" then
- turtle.select(slotNo)
- res = turtle.dig()
- elseif sDir == "cf" or sDir == "ct" or sDir == "cd" then
- turtle.select(slotNo)
- local nCount = turtle.getItemCount(slotNo)
- --print( "Slot " .. slotNo .. " has " .. nCount .. " items." )
- if nCount == 1 and slotNo ~= 4 then
- if sDir == "ct" then
- res = turtle.suckUp(1)
- elseif sDir == "cf" then
- res = turtle.suck(1)
- elseif sDir == "cd" then
- res = turtle.suckDown(1)
- end
- --print( "Sucked: " .. res)
- end
- end
- return res
- end
- function unloadSlot(slotNo, sDir)
- local res
- if sDir == "n" then
- return true
- end
- --print( "Unloading items..." )
- local res = false
- if slotNo == 4 and (sDir == "cf" or sDir == "ct" or sDir == "cd" ) then
- local good = true
- --print( "Crafting Slot: " .. turtle.getItemCount(slotNo))
- if (turtle.getItemCount(slotNo) == 0) then
- for rowI = 0, 2 do
- for colI = 1,3 do
- if (turtle.getItemCount(rowI * 4 + colI) == 1) then
- good = false
- end
- end
- end
- --print( "Ready to craft: " .. good)
- if good then
- turtle.select(slotNo)
- turtle.craft(1)
- end
- end
- if sDir == "ct" then
- res = turtle.dropUp()
- elseif sDir == "cf" then
- res = turtle.drop()
- elseif sDir == "cd" then
- res = turtle.dropDown()
- end
- return res
- elseif (sDir == "cf" or sDir == "ct" or sDir == "cd" ) then
- return true
- end
- if (turtle.getItemCount(slotNo) > 0) then
- turtle.select(slotNo)
- if sDir == "t" then
- res = turtle.dropUp()
- elseif sDir == "f" then
- res = turtle.drop()
- elseif sDir == "b" then
- res = turtle.dropDown()
- elseif sDir == "rt" then
- flashSide("top")
- res = (turtle.getItemCount(slotNo) == 0)
- elseif sDir == "rd" then
- flashSide("bottom")
- res = (turtle.getItemCount(slotNo) == 0)
- elseif sDir == "rf" then
- flashSide("front")
- res = (turtle.getItemCount(slotNo) == 0)
- elseif sDir == "rb" then
- flashSide("back")
- res = (turtle.getItemCount(slotNo) == 0)
- elseif sDir == "rl" then
- flashSide("left")
- res = (turtle.getItemCount(slotNo) == 0)
- elseif sDir == "rf" then
- flashSide("right")
- res = (turtle.getItemCount(slotNo) == 0)
- --Place Options
- elseif sDir == "pt"then
- res = turtle.placeUp()
- elseif sDir == "pd" then
- res = turtle.placeDown()
- elseif sDir == "pf" then
- res = turtle.place()
- end
- return res
- else
- return true
- end
- end
- function readSide(sDir)
- if sDir == "n" then
- return false
- end
- if sDir == "rt" or sDir == "t" or sDir == "ct" then
- res = redstone.getInput("top")
- elseif sDir == "rd" or sDir == "b" or sDir == "cd" then
- res = redstone.getInput("bottom")
- elseif sDir == "rf" or sDir == "f" or sDir == "cf" then
- res = redstone.getInput("front")
- elseif sDir == "rb" then
- res = redstone.getInput("back")
- elseif sDir == "rl" then
- res = redstone.getInput("left")
- elseif sDir == "rf" then
- res = redstone.getInput("right")
- --Attack Options
- elseif sDir == "at" then
- res = turtle.detectUp() ~= true
- elseif sDir == "ad" then
- res = turtle.detectDown() ~= true
- elseif sDir == "af" then
- res = turtle.detect() ~= true
- --Dig Options
- elseif sDir == "dt" then
- res = turtle.detectUp()
- elseif sDir == "dd" then
- res = turtle.detectDown()
- elseif sDir == "df" then
- res = turtle.detect()
- end
- return res
- end
- function emptySlot()
- local n2
- for n2 = 1, 16 do
- if (turtle.getItemCount(n2) == 0) then
- return n2
- end
- end
- return 0
- end
- function unload(sOutput, sOverflow)
- if sOutput == "n" then
- return
- end
- if sOverflow == nil then
- sOverflow = "n"
- end
- --print( "Unloading items..." )
- local res = false
- for n = 1, 16 do
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) > 0) or sOutput == "cf" or sOutput == "ct" or sOutput == "cd" then
- turtle.select(n)
- if unloadSlot(n, sOutput) == false and sOverflow ~= "n" then
- --the router is full, we have to pull the item out and ditch it.
- print("Destination Stuffed")
- local cacheSlot = emptySlot()
- print("Empty Slot at: " .. cacheSlot)
- if cacheSlot > 0 then
- turtle.select(cacheSlot)
- res = loadSlot(cacheSlot, sOutput)
- print("Pulling result: " .. YesNoOther(res))
- res = unloadSlot(cacheSlot, sOverflow)
- print("Overflow Output result: " .. YesNoOther(res))
- res = unloadSlot(n, sOutput)
- print("Retry result: " .. YesNoOther(res))
- end
- end
- sleep(0.2)
- end
- end
- end
- function load(sInput, minSlot, maxSlot)
- if sInput == "n" then
- return
- end
- if minSlot == nil then
- minSlot = 1
- end
- if maxSlot == nil then
- maxSlot = 15
- end
- --print( "Loading items..." )
- turtle.select(1)
- local n, res
- for n = minSlot, maxSlot do
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) == 0) or sInput == "cf" or sInput == "ct" or sInput == "cd" then
- res = loadSlot(n, sInput)
- if res == false then
- --print( "No more Items to get." )
- return false
- end
- --sleep(60)
- end
- end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment