Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get rXRCh3Bg RH
- --shell.run("RH t f b")
- local tArgs = { ... }
- local sInput, sOutput, sOverflow, nDelay = tArgs[1], tArgs[2], tArgs[3], tArgs[4]
- local filename = shell.getRunningProgram()
- local 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"
- else
- aSide = nil
- end
- return aSide
- end
- sInput = fixSide(sInput)
- sOutput = fixSide(sOutput)
- sOverflow = fixSide(sOverflow)
- if sInput == nil or sOutput == nil or sOverflow == nil then
- print( "Usage: " .. filename .. " <input side> <output side> <overflow side> [Delay Time] [slots]" )
- print( "Side values are Top, Bottom, Front, and None" )
- print( "The turtle will pull from the input side and push into the output side." )
- print( "None can be specified if the turtle is expected to deal with items moving on their own." )
- return
- end
- if nDelay ~= nil then
- nDelay = tonumber(nDelay)
- end
- if nDelay == nil then
- nDelay = 0.5
- end
- local 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"
- else
- aSide = "unknown (" .. aSide .. ")"
- end
- return aSide
- end
- local 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
- local 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
- local 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(n)
- flashSide("top")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rd" then
- turtle.select(n)
- flashSide("bottom")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rf" then
- turtle.select(n)
- flashSide("front")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rb" then
- turtle.select(n)
- flashSide("back")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rl" then
- turtle.select(n)
- flashSide("left")
- res = (turtle.getItemCount(slotNo) ~= 0)
- elseif sDir == "rf" then
- turtle.select(n)
- flashSide("right")
- res = (turtle.getItemCount(slotNo) ~= 0)
- end
- return res
- end
- local function unloadSlot(slotNo, sDir)
- if sDir == "n" then
- return true
- end
- --print( "Unloading items..." )
- local res = false
- 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)
- end
- return res
- else
- return true
- end
- end
- local function emptySlot()
- for n2 = 1, 16 do
- if (turtle.getItemCount(n2) == 0) then
- return n2
- end
- end
- return 0
- end
- local function YesNoOther(aBool)
- if aBool == true then
- return "Yes"
- else
- return "No"
- end
- end
- local function unload()
- if sOutput == "n" then
- return
- end
- --print( "Unloading items..." )
- local res = false
- for n = 1, 16 do
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) > 0) then
- turtle.select(n)
- if unloadSlot(n, sOutput) == false then
- --the router is full, we have to pull the item out and ditch it.
- print("Router 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
- local function load()
- if sInput == "n" then
- return
- end
- --print( "Loading items..." )
- turtle.select(1)
- for n = 2, 15 do
- --unloaded = unloaded + turtle.getItemCount(n)
- if (turtle.getItemCount(n) == 0) 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
- print( "Transposing from " .. displaySide(sInput) .. " to " .. displaySide(sOutput) .. " with a delay of " .. nDelay .. " seconds and sending overflow items to " .. displaySide(sOverflow) .. "." )
- while true do
- load()
- unload()
- sleep(nDelay)
- end
Advertisement
Add Comment
Please, Sign In to add comment