Advertisement
Guest User

wheat

a guest
Apr 3rd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local t = turtle
  2.  
  3. print("Enter length:")
  4. local length = tonumber(read())
  5.  
  6. print("Enter width:")
  7. local width = tonumber(read())
  8.  
  9. local area = width * length
  10.  
  11. local fuelLevel = t.getFuelLevel()
  12.  
  13. print("\nCurrent fuel level: ", fuelLevel)
  14. print("It requires: ", area, " fuel")
  15. if fuelLevel < area then
  16.   print("\nWARNING! Not enough fuel!")
  17. end
  18.  
  19. print("\nIt requires ~ ", area, " seeds. To continue enter 1..")
  20. local answer = tonumber(read())
  21.  
  22. if answer ~= 1 then
  23.   return
  24. end
  25.  
  26. function smartTurn(number)
  27.   if number % 2 == 0 then
  28.     t.turnLeft()
  29.   else
  30.     t.turnRight()
  31.   end
  32. end
  33.  
  34. function turnToNewIteration(numberForSmartTurn, width)
  35.   if numberForSmartTurn == width then
  36.     return
  37.   end
  38.   smartTurn(numberForSmartTurn)
  39.   t.forward()
  40.   smartTurn(numberForSmartTurn)
  41. end
  42.  
  43. t.up()
  44. t.forward()
  45.  
  46. local currentSlot = 1
  47.  
  48. function checkSlots()
  49.   local itemCount = t.getItemCount(currentSlot)
  50.   if itemCount == 0 then
  51.     if currentSlot == 16 then
  52.       print("Please, add resources, and press 1..")
  53.       local answer = tonumber(read())
  54.       if answer ~= 1 then
  55.         error("No resources")
  56.       else
  57.         currentSlot = 1
  58.         checkSlots()        
  59.       end
  60.        
  61.     else
  62.       currentSlot = currentSlot + 1
  63.       checkSlots()
  64.     end
  65.   else
  66.     t.select(currentSlot)
  67.   end
  68. end
  69.  
  70. for i = 1, width do
  71.   for j = 1, length do
  72.     t.digDown()
  73.     if t.placeDown() == false then
  74.       checkSlots()
  75.       t.placeDown()
  76.     end  
  77.    
  78.     if j ~= length then
  79.       t.forward()
  80.     end
  81.   end
  82.   turnToNewIteration(i, width)
  83. end
  84.  
  85. if width % 2 == 0 then
  86.   t.turnRight()
  87.   for i = 1, width - 1 do
  88.     t.forward()
  89.   end
  90. else
  91.   t.turnRight()
  92.   t.turnRight()
  93.   for i = 1, length - 1 do
  94.     t.forward()
  95.   end
  96.   t.turnRight()
  97.   for i = 1, width - 1 do
  98.     t.forward()
  99.   end
  100. end
  101. t.turnRight()
  102. t.back()
  103. t.down()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement