Advertisement
pson

BotaniaFlowers.lua

Jul 18th, 2020
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.36 KB | None | 0 0
  1. function forward(i)
  2.     while i > 0 do
  3.         turtle.forward()
  4.         i=i-1
  5.     end
  6. end
  7.  
  8. function pick_flower()
  9.     if turtle.detectDown() then
  10.         turtle.digDown()
  11.     end
  12. end
  13.  
  14. function pick_and_move(i)
  15.     while i > 0 do
  16.         if turtle.detectDown() then
  17.             turtle.digDown()
  18.         end
  19.         forward(1)
  20.         i = i-1
  21.     end        
  22. end
  23.  
  24.  
  25. function uturn_left()
  26.     turtle.turnLeft()
  27.     pick_and_move(1)
  28.     turtle.turnLeft()
  29. end
  30.  
  31. function uturn_right()
  32.     turtle.turnRight()
  33.     pick_and_move(1)
  34.     turtle.turnRight()
  35. end
  36.  
  37. function dump_flowers()
  38.     local i
  39.  
  40.     for i=1,16,1 do
  41.         if turtle.getItemCount(i) > 0 then
  42.             turtle.select(i)
  43.             turtle.dropDown()
  44.         end
  45.     end
  46.     turtle.select(1)
  47. end
  48.  
  49. function one_lap()
  50.     local i, fuel
  51.  
  52.     turtle.up()
  53.     forward(3)
  54.     pick_and_move(7)
  55.     uturn_right()
  56.     pick_and_move(7)
  57.     uturn_left()
  58.     pick_and_move(7)
  59.     uturn_right()
  60.     pick_and_move(7)
  61.     uturn_left()
  62.     pick_and_move(3)
  63.     forward(1)
  64.     pick_and_move(3)
  65.     uturn_right()
  66.     pick_and_move(7)
  67.     uturn_left()
  68.     pick_and_move(7)
  69.     uturn_right()
  70.     pick_and_move(7)
  71.     uturn_left()
  72.     pick_and_move(7)
  73.     turtle.turnLeft()
  74.     turtle.turnLeft()
  75.     pick_flower()
  76.     forward(8)
  77.     turtle.turnRight()
  78.     pick_and_move(8)
  79.     pick_flower()
  80.     turtle.turnRight()
  81.     turtle.back()
  82.     turtle.back()
  83.     turtle.down()
  84.     dump_flowers()
  85.     fuel = turtle.getFuelLevel()
  86.     if fuel > 200 then
  87.         print("Fuel: ",fuel)
  88.     else
  89.         print("Out of fuel")
  90.         return
  91.     end
  92. end
  93.  
  94. function main()
  95.     local fuel
  96.     fuel = turtle.getFuelLevel()
  97.     while fuel > 200 do
  98.         one_lap()
  99.         fuel = turtle.getFuelLevel()
  100.         if fuel > 200 then
  101.             sleep(180)
  102.         end
  103.     end
  104. end
  105.  
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement