Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. -- Direction enums
  2. LEFT = 0
  3. RIGHT = 1
  4.  
  5. function go(dir, n)
  6.     -- goes n blocks in direction dir
  7.     -- ends facing direction dir
  8.     if dir == LEFT then
  9.         turtle.turnLeft()
  10.     elseif dir == RIGHT then
  11.         turtle.turnRight()
  12.     else
  13.         print("Invalid direction: '" .. dir .. "'")
  14.         return
  15.     end
  16.  
  17.     for i = 1,n do
  18.         turtle.forward()
  19.     end
  20. end
  21.  
  22. function getBlock()
  23.     -- ensures turtle always has selected block
  24.     while(true) do
  25.         if turtle.getItemCount() == 0 then
  26.             i = turtle.getSelectedSlot()
  27.             turtle.select(i+1)
  28.         else
  29.             break
  30.         end
  31.     end
  32. end
  33.  
  34. function buildLine(length)
  35.     -- builds a line of blocks below the turtle
  36.     for i = 1,length do
  37.         getBlock()
  38.         turtle.placeDown()
  39.         turtle.forward()
  40.     end
  41. end
  42.  
  43. function bigSlice(n)
  44.     -- counter clockwise
  45.     for i = 1,n do
  46.         for j = 1,4 do
  47.             buildLine(4)
  48.  
  49.             turtle.forward()
  50.             go(LEFT, 1)
  51.             turtle.turnRight()
  52.             buildLine(2)
  53.  
  54.             turtle.forward()
  55.             go(LEFT, 1)
  56.             turtle.turnRight()
  57.             buildLine(1)
  58.  
  59.             turtle.forward()
  60.             go(LEFT, 1)
  61.             buildLine(2)
  62.  
  63.             go(LEFT, 1)
  64.             go(LEFT, 1)
  65.         end
  66.     end
  67. end
  68.  
  69. bigSlice(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement