SHARE
TWEET

stripmine

a guest May 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local x = 0
  2. local z = 0
  3. local xdir = 0
  4. local zdir = 1
  5.  
  6. local tryDig
  7.  
  8. local function forward()
  9.   while not turtle.forward() do
  10.     tryDig()
  11.   end
  12.   x = x + xdir
  13.   z = z + zdir
  14. end
  15.  
  16. local function turnLeft()
  17.   turtle.turnLeft()
  18.   xdir, zdir = -zdir, xdir
  19. end
  20.  
  21. local function turnRight()
  22.   turtle.turnRight()
  23.   xdir, zdir = zdir, -xdir
  24. end
  25.  
  26. local function goTo(xpos, zpos, xface, zface)
  27.   if x < xpos then
  28.     while xdir ~= 1 do
  29.       turnRight()
  30.     end
  31.     while x < xpos do
  32.       forward()
  33.     end
  34.   end
  35.   if x > xpos then
  36.     while xdir ~= -1 do
  37.       turnRight()
  38.     end
  39.     while x > xpos do
  40.       forward()
  41.     end
  42.   end
  43.   if z > zpos then
  44.     while zdir ~= -1 do
  45.       turnRight()
  46.     end
  47.     while z > zpos do
  48.       forward()
  49.     end
  50.   end
  51.   if z < zpos then
  52.     print("z is less than zero. Something is probably wrong!")
  53.     while zdir ~= 1 do
  54.       turnRight()
  55.     end
  56.     while z < zpos do
  57.       forward()
  58.     end
  59.   end
  60.   while xdir ~= xface or zdir ~= zface do
  61.     turnRight()
  62.   end
  63. end
  64.  
  65. local function collect()
  66.   local prevx, prevz, prevxd, prevzd = x, z, xdir, zdir
  67.   local bUnload = false
  68.   for c=1, 16 do
  69.     select(c)
  70.     if turtle.getItemCount() == 0 then
  71.       bUnload = false
  72.       return
  73.     end
  74.   end
  75.   if bUnload == true then
  76.     goTo(0, 0, 0, -1)
  77.     for c=1, 16 do
  78.          turtle.select(c)
  79.          if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:torch" or turtle.refuel(0) then
  80.               break
  81.          end
  82.          turtle.drop()
  83.     end
  84.   goTo(prevx, prevz, prevxd, prevzd)
  85.   end
  86. end
  87.  
  88. function tryDig()
  89.   while turtle.detect() do
  90.     if turtle.dig() then
  91.       sleep(0.1f)
  92.         -- collect()
  93.     else
  94.       return false
  95.     end
  96.   end
  97.   return true
  98. end
  99.  
  100. local function tryDigUp()
  101.   while turtle.detectUp() do
  102.     if turtle.digUp() then
  103.       sleep(0.1f)
  104.         -- collect()
  105.     else
  106.       return false
  107.     end
  108.   end
  109.   return true
  110. end
  111.  
  112. local function tryDigDown()
  113.   while turtle.detectDown() do
  114.     if turtle.digDown() then
  115.       sleep(0.1f)
  116.       collect()
  117.     else
  118.       return false
  119.     end
  120.   end
  121.   return true
  122. end
  123.  
  124. local function fuelCheck()
  125.   print("Fuel level at "..turtle.getFuelLevel())
  126.   if turtle.getFuelLevel() < 1 then
  127.     for n=1, 16 do
  128.       turtle.select(n)
  129.       if turtle.refuel() then
  130.         turtle.select(1)
  131.         return true
  132.       end
  133.     end
  134.     print("Please Supply Fuel")
  135.     return false
  136.   end
  137.   return true
  138. end
  139.  
  140. local function refuel()
  141.   while not fuelCheck() do
  142.     os.pullEvent("turtle_inventory")
  143.   end
  144. end
  145.  
  146. local function dig()
  147.   refuel()
  148.   while not forward() do
  149.     if turtle.detect() then
  150.       tryDig()
  151.       print("trydig loop!")
  152.     end
  153.   end
  154. end
  155.  
  156. local function digUp()
  157.   refuel()
  158.   while not turtle.up() do
  159.     if turtle.detectUp() then
  160.       tryDigUp()
  161.     end
  162.   end
  163. end
  164.  
  165. local function platform()
  166.   for a=1, 16 do
  167.     turtle.select(a)
  168.     if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:cobblestone" then
  169.       turtle.placeDown()
  170.       turtle.select(1)
  171.       break
  172.     end
  173.   end
  174. end
  175.  
  176. local function tunnel()
  177.   print("Beginning tunnel!")
  178.   for a=1, 32 do
  179.     dig()
  180.     platform()
  181.     tryDigUp()
  182.   end
  183. end
  184.  
  185. local function returnTunnel()
  186.   print("Ending tunnel!")
  187.   local blockCount = 0
  188.   for a=1, 32 do
  189.     refuel()
  190.     while not forward() do
  191.       tryDig()
  192.     end
  193.     blockCount = blockCount + 1
  194.     if blockCount == 8 then
  195.       for a=1, 16 do
  196.         turtle.select(a)
  197.         if turtle.getItemDetail() and turtle.getItemDetail().name == "minecraft:torch" then
  198.           if turtle.getItemCount() > 1 then
  199.             blockCount = 0
  200.             turnLeft()
  201.             turnLeft()
  202.             turtle.place()
  203.             turnLeft()
  204.             turnLeft()
  205.             turtle.select(1)
  206.             break
  207.           end
  208.         end
  209.       end  
  210.     end
  211.   end
  212. end
  213.  
  214. for n=1, 16 do
  215.   tryDigUp()
  216.   turnLeft()
  217.   tunnel()
  218.   turnRight()
  219.   turnRight()
  220.   returnTunnel()
  221.   tunnel()
  222.   turnLeft()
  223.   turnLeft()
  224.   returnTunnel()
  225.   turnRight()
  226.   for a=1, 3 do
  227.     dig()
  228.     tryDigUp()
  229.   end
  230. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top