Advertisement
Danovac

[CC] Turtle Quarry Program

Jan 31st, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.69 KB | None | 0 0
  1. -- quarry program
  2.  
  3. ztarget = 2 -- 2 for flat bedrock, 6 for normal
  4. invlimit = 8
  5. --default safe values
  6. x = 4
  7. y = 3
  8. z = 15
  9. maxheight = 15
  10. zhome = 15
  11. lr = "left"
  12. ---------------------
  13. fuellimit = 2000
  14. d = 0
  15. itemcount = 0
  16.  
  17. function up()
  18.   u = false
  19.   while u == false do
  20.     dig("up")
  21.     u = turtle.up()
  22.     z = z + 1
  23.   end
  24. end
  25.  
  26. function forward()
  27.   u = false
  28.   while u == false do
  29.     dig("forward")
  30.     u = turtle.forward()
  31.   end
  32. end
  33.  
  34. function down()
  35.   u = false
  36.   while u == false do
  37.     dig("down")
  38.     u = turtle.down()
  39.     z = z - 1
  40.   end
  41. end
  42.  
  43. function home()
  44.   for zc = z,zhome-1 do
  45.     up()
  46.   end
  47.   turtle.turnRight()
  48.   turtle.turnRight()
  49.   for i = 1,12 do
  50.     itemcount = itemcount + turtle.getItemCount(i)
  51.     turtle.select(i)
  52.     turtle.drop()
  53.   end
  54.   turtle.select(14)
  55.   turtle.placeDown()
  56.   turtle.slect(1)
  57.   print("Quarry complete")
  58.   print("Mined a total of "..itemcount.." items")
  59.   print("don't fall down the hole!")
  60.   return
  61. end
  62.  
  63. function inventorycheck()
  64.   invfull = false
  65.     for invslot = invlimit,12 do
  66.       turtle.select(invslot)
  67.       if turtle.getItemCount(invslot) > 0 then
  68.       invfull = true
  69.       else
  70.       end
  71.     end
  72.   if invfull == true then
  73.     print("Inventory getting full, returning to unload")
  74.     deposit()
  75.   else
  76.   end
  77. end
  78.  
  79. function deposit()
  80.   zreturn = z
  81.   for zd = z,zhome-1 do
  82.     up()
  83.   end
  84.   turtle.turnRight()
  85.   turtle.turnRight()
  86.   for drop = 1,12 do
  87.     itemcount = itemcount + turtle.getItemCount(drop)
  88.     turtle.select(drop)
  89.     turtle.drop()
  90.   end
  91.     print("Current items gathered: "..itemcount)
  92.   fuelcheck()
  93.   hold()
  94.   turtle.turnRight()
  95.   turtle.turnRight()
  96.   for zd = zreturn,zhome-1 do
  97.     down()
  98.   end
  99. end
  100.  
  101. function fuelcheck()
  102.   while turtle.getFuelLevel() < fuellimit do
  103.     turtle.select(1)
  104.     turtle.suckUp()
  105.     turtle.refuel()
  106.   end
  107. end
  108.  
  109. function hold()
  110.   redstonewait = true
  111.   print("Checking Torch Signal")
  112.   while redstonewait == true do
  113.     sleep(2)
  114.     if redstone.getInput("left") then
  115.       redstonewait = true
  116.       print("Waiting On Torch")
  117.       sleep(15)
  118.     elseif redstone.getInput("right") then
  119.       redstonewait = true
  120.       print("Waiting On Torch")
  121.       sleep(15)
  122.     else
  123.       redstonewait = false
  124.     end
  125.   end
  126. end
  127.  
  128. function layerTurn()
  129.   throwTrash()
  130.   if lastline == false then
  131.     if lr == "left" then
  132.       turtle.turnLeft()
  133.     else
  134.       turtle.turnRight()
  135.     end
  136.     forward()
  137.     if lr == "left" then
  138.       turtle.turnLeft()
  139.       lr = "right"
  140.     else
  141.       turtle.turnRight()
  142.       lr = "left"
  143.     end
  144.   else
  145.     layerReturn()
  146.   end
  147. end
  148.  
  149. function layerReturn()
  150.   if xstart == false then
  151.     if lr == "left" then
  152.       turtle.turnLeft()
  153.       turtle.turnLeft()
  154.     else
  155.       turtle.turnRight()
  156.       turtle.turnRight()
  157.     end
  158.     for i = 1,x-1 do
  159.       forward()
  160.     end
  161.   else
  162.     if lr == "left" then
  163.       lr = "right"
  164.     else
  165.       lr = "left"
  166.     end
  167.   end
  168.   if lr == "left" then
  169.     turtle.turnLeft()
  170.   else
  171.     turtle.turnRight()
  172.   end
  173.   for i = 1,y-1 do
  174.     forward()
  175.   end
  176.   if lr == "left" then
  177.     turtle.turnLeft()
  178.   else
  179.     turtle.turnRight()
  180.   end
  181. end
  182.  
  183. function dig(dir)
  184.   turtle.select(1)
  185.   if dir == "forward" then
  186.     turtle.dig()
  187.   elseif dir == "up" then
  188.     turtle.digUp()
  189.   elseif dir == "down" then
  190.     turtle.digDown()
  191.   else
  192.   end
  193. end
  194.  
  195. function throwTrash()
  196.   for stack = 1,12 do
  197.     junk = false
  198.     turtle.select(stack)
  199.     for trash = 13,16 do
  200.       if turtle.compareTo(trash) == true then
  201.         junk = true
  202.       else
  203.       end
  204.     end
  205.     if junk == true then
  206.       turtle.drop()
  207.     else
  208.     end
  209.   end
  210. end
  211.  
  212. function blockTestUp()
  213.   mineup = true
  214.   for i = 13,16 do
  215.     turtle.select(i)
  216.     if turtle.compareUp() == true then
  217.       mineup = false
  218.     else
  219.     end
  220.   end
  221. end
  222.  
  223. function blockTestDown()
  224.   minedown = true
  225.   for i = 13,16 do
  226.     turtle.select(i)
  227.     if turtle.compareDown() == true then
  228.       minedown = false
  229.     else
  230.     end
  231.   end
  232. end
  233.  
  234. function mine()
  235.   blockTestUp()
  236.   blockTestDown()
  237.   if mineup == true then
  238.     dig("up")
  239.   else
  240.   end
  241.   if minedown == true then
  242.     dig("down")
  243.   else
  244.   end
  245. end
  246.  
  247. function clean()
  248.   term.clear()
  249.   term.setCursorPos(1,1)
  250. end
  251.  
  252. function minelayer()
  253.   xstart = true
  254.   lastline = false
  255.   mine()
  256.   for yc = 1,y do
  257.     for xc = 1,x-1 do
  258.       forward()
  259.       mine()
  260.     end
  261.     if xstart == true then
  262.       xstart = false
  263.     else
  264.       xstart = true
  265.     end
  266.     if yc == y then
  267.       lastline = true
  268.     end
  269.     layerTurn()
  270.     mine()
  271.   end
  272. end
  273.  
  274. function maxcheck()
  275.   if zcurrent >= maxheight then
  276.     home()
  277.   else
  278.   end
  279. end
  280.  
  281. function layermove()
  282.   for zc = ztarget,zhome-3,3 do
  283.     print("Mining layer: "..zc)
  284.     zcurrent = zc
  285.     minelayer()
  286.     maxcheck()
  287.     inventorycheck()
  288.     for i = 1,3 do
  289.       up()
  290.     end
  291.   end
  292. end
  293.  
  294. function initiate()
  295.   z = zhome
  296.   for zi = ztarget,z-1 do
  297.     down()
  298.   end
  299. end
  300.  
  301. -- Program
  302.  
  303. clean()
  304. print("QUARRY PROGRAM")
  305. print("")
  306. print("Current Height: ")
  307. print("Lowest Height: ")
  308. print("Maximum Height: ")
  309. print("Length: ")
  310. print("Width: ")
  311. print("First turn: ")
  312.  
  313. term.setCursorPos(17,3)
  314.  zhome = tonumber(read())
  315. term.setCursorPos(17,4)
  316.  ztarget = tonumber(read())
  317. term.setCursorPos(17,5)
  318.  maxheight = tonumber(read())
  319. term.setCursorPos(17,6)
  320.  x = tonumber(read())
  321. term.setCursorPos(17,7)
  322.  y = tonumber(read())
  323. term.setCursorPos(17,8)
  324.  lr = read()
  325.  
  326. clean()
  327. print("Digging to bedrock")
  328. initiate()
  329. print("Mining first layer")
  330. layermove()
  331. print("Returning home")
  332. home()
  333.  
  334. --read info
  335. --initiate
  336. --layermove
  337.   --layermine
  338.   --inventorycheck
  339.     --deposit
  340.       --fuelcheck
  341. --home
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement