Advertisement
GooGoo

ComputerCraft FloorFiller/Platform Turtle Program

Oct 29th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. -- floor filler/ bridge maker? v1 by GooGoo @ pastebin, ThaWade @ ComputerCraft Forums
  2. --[[
  3.  Known bugs: when turtle runs out of blocks in slot 1 it continues going but places no blocks.
  4.         No refuel.
  5.  
  6. TODO: Add a waitForBlocks bit of code. or make it check and move blocks to slot 1 while working?
  7.     add refuel
  8. ]]
  9.  
  10. --edited on 14, Nov, 2014. Reason: Rewrite of program.
  11.  
  12. local tArgs = { ... }
  13.  
  14. if #tArgs ~= 1 then
  15.     print( "Usage: floor <amount>" )
  16.     return
  17. end
  18.  
  19. -- CONFIGS --
  20. length = tonumber(tArgs[1])
  21. local countOne = turtle.getItemCount(1)
  22. local countTwo = turtle.getItemCount(2)
  23. local countThree = turtle.getItemCount(3)
  24. local countFour = turtle.getItemCount(4)
  25. local maxCount = 64
  26. local minCount = 3
  27. local minAddCount = 1
  28. local getSpace = turtle.getItemSpace(1)
  29. t = turtle
  30. local blocksNeeded = length * 3
  31. local manAddBlocks = (blocksNeeded) - ((countOne + countTwo) + (countThree + countFour)) --for checkBlockInv()
  32. local moveBlocks = (blocksNeeded) - countOne
  33. local totalBlocks = ((countOne + countTwo) + (countThree + countFour))
  34. local yesOrNo
  35. -- CONFIGS END --
  36.  
  37. function checkSlotOne()
  38.     if countOne >= blocksNeeded then
  39.         layFloor()
  40.     elseif totalBlocks < blocksNeeded then
  41.         fillSlot()
  42.     elseif totalBlocks >= blocksNeeded then
  43.         autoSortInv()
  44.     else print("ERROR:@checkSlotOne() Func")
  45.     end
  46. end
  47.  
  48. function fillSlot()
  49.         print("Please add atleast " ..manAddBlocks.." blocks to either slot 1 - 4.")
  50.         sleep(2)
  51.     repeat
  52.         print("Have you added the blocks yet? Yes(y) or No(n)")
  53.         yesOrNo = io.read()
  54.             if yesOrNo == "y" then
  55.                 autoSortInv()
  56.             elseif yesOrNo == "n" then             
  57.                 exit()
  58.             else print("Error:@fillSlot()! Type Y or N! If you did there's something wrong!")
  59.             end
  60.     until yesOrNo == "y" or yesOrNo == "n"
  61. end
  62.  
  63. function checkBlockInv()
  64.     if totalBlocks >= blocksNeeded then
  65.         autoSortInv()
  66.     end
  67. end
  68.  
  69. local firstSlot,lastSlot = 1,4
  70.  
  71. function autoSortInv()
  72.     if countOne < blocksNeeded then
  73.         t.select(1)
  74.         t.transferTo(1)
  75.         t.select(2)
  76.         t.transferTo(1)
  77.         t.select(3)
  78.         t.transferTo(1)
  79.         t.select(4)
  80.         t.transferTo(1)
  81.         layFloor()
  82.         if countOne >= blocksNeeded then
  83.             print("layFloor() would run now from autoSort")
  84.         end
  85.     end
  86. end
  87. function rightFace()
  88.     t.turnRight()
  89. end
  90.  
  91. function leftFace()
  92.     t.turnLeft()
  93. end
  94.  
  95. function aboutFace()
  96.   rightFace()
  97.   rightFace()
  98. end
  99.  
  100. function leftBlock() -- digs and places a block to the left
  101.     leftFace()
  102.     t.dig()
  103.     t.place()
  104. end
  105.  
  106. function frontBlock() --digs block in front of turtle.
  107.     t.select(1)
  108.     t.dig()
  109. end
  110.  
  111. function rightBlock() --digs and places a block to the right.
  112.     aboutFace()
  113.     t.dig()
  114.     t.place()
  115. end
  116.  
  117. function moveUp() --moves forward one block.
  118.     leftFace()
  119.     t.forward()
  120. end
  121.  
  122. function rearBlock() -- places block behind turtle.
  123.     aboutFace()
  124.     t.place()
  125.     aboutFace()
  126. end
  127.  
  128. function layFloor()
  129.     for x = 1, length do
  130.         frontBlock()
  131.         leftBlock()
  132.         rightBlock()
  133.         moveUp()
  134.         rearBlock()
  135.     end
  136. end
  137.  
  138. function startPos()--Goes back to where you started the turtle.
  139.     t.forward()
  140. end
  141.  
  142. checkSlotOne()
  143.  
  144. t.up()
  145.  
  146. aboutFace()
  147.  
  148. local home = length + 1
  149.  
  150. for z=1, home do
  151.     startPos()
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement