jcoutie

miner

Jan 21st, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. -- Tunnel Mining Turtle (with return)
  2. -- Mines, places torches, builds floor
  3. -- Variables
  4.  turtle.select(1)
  5.  local tArgs = { ... }
  6.  local togo = tonumber(tArgs[1])
  7.  togo = togo or 1
  8.  local torch = 0
  9.  local cobble = 0
  10.  term.clear()
  11.  term.setCursorPos(1,1)
  12.  -- print(os.getComputerLabel() .. " at your service!")
  13.  print()
  14.  print("Please place blocks as follows:")
  15.  print("Slot 1 - Fuel (coal or lava)")
  16.  print("Slot 2 - Torches (optional)")
  17.  print("Slot 3 - Cobble (optional)")
  18.  print()
  19.  print("Press [ENTER] when ready.")
  20.  read(input)
  21.  
  22. -- Starting Out
  23.  if turtle.getItemCount(1) < 1 then
  24.   print("No fuel! Abort!")
  25.   quit()
  26.  end
  27.  if turtle.getItemCount(2) > 0 then
  28.   torch = 1
  29.  end
  30.  if turtle.getItemCount(3) > 0 then
  31.   cobble = 1
  32.  end
  33.  local i = 0
  34. -- Functions
  35.  function tfuel(amount)
  36.   if turtle.getFuelLevel() < 16 then
  37.    turtle.select(1)
  38.    turtle.refuel(amount)
  39.   end
  40.  end
  41.      
  42.  function turnaround()
  43.   turtle.turnRight()
  44.   turtle.turnRight()
  45.  end
  46.  
  47.  function uandd()
  48.   if turtle.detectUp() then
  49.    repeat
  50.     turtle.digUp()
  51.     sleep(0.5)
  52.    until turtle.detectUp() == false
  53.   end
  54.   if turtle.detectDown() then
  55.    repeat
  56.     turtle.digDown()
  57.    until turtle.detectDown() == false
  58.   end
  59.   if cobble > 0 then
  60.    turtle.down()
  61.    if turtle.detectDown() == false then
  62.     turtle.select(3)
  63.     turtle.placeDown()
  64.     turtle.select(1)
  65.    end
  66.    turtle.up()
  67.   end
  68.  end
  69.      
  70.  function mydig()
  71.   tfuel(1)
  72.   if turtle.detect() then
  73.    repeat
  74.     turtle.dig()
  75.     sleep(0.5)
  76.    until turtle.detect() == false
  77.    turtle.forward()
  78.    uandd()
  79.   else
  80.    turtle.forward()
  81.    uandd()
  82.   end
  83.  end
  84.      
  85.  function discard()
  86.   turnaround()
  87.   for f = 1,i do
  88.    tfuel(1)
  89.    while turtle.forward() == false do
  90.     turtle.dig()
  91.    end
  92.   end
  93.   for x = 2+torch+cobble,16 do
  94.    turtle.select(x)
  95.    turtle.dropDown()
  96.   end
  97.   turnaround()
  98.   for f = 1,i do
  99.    tfuel(1)
  100.    while turtle.forward() == false do
  101.     turtle.dig()
  102.    end
  103.   end
  104.   turtle.select(1)
  105.  end
  106.  
  107. -- Main Loop
  108.  repeat
  109.   i = i + 1
  110.   term.clear()
  111.   term.setCursorPos(1,1)
  112.   local pct = (i/togo)*100
  113.   print("Mining "..i.." of "..togo.." ("..pct.."%)")
  114.   print("Fuel: "..turtle.getFuelLevel())
  115.   mydig()
  116.   turtle.turnRight()
  117.   mydig()
  118.   turnaround()
  119.   turtle.forward()
  120.   mydig()
  121.   turnaround()
  122.   turtle.forward()
  123.   turtle.turnLeft()
  124.   if togo >= 8 and torch > 0 then
  125.    if (i % 8 == 0) then
  126.     turtle.select(2)
  127.     turtle.placeDown()
  128.     turtle.select(1)
  129.    end
  130.   end
  131.   -- check to see if turtle is full
  132.   if turtle.getItemCount(16) > 0 then
  133.    discard()
  134.   end
  135.   turtle.select(1)
  136.  until i >= togo
  137.  --Lets assume that worked and he made it
  138.  turnaround()
  139.  for r = 1, togo do
  140.   tfuel(1)
  141.   while turtle.forward() == false do
  142.    turtle.dig()
  143.   end
  144.  end
  145.  for x = 1,16 do
  146.   turtle.select(x)
  147.   turtle.dropDown()
  148.  end
  149.  turtle.select(1)
Advertisement
Add Comment
Please, Sign In to add comment