SHARE
TWEET

quarry.lua

wilhueb May 25th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("enter the size (NxN):")
  2.  
  3. n = tonumber(read())
  4.  
  5. x = 0
  6. y = 0
  7. z = 0
  8.  
  9. dir = 0
  10.  
  11. function updatePos()
  12.     if dir == 0 then
  13.         y = y + 1
  14.     elseif dir == 1 then
  15.         x = x + 1
  16.     elseif dir == 2 then
  17.         y = y - 1
  18.     elseif dir == 3 then
  19.         x = x - 1
  20.     end
  21. end
  22.  
  23. function dig()
  24.     turtle.digUp()
  25.     turtle.digDown()
  26.     turtle.dig()
  27. end
  28.  
  29. function forward()
  30.     local fuel = turtle.getFuelLevel()
  31.  
  32.     if fuel == 0 then
  33.         turtle.refuel(1)
  34.     end
  35.  
  36.     turtle.forward()
  37.  
  38.     updatePos()
  39. end
  40.  
  41. function right()
  42.     turtle.turnRight()
  43.  
  44.     if dir == 3 then
  45.         dir = 0
  46.     else
  47.         dir = dir + 1
  48.     end
  49. end
  50.  
  51. function left()
  52.     turtle.turnLeft()
  53.  
  54.     if dir == 0 then
  55.         dir = 3
  56.     else
  57.         dir = dir - 1
  58.     end
  59. end
  60.  
  61. function down()
  62.     local success, data = turtle.inspectDown()
  63.  
  64.     if success then
  65.         if data.name == "minecraft:bedrock" then
  66.             toChest()
  67.             return false
  68.         end
  69.     end
  70.  
  71.     turtle.digDown()
  72.     turtle.down()
  73.  
  74.     z = z - 1
  75. end
  76.  
  77. function up()
  78.     turtle.digUp()
  79.     turtle.up()
  80.  
  81.     z = z + 1
  82. end
  83.  
  84. function returnToChest()
  85.     if dir == 0 then
  86.         left()
  87.     elseif dir == 1 then
  88.         right()
  89.         right()
  90.     elseif dir == 2 then
  91.         right()
  92.     end
  93.  
  94.     for i=1,x do
  95.         forward()
  96.     end
  97.  
  98.     left()
  99.  
  100.     for i=1,y do
  101.         forward()
  102.     end
  103.  
  104.     right()
  105.     right()
  106.  
  107.     for i=z,-1 do
  108.         up()
  109.     end
  110. end
  111.  
  112. while true do
  113.     for x=1,n do
  114.         for y=1,n do
  115.             dig()
  116.  
  117.             if y ~= n then
  118.                 forward()
  119.             end
  120.         end
  121.  
  122.         if x ~= n then
  123.             if x % 2 == 1 then
  124.                 right()
  125.                 forward()
  126.                 right()
  127.             else
  128.                 left()
  129.                 forward()
  130.                 left()
  131.             end
  132.         end
  133.     end
  134.  
  135.     returnToChest()
  136.  
  137.     down()
  138. 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