Advertisement
OldDragon2A

transfer (in-place)

Dec 16th, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- turtle stack transfer
  2. -- moves blocks from one side to the other (up, forward, down)
  3.  
  4. local source   = "up"
  5. local target   = "forward"
  6. local overflow = ""
  7. local slot     = 1
  8.  
  9. function getSuck(dir)
  10.   if     dir == "up"      then return turtle.suckUp
  11.   elseif dir == "forward" then return turtle.suck
  12.   elseif dir == "down"    then return turtle.suckDown
  13.   else
  14.     print("Unknown Direction: " .. dir)
  15.     exit()
  16.   end
  17. end
  18. function getDrop(dir)
  19.   if     dir == "up"      then return turtle.dropUp
  20.   elseif dir == "forward" then return turtle.drop
  21.   elseif dir == "down"    then return turtle.dropDown
  22.   else
  23.     print("Unknown Direction: " .. dir)
  24.     exit()
  25.   end
  26. end
  27.  
  28. sourceSuck = getSuck(source)
  29. targetDrop = getDrop(target)
  30. if overflow ~= "" then
  31.   overflowSuck = getSuck(overflow)
  32.   overflowDrop = getDrop(overflow)
  33.   overflow = true
  34. else
  35.   overflow = false
  36. end
  37.  
  38. turtle.select(slot)
  39. while true do
  40.   if turtle.getItemCount(slot) > 0 then targetDrop() end
  41.   if overflow and turtle.getItemCount(slot) > 0 then overflowDrop() end
  42.   if turtle.getItemCount(slot) == 0 then sourceSuck() end
  43.   if overflow and turtle.getItemCount(slot) == 0 then overflowSuck() end
  44.   sleep(0)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement