Advertisement
Guest User

farm

a guest
Jul 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. --os.loadAPI("inventory")
  2. os.loadAPI("itemID")
  3. rowSize = 8
  4. length = 9
  5. rowCount = 5
  6.  
  7. function start()
  8.   turtle.up()
  9.   for i=1, rowCount do
  10.     for x=1, rowSize do
  11.       if not turtle.forward() then
  12.         refuel()
  13.         turtle.forward()
  14.       end
  15.       checkCrops()
  16.     end
  17.     nextRow()
  18.   end
  19.   replace()
  20. end
  21.  
  22. function refuel()
  23.   say("Refueling...")
  24.   currentSlot = turtle.getSelectedSlot()
  25.   turtle.select(16)
  26.   while not turtle.refuel()  do
  27.     say("FARMING TURTLE NEEDS FUEL.")
  28.     sleep(20)
  29.   end
  30.   say("Fuel Level at " .. turtle.getFuelLevel())
  31. end
  32.  
  33. function plant()
  34.   say("Planting Seeds...")
  35.   selectingSeeds = false
  36.   while not selectingSeeds do
  37.     slotInfo = turtle.getItemDetail()
  38.     currentItem = ""
  39.     if slotInfo ~= nil then
  40.       currentItem = slotInfo.name
  41.     end
  42.     if currentItem == "minecraft:wheat_seeds" then
  43.       selectingSeeds = true
  44.     else
  45.       num = turtle.getSelectedSlot() + 1
  46.       if num > 15 then
  47.         num = 1
  48.       end
  49.       turtle.select(num)
  50.       say("Searching for seeds in slot" .. num)
  51.     end
  52.   end
  53.   if not turtle.placeDown() then  
  54.     say("Failed. The space is occupied.")
  55.   end
  56. end
  57.  
  58. function checkCrops()
  59.   say("Checking Crops...")
  60.   if turtle.detectDown() then
  61.     success, info = turtle.inspectDown()
  62.     name = info.name
  63.     if name == "minecraft:wheat" then
  64.       say("Wheat Detected...")
  65.       growth = info.metadata
  66.       if growth == 7 then
  67.         say("Wheat fully grown!")
  68.         harvest()
  69.       else
  70.         say("Wheat still growing...")
  71.       end
  72.     end    
  73.   else
  74.     say("Space empty. Planting...")
  75.     harvest()
  76.   end
  77. end
  78.  
  79. function harvest()
  80.   say("Harvesting...")
  81.   turtle.digDown()
  82.   plant()
  83. end
  84. function nextRow()
  85.   say("Moving to next row...")
  86.   shell.run(string.format("go back %d", rowSize))
  87.   turtle.turnRight()
  88.   turtle.forward()
  89.   turtle.forward()
  90.   turtle.turnLeft()
  91. end
  92.  
  93. function replace()
  94.   say("Moving to starting position...")
  95.   turtle.turnLeft()
  96.   shell.run(string.format("go forward %d", length - 1))
  97.   turtle.down()
  98.   turtle.turnRight()
  99.   say("Finished!")
  100.   shell.run("clear")
  101. end
  102.  
  103. function say(message)
  104.   print(message)
  105. end
  106.  
  107. start()
  108. say("END")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement