Advertisement
lucifersamfr

farmer-turtle

Mar 1st, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. --farmer turtle
  2.  
  3. function isEmpty()
  4.   for i = 1,16 do
  5.     if ( turtle.getItemCount(i) > 0 ) then
  6.       return false
  7.     end
  8.   end
  9.   return true
  10. end
  11.  
  12. function refuel()
  13.   if ( turtle.getFuelLevel() < 5000 ) then
  14.     for i = 1, 16 do
  15.       turtle.select(i)
  16.       if turtle.refuel(0) then -- if it's valid fuel
  17.         turtle.refuel()
  18.       end
  19.     end
  20.   end
  21. end
  22.  
  23. function unload()
  24.   for i = 1,16 do
  25.     turtle.select(i)
  26.     turtle.dropDown()
  27.   end
  28. end
  29.  
  30. function uturn()
  31.   turtle.turnRight()
  32.   turtle.turnRight()
  33. end
  34.  
  35. function f(dist)
  36.   print("[going forward] blocs left : "..dist)
  37.   if ( dist > 1) then
  38.     if ( turtle.detect() ) then
  39.           turtle.dig()
  40.         end
  41.         turtle.forward()
  42.         f(dist-1)
  43.   end
  44. end
  45.  
  46. function u(dist)
  47.   print("[going up] blocs left : "..dist)
  48.   if ( dist > 1) then
  49.     if ( turtle.detectUp() ) then
  50.           turtle.digUp()
  51.         end
  52.         turtle.up()
  53.         u(dist-1)
  54.   end
  55. end
  56.  
  57. function d(dist)
  58.   print("[going down] blocs left : "..dist)
  59.   if ( dist > 1) then
  60.     if ( turtle.detectDown() ) then
  61.           turtle.digDown()
  62.         end
  63.         turtle.down()
  64.         d(dist-1)
  65.   end
  66. end
  67.  
  68. function farmPumpkin(nb)
  69.   --going through a row of pumpkin
  70.   f(nb)
  71.   --get back to starting point
  72.   uturn()
  73.   f(nb)
  74.   --resetting position for next run
  75.   uturn()
  76.   --unload turtle inv in a chest below
  77.   unload()
  78. end
  79.  
  80. function farmMelon(nb)
  81.   --same thing as farm Pumpkin, we call the method
  82.   farmPumpkin(nb)
  83. end
  84.  
  85. function farmSugarCanes(nb)
  86.   --y+2 : farming top layer
  87.   u(2)
  88.   f(nb)
  89.   --y+1 : farming middle layer as we get back to the starting point
  90.   uturn()
  91.   d(1)
  92.   f(nb)
  93.   --resetting position for next run
  94.   uturn()
  95.   d(1)
  96.   --unload turtle inv in a chest below  
  97.   unload()
  98. end
  99.  
  100. function farmGrassField
  101. end
  102.  
  103. if ( isEmpty() ) then
  104.   while true do
  105.     -- farm function call
  106.     sleep(10)
  107.   end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement