Advertisement
argaman

BuildCube

Jun 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. function moveSafely()
  2.     while(turtle.detect()) do
  3.         turtle.dig()
  4.     end
  5.     turtle.forward()
  6. end
  7.  
  8. function reverse()
  9.     turtle.turnRight()
  10.     turtle.turnRight()
  11. end
  12.  
  13. function moveLeft(blocks)
  14.     turtle.turnLeft()
  15.     for i=1,blocks do
  16.         turtle.forward()
  17.     end
  18.     turtle.turnRight()
  19. end
  20.  
  21. function moveRight(blocks)
  22.     turtle.turnRight()
  23.     for i=1,blocks do
  24.         turtle.forward()
  25.     end
  26.     turtle.turnLeft()
  27. end
  28.  
  29. function moveForward(blocks)
  30.     for i=1,blocks do
  31.         turtle.forward()
  32.     end
  33. end
  34.  
  35. function moveBackwards(blocks)
  36.     reverse()
  37.     moveForward(blocks)
  38.     reverse()
  39. end
  40.  
  41. function prepareLine(amount)
  42.     for i=1,amount do
  43.         turtle.moveSafely()
  44.     end
  45. end
  46.  
  47. function prepare(x, y)
  48.     local s = 1
  49.     for i=1,4 do
  50.         prepareLine(SizePairSwitch(1))
  51.         s = s * -1
  52.         turtle.turnLeft()
  53.     end
  54. end
  55.  
  56. function SizePairSwitch(num, x, y)
  57.     if (num == 1) then
  58.         return x
  59.     else
  60.         return y
  61.     end
  62. end
  63.  
  64. function placeBelowLine(amount)
  65.     for i=1,amount-1 do
  66.         turtle.placeDown()
  67.         moveSafely()
  68.     end
  69.     turtle.placeDown()
  70. end
  71.    
  72. function place(x, y)
  73.     local s = 1
  74.     for i=1,4 do
  75.         placeBelowLine(SizePairSwitch(s, x, y))
  76.         s = s * -1
  77.         turtle.turnRight()
  78.     end
  79. end
  80.  
  81. function turnNum(num)
  82.     if (num == 1) then
  83.         turtle.turnRight()
  84.         turtle.dig()
  85.         turtle.forward()
  86.         turtle.turnRight()
  87.     else
  88.         turtle.turnLeft()
  89.         turtle.dig()
  90.         turtle.forward()
  91.         turtle.turnLeft()
  92.     end
  93. end
  94.  
  95. function digAllLine(amount)
  96.     for i=1,amount-1 do
  97.         turtle.dig()
  98.         moveSafely()
  99.     end
  100. end
  101.  
  102. function backToStart(x, y)
  103.     if(x % 2 == 0) then
  104.         moveRight(x-1)
  105.         reverse()
  106.     else
  107.         moveLeft(x-1)
  108.         moveBackwards(y-1)
  109.     end
  110. end
  111.  
  112. function digFloor(x, y)
  113.     local s = 1
  114.     for i=1,x-1 do
  115.         digAllLine(y)
  116.         turnNum(s)
  117.         s = s * -1
  118.     end
  119.     digAllLine(y)
  120.     backToStart(x, y)
  121. end
  122.  
  123. function placeFloor(x, y)
  124.     local s = 1
  125.     for i=1,x-1 do
  126.         placeBelowLine(y)
  127.         turnNum(s)
  128.         s = s * -1
  129.     end
  130.     placeBelowLine(y)
  131.     backToStart(x, y)
  132. end
  133.  
  134. function main(x, y, h)
  135.     --turtle.digDown()
  136.     --turtle.down()
  137.     --digFloor(x, y)
  138.     --turtle.up()
  139.     --placeFloor(x, y)
  140.     --for i=1,h-2 do
  141.     for i=1,h do
  142.         turtle.up()
  143.         place(x, y)
  144.     end
  145.     turtle.up()
  146.     placeFloor(x, y)
  147. end
  148.  
  149. print("length(right):")
  150. local x = tonumber(read())
  151. print("width(forward):")
  152. local y = tonumber(read())
  153. print("height:")
  154. local h = tonumber(read())
  155.  
  156. main(x, y, h)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement