_Nobody_

platform

Jan 8th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. io.write("Enter Length: ")
  2. length = io.read()
  3. io.write("Enter Width: ")
  4. width = io.read()
  5. io.write("Build off in what direction? Left or Right?: ")
  6. direction = io.read()
  7.  
  8. local SLOT_COUNT = 16
  9. local WOOD_CHEST = 16
  10. local FILL_SLOT_COUNT = 4
  11.  
  12. function countItems(itemToCount)
  13.     local itemCount = 0
  14.     for slot = 1, SLOT_COUNT, 1 do
  15.         item = turtle.getItemDetail(slot)
  16.         if(item ~= nil) then
  17.             if(item.name == itemToCount) then
  18.                 itemCount = itemCount + turtle.getItemCount(slot)
  19.             end
  20.         end
  21.     end
  22.  
  23.     return itemCount
  24. end
  25.  
  26. function checkWOOD()
  27.     if (countItems("minecraft:cobblestone") < 64) then
  28.         turtle.select(WOOD_CHEST)
  29.         turtle.digUp()
  30.         turtle.placeUp()
  31.  
  32.         for slot = 1, FILL_SLOT_COUNT, 1 do
  33.             turtle.select(slot)
  34.             turtle.suckUp()
  35.         end
  36.  
  37.         turtle.select(WOOD_CHEST)
  38.         turtle.digUp()
  39.     end
  40. end
  41.  
  42. function getItemIndex(itemName)
  43.     for slot = 1, SLOT_COUNT, 1 do
  44.         local item = turtle.getItemDetail(slot)
  45.         if(item ~= nil) then
  46.             if(item["name"] == itemName) then
  47.                 return slot
  48.             end
  49.         end
  50.     end
  51. end
  52.  
  53. function moveForward()
  54.     turtle.forward()
  55. end
  56.  
  57. function moveBackward()
  58.     turtle.back()
  59. end
  60.  
  61. function placeBlock()
  62.     turtle.placeDown()
  63. end
  64.  
  65. function turnRight()
  66.     turtle.turnRight()
  67.     turtle.forward()
  68.     turtle.turnRight()
  69. end
  70.  
  71. function turnLeft()
  72.     turtle.turnLeft()
  73.     turtle.forward()
  74.     turtle.turnLeft()
  75. end
  76.  
  77. function turnAround()
  78.     if direction == "Right" then turnRight()
  79.     elseif direction == "Left" then turnLeft()
  80.     end
  81. end
  82.  
  83. repeat
  84.     for i = 1,tonumber(length) -1 do
  85.         checkWOOD()
  86.         turtle.select(getItemIndex("minecraft:cobblestone"))
  87.         placeBlock()
  88.         moveForward()
  89.  
  90.         if i == tonumber(length) - 1 then
  91.             placeBlock()
  92.             turnAround()
  93.             width = width - 1
  94.  
  95.             if i == tonumber(length) - 1 and direction == "Right"
  96.                 then direction = "Left"
  97.                 elseif i == tonumber(length) - 1 and direction == "Left"
  98.                     then direction = "Right"
  99.             end        
  100.         end
  101.     end    
  102. until width == 0
  103.  
  104.  
Add Comment
Please, Sign In to add comment