LayZee

ComputerCraft Turtle Platform Builder

Sep 2nd, 2013
1,820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. function getInventoryCount ()
  2.   inventoryCount = 0
  3.  
  4.   for slot = 1, 16 do
  5.     inventoryCount = inventoryCount
  6.       + turtle.getItemCount(slot)
  7.   end
  8.  
  9.   return inventoryCount
  10. end
  11.  
  12. function scanForItem ()
  13.   for slot = 1, 16 do
  14.     if turtle.getItemCount(slot) > 0 then
  15.       turtle.select(slot)
  16.  
  17.       return true
  18.     end
  19.   end
  20.  
  21.   return false
  22. end
  23.  
  24. function getItem ()
  25.   while not scanForItem() do
  26.     print("Need more items")
  27.     print("Press any key when ready...")
  28.     io.read()
  29.   end
  30. end
  31.  
  32. function buildRow (rowLength)
  33.   for i = 1, rowLength do
  34.     getItem()
  35.     turtle.placeDown()
  36.  
  37.     if i < rowLength then
  38.       repeat until turtle.forward()
  39.     end
  40.   end
  41. end
  42.  
  43. function buildPlatform (rows, rowLength)
  44.   for i = 1, rows do
  45.     buildRow(rowLength)
  46.  
  47.     if i < rows then
  48.       if i % 2 == 1 then
  49.         turtle.turnLeft()
  50.         repeat until turtle.forward()
  51.         turtle.turnLeft()
  52.       else
  53.         turtle.turnRight()
  54.         repeat until turtle.forward()
  55.         turtle.turnRight()
  56.       end
  57.     end
  58.   end
  59. end
  60.  
  61. -- Get dimensions
  62. term.setCursorPos(1, 1)
  63. term.clear()
  64. print "Platform Builder v0.1 (C) LayZee 2013"
  65.  
  66. term.write("Row length: ")
  67. local rowLength = tonumber(io.read())
  68.  
  69. term.write("Number of rows: ")
  70. local rows = tonumber(io.read())
  71.  
  72. local itemsNeeded = rows * rowLength
  73. local itemsInInventory = getInventoryCount()
  74.  
  75. while itemsInInventory < itemsNeeded do
  76.   print("Need " .. itemsNeeded - itemsInInventory
  77.     .. " additional items to build platform")
  78.   print("Press any key when ready...")
  79.   io.read()
  80.  
  81.   itemsInInventory = getInventoryCount()
  82. end
  83.  
  84. buildPlatform(rows, rowLength)
Advertisement
Add Comment
Please, Sign In to add comment