Advertisement
Dission

rect2

Apr 1st, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. depth, width, height, h_offset = ...
  2. if depth == nil then
  3.     depth = 2
  4. end
  5. if width == nil then
  6.     width = 2
  7. end
  8. if height == nil then
  9.     height = 2
  10. end
  11. if h_offset == nil then
  12.     h_offset = 0
  13. end
  14.  
  15. width_dir = 'r'
  16. timesHorizontal = depth*width
  17. turnAgain = false
  18. height_dir = 'u'
  19. height_traveled = 0
  20. facing = 'f'
  21. num_moves = 0
  22.  
  23. function refuel()
  24.     for i = 1, 16 do
  25.         turtle.select(i)
  26.         turtle.refuel()
  27.     end
  28. end
  29.  
  30. function forward()
  31.     if height_traveled < 2 then
  32.         while not turtle.forward() do  --this loop runs as long as turtle.forward() return false
  33.             turtle.dig() --dig its way through
  34.             sleep(0.8) --i think this is falling time of gravel
  35.         end
  36.     else
  37.         turtle.dig()
  38.         turtle.forward()
  39.     end
  40.     num_moves = num_moves + 1
  41.     if turtle.getFuelLevel() < 500 then
  42.         refuel()
  43.     end
  44. end
  45.  
  46. function right()
  47.     turtle.turnRight()
  48.     if facing == 'f' then
  49.         facing = 'r'
  50.     elseif facing == 'r' then
  51.         facing = 'b'
  52.     elseif facing == 'b' then
  53.         facing = 'l'
  54.     elseif facing == 'l' then
  55.         facing = 'f'
  56.     end
  57. end
  58.  
  59. function left()
  60.     turtle.turnLeft()
  61.     if facing == 'f' then
  62.         facing = 'l'
  63.     elseif facing == 'l' then
  64.         facing = 'b'
  65.     elseif facing == 'b' then
  66.         facing = 'r'
  67.     elseif facing == 'r' then
  68.         facing = 'f'
  69.     end
  70. end
  71.  
  72. function horizontal(start)
  73.     for i = start, timesHorizontal do
  74.         forward()
  75.    
  76.         if turnAgain == true then
  77.             if width_dir == 'r' then
  78.                 right()
  79.                 width_dir = 'l'
  80.             else
  81.                 left()
  82.                 width_dir = 'r'
  83.             end
  84.             turnAgain = false
  85.         end
  86.    
  87.         if i % depth == 0 and i < timesHorizontal then
  88.             if width_dir == 'r' then
  89.                 right()
  90.             else
  91.                 left()
  92.             end
  93.             turnAgain = true
  94.         end
  95.     end
  96. end
  97.  
  98. function vertical()
  99.     for i = 1, height do
  100.         height_traveled = height_traveled + 1
  101.         if i == 1 then
  102.             horizontal(1)
  103.         else
  104.             right()
  105.             right()
  106.             turtle.digDown()
  107.             turtle.down()
  108.             horizontal(2)
  109.         end
  110.     end
  111. end
  112.  
  113. function home()
  114.     start = 1
  115.    
  116.     for i = 2, height do
  117.         turtle.up()
  118.     end
  119.  
  120.     if facing == 'f' then
  121.         left()
  122.         for i = 2, width do
  123.             forward()
  124.         end
  125.         left()
  126.     elseif facing == 'r' then
  127.         left()
  128.         left()
  129.         for i = 2, width do
  130.             forward()
  131.         end
  132.         left()
  133.     elseif facing == 'l' then
  134.         left()
  135.     elseif facing == 'b' then
  136.         start = 2
  137.     end
  138.    
  139.     for i = start, depth do
  140.         forward()
  141.     end
  142. end
  143.  
  144. function drop()
  145.     for i = 1, 16 do
  146.         turtle.select(i)
  147.         turtle.drop()
  148.     end
  149. end
  150.  
  151. function init()
  152.     refuel()
  153.     vertical()
  154.     -- home()
  155.     -- drop()
  156. end
  157.  
  158. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement