Advertisement
Guest User

TurtleFiller

a guest
Apr 1st, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1.  
  2. -- Filler --
  3.  
  4. -- Refill Product Chest in Slot #1
  5. -- Fuel Chest in Slot #2
  6.  
  7.  
  8.  
  9.  
  10.  
  11. -- Program Variables --
  12. local tH = 0
  13. local cFail = 0
  14. local isHeadingOut = true
  15. local numRunsRight = 0
  16. local slotNum = 3
  17. local chest = 1
  18. local fuel = 2
  19. local swordHand = "left"
  20. local pickHand = "right"
  21. local failCheck = 7
  22. local set = 3
  23.  
  24. -- Base Functions Expanded --
  25. function tA() turtle.attack(swordHand) end
  26. function tAU() turtle.attackUp(swordHand) end
  27. function tAD() turtle.attackDown(swordHand) end
  28. function slp() os.sleep(sL) end
  29. function tRound() turtle.turnLeft() turtle.turnLeft() end
  30. function mF()
  31.  if turtle.detect() then turtle.dig(pickHand) end
  32.  while not turtle.forward() do slp() turtle.dig(pickHand) tA() end
  33. end
  34. function mB()
  35.  while not turtle.back() do slp() tRound() turtle.dig(pickHand) tA() tRound() end
  36. end
  37. function mU()
  38.  if turtle.detectUp() then turtle.digUp(pickHand) end
  39.  while not turtle.up() do slp() turtle.digUp(pickHand) tAU() end
  40. end
  41. function mD()
  42.  if turtle.detectDown() then turtle.digDown(pickHand) end
  43.  while not turtle.down() do slp() turtle.digDown(pickHand) tAD() end
  44. end
  45. function tR() turtle.turnRight() end
  46. function tL() turtle.turnLeft() end
  47.  
  48. -- Functions Start --
  49.  
  50. function calcDown()
  51.  while cFail <= failCheck do
  52.   if turtle.down() then
  53.    tH = tH + 1
  54.    if cFail > 0 then cFail = 0 end
  55.   else
  56.    tAD()
  57.    cFail = cFail + 1
  58.   end
  59.  end
  60.  mU()
  61.  tH = tH - 1
  62. end
  63.  
  64. function refillBlocks()
  65.  turtle.select(chest)
  66.  turtle.placeUp()
  67.  for i = 3,16 do
  68.   turtle.select(i)
  69.   turtle.suckUp(64)
  70.  end
  71.  turtle.select(chest)
  72.  turtle.digUp(pickHand)
  73.  turtle.select(set)
  74. end
  75.  
  76. function refillFuel()
  77.  if turtle.getFuelLevel() < 10000 then
  78.   turtle.select(fuel)
  79.   turtle.placeUp()
  80.   while turtle.getFuelLevel() < 11000 do
  81.    turtle.suckUp(10)
  82.    shell.run("refuel","10")
  83.   end
  84.   turtle.select(fuel)
  85.   turtle.digUp()
  86.   turtle.select(set)
  87.  end
  88. end
  89.  
  90. function placeDown()
  91.  turtle.select(slotNum)
  92.  if turtle.getItemCount() == 0 then
  93.   slotNum = slotNum + 1
  94.   if slotNum <= 16 then
  95.    turtle.select(slotNum)
  96.   else
  97.    refillBlocks()
  98.    slotNum = set
  99.    turtle.select(slotNum)
  100.   end
  101.  end
  102.  turtle.placeDown()
  103. end
  104.  
  105. function placeRow()
  106.  for i = 1,16 do
  107.   placeDown()
  108.   if not (i == 16) then
  109.    mF()
  110.   end
  111.  end
  112. end
  113.  
  114. function endTurn()
  115.  if isHeadingOut then
  116.   isHeadingOut = not isHeadingOut
  117.   tR()
  118.   mF()
  119.   tR()
  120.  else
  121.   isHeadingOut = not isHeadingOut
  122.   if not (numRunsRight == 16) then
  123.    tL()
  124.    mF()
  125.    tL()
  126.   else
  127.    mU()
  128.    tR()
  129.    tH = tH - 1
  130.   end
  131.  end
  132. end
  133.  
  134. function loopFloor()
  135.  for i = 1,16 do
  136.   numRunsRight = i
  137.   placeRow()
  138.   endTurn()
  139.  end
  140. end
  141.  
  142. function runQuad()
  143.  while tH > 0 do
  144.   refillFuel()
  145.   loopFloor()
  146.  end
  147. end
  148.  
  149. -- Main Loop --
  150.  
  151. calcDown()
  152. runQuad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement