Advertisement
Ignius12

quarry

Oct 7th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. function quarry(width, length, y)
  2.     local row = 0
  3.     local blocks = 0
  4.     local levels = 1
  5.     local turned = false
  6.     local width = width
  7.     local length  = length - 1
  8.     local y1 = y + 1
  9.     local y = y
  10.     local x = 0
  11.     local z = 0
  12.     local xt = 0
  13.     local zt = 0
  14.  
  15.     while(y > 5) do
  16.         turtle.digDown()
  17.         turtle.down()
  18.         if(levels > 1) then
  19.             turtle.turnLeft()
  20.             turtle.turnLeft()
  21.         end
  22.         while(width > z) do
  23.             while(length > x) do
  24.                 turtle.dig()
  25.                 turtle.forward()
  26.                 x = x + 1
  27.                 blocks = blocks + 1
  28.                 print("Blocks mined: " , blocks)
  29.                 if(turtle.getFuelLevel() < 10) then
  30.                     turtle.refuel()
  31.                 end
  32.                 if(turtle.getItemCount(16) > 1) then
  33.                     if((row + 1) % 2 == 0) then
  34.                         xt = length - x
  35.                     else
  36.                         xt = x
  37.                     end
  38.                     if(levels % 2 == 0) then
  39.                         zt = (width - 1)- z
  40.                     else
  41.                         zt = z
  42.                     end
  43.                     x2 = xt
  44.                     y2 = y
  45.                     z2 = zt
  46.                     print("(", zt,",", xt, ")")
  47.                     while(y < y1) do
  48.                         turtle.up()
  49.                         y = y + 1
  50.                     end
  51.                     if(turned == true) then
  52.                         turtle.turnLeft()
  53.                         turtle.turnLeft()
  54.                     end
  55.                     while(xt > 0) do
  56.                         turtle.forward()
  57.                         xt = xt - 1
  58.                     end
  59.                     turtle.turnRight()
  60.                     while(zt > 0) do
  61.                         turtle.forward()
  62.                         zt = zt - 1
  63.                     end
  64.                     turtle.turnLeft()
  65.                     for I = 16,2,-1 do
  66.                         turtle.select(I)
  67.                         turtle.drop()
  68.                     end
  69.                     turtle.turnLeft()
  70.                     while(z2 > zt) do
  71.                         turtle.forward()
  72.                         zt = zt + 1
  73.                     end
  74.                     turtle.turnLeft()
  75.                     while(x2 > xt) do
  76.                         turtle.forward()
  77.                         xt = xt + 1
  78.                     end
  79.                     while(y2 < y) do
  80.                         turtle.down()
  81.                         y = y - 1
  82.                     end
  83.                     if(turned == false) then
  84.                         turtle.turnLeft()
  85.                         turtle.turnLeft()
  86.                     end
  87.                 end
  88.             end
  89.         x = 0
  90.         z = z + 1
  91.         row = row + 1
  92.         if(row % 2 == 0 and z < width and levels % 2 > 0) then
  93.             turtle.turnLeft()
  94.             turtle.dig()
  95.             turtle.forward()
  96.             blocks = blocks + 1
  97.             turtle.turnLeft()
  98.             turned = true
  99.         else if(row % 2 > 0 and z < width and levels % 2 > 0) then
  100.             turtle.turnRight()
  101.             turtle.dig()
  102.             turtle.forward()
  103.             blocks = blocks + 1
  104.             turtle.turnRight()
  105.             turned = false
  106.         else if(row % 2 == 0 and z < width and levels % 2 == 0) then
  107.             turtle.turnRight()
  108.             turtle.dig()
  109.             turtle.forward()
  110.             blocks = blocks + 1
  111.             turtle.turnRight()
  112.             turned = true
  113.         else if(row % 2 > 0 and z < width and levels % 2 == 0) then
  114.             turtle.turnLeft()
  115.             turtle.dig()
  116.             turtle.forward()
  117.             blocks = blocks + 1
  118.             turtle.turnLeft()
  119.             turned = false
  120.         end
  121.         end
  122.         end
  123.         end
  124.         end
  125.         y = y - 1
  126.         z = 0
  127.         levels = levels + 1
  128.         local heightReport = "I have gone ", y, " levels down out of ", y1, " levels"
  129.         rednet.send(3, heightReport)
  130.     end
  131. end
  132.  
  133. rednet.open("left")
  134. local sender, width, protocol = rednet.receive("quarry")
  135. local sender2, length, protocol2 = rednet.receive("quarry")
  136. local sender3, height, protocol3 = rednet.receive("quarry")
  137. local sender4, confirm, protocol4 = rednet.receive("quarry")
  138. if(confirm == "Y") then
  139.     turtle.refuel()
  140.     rednet.send(3, 'Starting...')
  141.     quarry(width,length,height)
  142.     rednet.send(3, 'Complete!')
  143. else
  144.     rednet.send(3, 'Canceled')
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement