Advertisement
maxthewell

build.lua

Aug 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. -- Direction enums
  2. LEFT = 0
  3. RIGHT = 1
  4. FORWARD = 3
  5.  
  6. function go(dir, n)
  7.     -- goes n blocks in direction dir
  8.     -- ends facing direction dir
  9.     if dir == LEFT then
  10.         turtle.turnLeft()
  11.     elseif dir == RIGHT then
  12.         turtle.turnRight()
  13.     elseif dir ~= FORWARD then
  14.         print("Invalid direction: '" .. dir .. "'")
  15.         return
  16.     end
  17.  
  18.     for i = 1,n do
  19.         turtle.forward()
  20.     end
  21. end
  22.  
  23. function getBlock()
  24.     -- ensures turtle always has selected block
  25.     while(true) do
  26.         if turtle.getItemCount() == 0 then
  27.             i = turtle.getSelectedSlot()
  28.             turtle.select(i+1)
  29.         else
  30.             break
  31.         end
  32.     end
  33. end
  34.  
  35. function buildLine(length)
  36.     -- builds a line of blocks below the turtle
  37.     for i = 1,length do
  38.         getBlock()
  39.         turtle.placeDown()
  40.         turtle.forward()
  41.     end
  42. end
  43.  
  44. function bigSlice(n)
  45.     -- counter clockwise
  46.     for i = 1,n do
  47.         for j = 1,4 do
  48.             buildLine(4)
  49.  
  50.             go(LEFT, 1)
  51.             turtle.turnRight()
  52.             buildLine(2)
  53.  
  54.             go(LEFT, 1)
  55.             turtle.turnRight()
  56.             buildLine(1)
  57.  
  58.             go(LEFT, 1)
  59.             buildLine(2)
  60.  
  61.             go(RIGHT, 1)
  62.             turtle.turnLeft()
  63.         end
  64.         turtle.up()
  65.     end
  66. end
  67.  
  68. function medSlice(n)
  69.     for i = 1,n do
  70.         for j = 1,4 do
  71.             buildLine(4)
  72.  
  73.             go(LEFT, 1)
  74.             turtle.turnRight()
  75.             buildLine(2)
  76.  
  77.             go(LEFT, 1)
  78.             buildLine(2)
  79.  
  80.             go(RIGHT, 1)
  81.             turtle.turnLeft()
  82.         end
  83.         turtle.up()
  84.     end
  85. end
  86.  
  87. function smallSlice(n)
  88.     for i = 1,n do
  89.         for j = 1,4 do
  90.             buildLine(4)
  91.  
  92.             go(LEFT, 1)
  93.             buildLine(1)
  94.  
  95.             go(RIGHT, 1)
  96.             buildLine(1)
  97.  
  98.             go(LEFT, 1)
  99.         end
  100.         turtle.up()
  101.     end
  102. end
  103.  
  104. turtle.select(1)
  105. bigSlice(1)
  106. -- adjust position for medslice
  107. go(LEFT, 1)
  108. turtle.turnRight()
  109. medSlice(1)
  110. -- adjust position for smallslice
  111. go(LEFT, 1)
  112. turtle.turnRight()
  113. smallSlice(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement