Advertisement
DomMOW

3by3 Tunnel

Dec 30th, 2020 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. tunnelLengthMax = 32
  2. turn = 1
  3. tunnelLengthCurrent = tunnelLengthMax
  4. placeTorch = 10
  5. kill = 0
  6. ending = false
  7.  
  8. function left()
  9.   turtle.turnLeft()
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function moveForward()
  17.   while turtle.detect() do
  18.     turtle.dig()
  19.   end
  20.   moved = false
  21.   while not(moved) do
  22.     moved = turtle.forward()
  23.   end
  24. end
  25.  
  26. function digForward()
  27.   while turtle.detect() do
  28.     turtle.dig()
  29.   end
  30. end
  31.  
  32. function digBelow()
  33.   while turtle.detectDown() do
  34.     turtle.digDown()
  35.   end
  36. end
  37.  
  38. function digAbove()
  39.   while turtle.detectUp() do
  40.     turtle.digUp()
  41.   end
  42. end
  43.  
  44. function moveUp()
  45.   turtle.digUp()
  46.   moved = false
  47.   while not(moved) do
  48.     turtle.up()
  49.     moved = turtle.up()
  50.   end
  51. end
  52.  
  53. function moveDown()
  54.   turtle.digDown()
  55.   moved = false
  56.   while not(moved) do
  57.     moved = turtle.down()
  58.   end
  59. end
  60.  
  61. function leftDig()
  62.     turtle.turnLeft()
  63.     moveForward()
  64.     digAbove()
  65.     digBelow()
  66.     turtle.turnLeft()
  67.   end
  68.  
  69.   function rightDig()
  70.     turtle.turnRight()
  71.     moveForward()
  72.     digAbove()
  73.     digBelow()
  74.     turtle.turnRight()
  75.   end
  76.  
  77. while true do
  78.   if tunnelLengthCurrent > 0 and ending == false then
  79.     moveForward()
  80.     digAbove()
  81.     digBelow()
  82.     placeTorch = placeTorch - 1
  83.     tunnelLengthCurrent = tunnelLengthCurrent - 1
  84.     if placeTorch <= 0 then
  85.       placeTorch = 10
  86.       turtle.placeDown()
  87.     end
  88.   end
  89.   if tunnelLengthCurrent <= 0 and turn == 1 then
  90.     rightDig()
  91.     tunnelLengthCurrent = tunnelLengthMax
  92.     kill = kill + 1
  93.     turn = 2
  94.   end
  95.   if tunnelLengthCurrent <= 0 and turn == 2 then
  96.     leftDig()
  97.     tunnelLengthCurrent = tunnelLengthMax
  98.     kill = kill + 1
  99.     turn = 3
  100.   end
  101.   if tunnelLengthCurrent <= 0 and turn == 3 then
  102.     tunnelLengthCurrent = tunnelLengthMax
  103.     leftDig()
  104.     right()
  105.     moveForward()
  106.     left()
  107.     while tunnelLengthCurrent > 0 do
  108.       moveForward()
  109.       tunnelLengthCurrent = tunnelLengthCurrent - 1
  110.     end
  111.     kill = 3
  112.     turn = 4
  113.   end
  114.   if kill == 3 then
  115.     error()
  116.   end
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement