4ndertheker

[CC-Turtle] 4x2x2-Fir/Redwood-Farm

Dec 13th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. local height = 0
  2. local time = os.clock()
  3. local fuelNeeded = false
  4.  
  5. local function forward()
  6.   while not turtle.forward() do
  7.     turtle.attack()
  8.     turtle.dig()
  9.   end
  10.   return true
  11. end
  12.  
  13. local function down()
  14.   while not turtle.down() do
  15.     turtle.attackDown()
  16.     turtle.digDown()
  17.   end
  18.   return true
  19. end
  20.  
  21. local function up()
  22.   while not turtle.up() do
  23.     turtle.attackUp()
  24.     turtle.digUp()
  25.   end
  26.   return true
  27. end
  28.  
  29. local function checkFuel()
  30.   if turtle.getFuelLevel() <= 200 then
  31.     fuelNeeded = true
  32.   elseif turtle.getFuelLevel() <= 10 then
  33.     error("Bitte manuel auftanken.")
  34.   else
  35.     fuelNeeded = false
  36.   end
  37. end
  38.  
  39. local function checkSuck()
  40.   if os.clock() >= (time + 200) then
  41.     down()
  42.     down()
  43.     time = os.clock()
  44.     turtle.suckDown()
  45.     up()
  46.     up()
  47.   end
  48. end
  49.  
  50. local function checkSlots(sCount)
  51.   if turtle.getItemCount(1) < sCount then
  52.     print("Zu wenige Saplings in Slot 1, bitte mindestens ", sCount, " einfuellen und Taste druecken.")
  53.     os.pullEvent("key")
  54.   end
  55. end
  56.  
  57. local function drop()
  58.   down()
  59.   down()
  60.   down()
  61.   for i=2, 16 do
  62.     turtle.select(i)
  63.     turtle.dropDown()
  64.   end
  65.   turtle.select(1)
  66.   up()
  67.   turtle.suckDown()
  68.   time = os.clock()
  69.   up()
  70.   up()
  71.   checkFuel()
  72. end
  73.  
  74. local function harvest()
  75.   checkSlots(5)
  76.   turtle.select(2)
  77.   turtle.down()
  78.   turtle.dig()
  79.   forward()
  80.   while turtle.detectUp() do
  81.     turtle.dig()
  82.     turtle.digUp()
  83.     if up() then
  84.       height = height + 1
  85.     end
  86.   end
  87.   turtle.dig()
  88.   turtle.turnLeft()
  89.   turtle.dig()
  90.   forward()
  91.   turtle.turnRight()
  92.   while height > 0 do
  93.     turtle.dig()
  94.     turtle.digDown()
  95.     if down() then
  96.       height = height - 1
  97.     end
  98.   end
  99.   turtle.dig()
  100.   checkSlots(5)
  101.   turtle.select(1)
  102.   turtle.dig()
  103.   turtle.place()
  104.   turtle.turnRight()
  105.   forward()
  106.   turtle.turnLeft()
  107.   turtle.dig()
  108.   turtle.place()
  109.   turtle.turnLeft()
  110.   turtle.place()
  111.   turtle.turnLeft()
  112.   forward()
  113.   turtle.turnLeft()
  114.   turtle.turnLeft()
  115.   turtle.place()
  116.   checkFuel()
  117.   if fuelNeeded then
  118.     for i=2, 16 do
  119.     turtle.select(i)
  120.     turtle.refuel()
  121.     end
  122.     turtle.select(1)
  123.     checkFuel()
  124.   end
  125.   up()
  126.   drop()
  127. end
  128.  
  129. local function place()
  130.   checkSlots(5)
  131.   turtle.select(1)
  132.   forward()
  133.   turtle.turnLeft()
  134.   forward()
  135.   turtle.turnRight()
  136.   turtle.dig()
  137.   turtle.place()
  138.   turtle.turnRight()
  139.   forward()
  140.   turtle.turnLeft()
  141.   turtle.dig()
  142.   turtle.place()
  143.   turtle.turnLeft()
  144.   turtle.place()
  145.   turtle.turnLeft()
  146.   forward()
  147.   turtle.turnLeft()
  148.   turtle.turnLeft()
  149.   turtle.place()
  150. end
  151.  
  152. local function start()
  153.   checkSlots(17)
  154.   checkSuck()
  155.   checkFuel()
  156.   for i = 1, 4 do
  157.     place()
  158.     turtle.turnLeft()
  159.   end
  160.   up()
  161.   checkFuel()
  162. end
  163.  
  164. local function wait()
  165.   checkSlots(5)
  166.   select(1)
  167.   while not turtle.detect() do
  168.     turtle.turnLeft()
  169.     sleep(1)
  170.     checkSuck()
  171.   end
  172. end
  173.  
  174. ----------------------------------------------
  175.  
  176. start()
  177. while true do
  178.   wait()
  179.   harvest()
  180. end
Advertisement
Add Comment
Please, Sign In to add comment