Advertisement
Guest User

stripmine

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