Advertisement
Zac_McDonald

CC: Miner Filler

Oct 17th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- Turtle Program for digging and filling in tunnels
  2.  
  3. blocks = {1,1,1,2}
  4.  
  5. doBoth = false
  6. digging = false
  7. finished = false
  8. index = 1
  9.  
  10. function refuel ()
  11.     -- Refuel from the last slot if we are low
  12.     if turtle.getFuelLevel() < 10 then
  13.         i = turtle.getSelectedSlot()
  14.         turtle.select(16)
  15.         turtle.refuel()
  16.         turtle.select(i)
  17.     end
  18. end
  19.  
  20. -- Setup main variables based on user input
  21. function setup ()
  22.     print("Are we digging [dig], filling [fill], or both [both]?")
  23.     op = read()
  24.     responses = {["dig"] = true, ["fill"] = true, ["both"] = true}
  25.     if (responses[op] ~= true) then
  26.         print("Invalid response.")
  27.         return false
  28.     elseif (op == "dig") then
  29.         digging = true
  30.     elseif (op == "fill") then
  31.         digging = false
  32.         setupOffset()
  33.     elseif (op == "both") then
  34.         digging = true
  35.         doBoth = true
  36.         setupOffset()
  37.     end
  38.  
  39.     return true
  40. end
  41.  
  42. -- Setup for the offset variable
  43. function setupOffset ()
  44.     print("Enter offset in blocks list: ")
  45.     op = read()
  46.     current = tonumber(op)
  47. end
  48.  
  49. function main ()
  50.     refuel()
  51.  
  52.     if digging then
  53.         -- If we have reached an air block, finish digging phase
  54.         if (turtle.inspect() == false) then
  55.             digging = false
  56.             if not doBoth then
  57.                 finished = true
  58.             end
  59.             return
  60.         end
  61.  
  62.         turtle.dig()
  63.         turtle.forward()
  64.     else -- If Filling
  65.         if (turtle.back()) then
  66.             turtle.select(blocks[current])
  67.             turtle.place()
  68.  
  69.             current = (current % table.getn(blocks)) + 1
  70.         else -- Can't move back, finish fill phase
  71.             finished = true
  72.         end
  73.     end
  74. end
  75.  
  76. if (setup()) then
  77.     while (not finished) do
  78.         main ()
  79.     end
  80.  
  81.     print("Finished Operation")
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement