jcoutie

skyscraper

Jan 22nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.53 KB | None | 0 0
  1. -- Variables
  2.  
  3. turtle.select(1)
  4. height = 0
  5. // local tArgs = { ... }
  6. // local levelTotal = tonumber(tArgs[1])
  7. // levelTotal = levelTotal or 1
  8.  
  9. -- Functions
  10.  
  11. local function tMove(distance)
  12.   for i=1,distance do
  13.     while turtle.forward() == false do
  14.       turtle.dig()
  15.       turtle.attack()
  16.       sleep(0.5)
  17.     end
  18.   end
  19. end
  20.  
  21. local function tDescend(distance)
  22.   for i=1,distance do
  23.     while turtle.down() == false do
  24.       turtle.digDown()
  25.       turtle.attackDown()
  26.       sleep(0.5)
  27.     end
  28.   end
  29. end
  30.  
  31. local function tAscend(distance)
  32.   for i=1,distance do
  33.     while turtle.up() == false do
  34.       turtle.digUp()
  35.       turtle.attackUp()
  36.       sleep(0.5)
  37.     end
  38.   end
  39. end
  40.  
  41. local function turnaround()
  42.   turtle.turnRight()
  43.   turtle.turnRight()
  44. end
  45.  
  46. local function checkInv(wanted)
  47.     numReq = 0
  48.     for i=1,15 do
  49.       numReq = numReq + turtle.getItemCount(i)
  50.     end
  51.   if wanted > numReq then
  52.     turtle.turnRight()
  53.     tMove(5)
  54.     turtle.turnRight()
  55.     tMove(1)
  56.     tDescend(height)
  57.     for i=1,15 do
  58.       turtle.select(i)
  59.       turtle.suckDown(turtle.getItemSpace(i))
  60.     end
  61.     turtle.select(1)
  62.     turnaround()
  63.     tAscend(height)
  64.     tMove(1)
  65.     turtle.turnLeft()
  66.     tMove(5)
  67.     turtle.turnRight()
  68.   end
  69. end
  70.  
  71. local function tPlace()
  72.  if turtle.getItemCount(1) == 0 then
  73.   for i=2,15 do
  74.     turtle.select(i)
  75.     turtle.transferTo(1)
  76.   end
  77.  end
  78.   turtle.select(1)
  79.   while turtle.placeDown() == false do
  80.     turtle.digDown()
  81.     turtle.attackDown()
  82.   end
  83. end
  84.  
  85. -- -- delete section if above is working
  86. local function tPlaceBk()
  87.   placedItem = 0
  88.   for i=1,15 do
  89.     if turtle.getItemCount(i) > 0 then
  90.       if placedItem == 0 then
  91.         turtle.select(i)
  92.         turtle.placeDown()
  93.         placedItem = 1
  94.       end
  95.     end
  96.   end
  97.   turtle.select(1)
  98. end
  99.  
  100. local function tLineDraw(length)
  101.   for i=1,length do
  102.     tMove(1)
  103.     tPlace()
  104.   end
  105. end
  106.  
  107. local function tOuterLoop()
  108.   tLineDraw(2)
  109.   turtle.turnLeft()
  110.   tLineDraw(2)
  111.   turtle.turnLeft()
  112.   tLineDraw(1)
  113. end
  114.  
  115. local function tLevelWall()
  116.   checkInv(60)
  117.   for wall=1,4 do
  118.     tLineDraw(4)
  119.     turtle.turnLeft()
  120.     for c=1,3 do
  121.       tLineDraw(2)
  122.       turtle.turnRight()
  123.     end
  124.     tLineDraw(1)
  125.     turnaround()
  126.     tMove(1)
  127.     tLineDraw(4)
  128.     turtle.turnRight()
  129.   end
  130. end
  131.  
  132. local function tTorchPlace()
  133.   turtle.select(16)
  134.   while turtle.placeDown() == false do
  135.     turtle.digDown()
  136.     turtle.attackDown()
  137.   end
  138.   turtle.select(1)
  139. end
  140.  
  141. local function tTorchCheck()
  142.   if turtle.getItemCount(16) < 4 then
  143.     tMove(5)
  144.     turtle.turnLeft()
  145.     tMove(1)
  146.     tDescend(height)
  147.     turtle.select(16)
  148.     turtle.suckDown(turtle.getItemSpace(16))
  149.     turtle.select(1)
  150.     turnaround()
  151.     tAscend(height)
  152.     tMove(1)
  153.     turtle.turnRight()
  154.     tMove(5)
  155.     turnaround()
  156.   end
  157. end
  158.  
  159. local function tFloorLoopNorm()
  160.   tPlace()
  161.   tLineDraw(10)
  162.   turtle.turnLeft()
  163.   tLineDraw(1)
  164.   turtle.turnLeft()
  165.   tLineDraw(10)
  166.   turtle.turnRight()
  167.   tMove(1)
  168.   turtle.turnRight()
  169. end
  170.  
  171. local function tLevelFloor()
  172.   checkInv(141)
  173.   tTorchCheck()
  174.   turtle.turnRight()
  175.   for i=1,5 do
  176.     tFloorLoopNorm()
  177.   end
  178.   tPlace()
  179.   tLineDraw(10)
  180.   turnaround()
  181.   tMove(4)
  182.   turtle.turnRight()
  183.   tOuterLoop()
  184.   tMove(5)
  185.   turtle.turnRight()
  186.   tMove(4)
  187.   tOuterLoop()
  188.   tMove(11)
  189.   tOuterLoop()
  190.   tMove(7)
  191.   turtle.turnLeft()
  192.   tMove(6)
  193.   tOuterLoop()
  194.   tMove(1)
  195.   turtle.turnLeft()
  196.   tMove(6)
  197.   turtle.turnRight()
  198. end
  199.  
  200. local function tTorchLay()
  201.   tTorchCheck()
  202.   tMove(3)
  203.   turtle.turnRight()
  204.   tMove(3)
  205.   tTorchPlace()
  206.   tMove(4)
  207.   tTorchPlace()
  208.   turtle.turnLeft()
  209.   tMove(4)
  210.   tTorchPlace()
  211.   turtle.turnLeft()
  212.   tMove(4)
  213.   tTorchPlace()
  214.   tMove(3)
  215.   turtle.turnLeft()
  216.   tMove(7)
  217.   turnaround()
  218. end
  219.  
  220. -- Startup
  221.  
  222.  term.clear()
  223.  term.setCursorPos(1,1)
  224.  print("Please place blocks as follows:")
  225.  print("Slot 1-15 - Building Material")
  226.  print("Slot 16 - Torches")
  227.  print("Chest Beneath - Building Material")
  228.  print("Chest Beneath,Left - Torches")
  229.  print()
  230.  print("Enter number of floors:")
  231.  levelTotal = read(input)
  232.  tMove(1)
  233.  turtle.turnLeft()
  234.  tMove(5)
  235.  turtle.turnRight()
  236.  
  237. -- Main Loop
  238. for cycle=1,levelTotal do
  239.   tTorchLay()
  240.   tLevelWall()
  241.   tAscend(1)
  242.   height = height + 1
  243.   tLevelWall()
  244.   tAscend(1)
  245.   height = height + 1
  246.   tLevelWall()
  247.   tAscend(1)
  248.   height = height + 1
  249.   tLevelFloor()
  250.   tAscend(1)
  251.   height = height + 1
  252. end
  253. tTorchLay()
  254. turtle.turnRight()
  255. tMove(5)
  256. turtle.turnRight()
  257. tMove(1)
  258. tDescend(height)
  259. turnaround()
Advertisement
Add Comment
Please, Sign In to add comment