Guest User

Untitled

a guest
Nov 20th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.62 KB | None | 0 0
  1. local t = 4
  2. local h = 0
  3. local s = 16
  4. local tArgs = {...}
  5. if #tArgs < 1 then
  6.   print("Usage: trees <area>")
  7.   return
  8. end
  9.  
  10. --[[function home()
  11.   rednet.open("right")
  12.   loc = {gps.locate(3,false)}
  13.   if loc[1],loc[2],loc[3] ~= -466, 63, 2298 then
  14.     if turtle.detect() then
  15.       turtle.dig()
  16.     end
  17.     turtle.forward()
  18.     tempLoc = {gps.locate(3,false)}
  19.     turtle.back()
  20.     if loc[1] - tempLoc[1] == 1 then
  21.       dir = 2
  22.     elseif
  23.       loc[1] - tempLoc[1] == -1 then
  24.       dir = 0
  25.       turtle.turnLeft()
  26.       turtle.turnLeft()
  27.     elseif
  28.       loc[3] - tempLoc[3] == 1 then
  29.       dir = 3
  30.       turtle.turnLeft()
  31.     elseif
  32.       loc[3] - tempLoc[3] == -1 then
  33.       dir = 1
  34.       turtle.turnRight()  
  35.     end
  36.      travel = {loc[1] - -466, loc[2] - 63, loc[3] - 2298}
  37.   if travel[1] > 0 then
  38.     turtle.turnLeft()
  39.     turtle.turnLeft()
  40.     for i = 1,travel[1] do
  41.       if turtle.detect()then
  42.         turtle.dig()
  43.       end
  44.       turtle.forward()
  45.     end
  46.   elseif travel[1] < 0 then
  47.     for i = travel[1],0 do
  48.       if turtle.detect() then
  49.         turtle.dig()
  50.       end
  51.       turtle.forward()
  52.     end
  53.   end
  54.   if travel[3] < 0 then
  55. end
  56. ]]--    
  57.  
  58. function usage()
  59.   print("Place saplings into slot 2, and a single piece of wood that corresponds to the type of sapling you are using into slot 1")
  60. end      
  61.    
  62. function check()
  63.   if turtle.getItemCount(1) == 0 or turtle.getItemCount(2) == 0 then
  64.     print(usage())
  65.    exit()
  66.   end
  67. end
  68.  
  69. function failsafe()
  70.     turtle.select(2)
  71.     if turtle.compare() == false then
  72.         turtle.select(1)
  73.         if turtle.compare() == false then
  74.             print("Lost. Quitting for safety")
  75.         end
  76.     exit()
  77.     end
  78. end
  79.  
  80. function fwd()
  81.     if turtle.detect() then
  82.         turtle.dig()
  83.     end
  84.     turtle.attack()
  85.     turtle.forward()
  86. end
  87.  
  88. function cut()
  89.   turtle.select(1)  
  90.   if turtle.compare() then
  91.     turtle.dig()
  92.     turtle.forward()
  93.     while turtle.compareUp() do
  94.       turtle.digUp()
  95.       turtle.up()
  96.       h = h + 1
  97.     end
  98.     for i = 1,h do
  99.       turtle.down()
  100.     end
  101.     turtle.back()
  102.   end
  103.   turtle.select(2)
  104.   turtle.place()
  105. end
  106.  
  107. function move()
  108.   turtle.turnRight()
  109.   for i = 1,2 do
  110.     if turtle.detect() then
  111.         turtle.dig()
  112.     end
  113.     turtle.forward()
  114.   end
  115.   turtle.turnLeft()
  116. end
  117.  
  118. function line()
  119.   for i = 1,tArgs[1]-1 do
  120.     cut()
  121.     move()
  122.   end
  123.   cut()
  124. end
  125.  
  126. function switchLine()
  127.   turtle.turnLeft()
  128.   for i = 1,(tArgs[1]*2-1) do
  129.     turtle.forward()
  130.   end
  131.   turtle.turnLeft()
  132.   for i = 1,2 do
  133.     if turtle.detect() then
  134.         turtle.dig()
  135.     end
  136.     turtle.forward()
  137.   end
  138.   turtle.turnLeft()
  139.   if turtle.detect() then
  140.     turtle.dig()
  141.   end
  142.   turtle.forward()
  143.   turtle.turnLeft()
  144. end
  145.  
  146. function deposit()
  147.   local tWood = turtle.getItemCount(1)
  148.   local tSaplings = turtle.getItemCount(2)
  149.   turtle.turnLeft()
  150.   for i = 1,tArgs[1]*2-1 do
  151.     if turtle.detect() then
  152.         turtle.dig()
  153.     end
  154.     turtle.forward()
  155.   end
  156.   turtle.turnRight()
  157.   for i = 1,tArgs[1]*2-2 do
  158.     if turtle.detect() then
  159.         turtle.dig()
  160.     end
  161.     turtle.forward()
  162.   end
  163.   turtle.turnLeft()
  164.   turtle.select(2)
  165.   turtle.suck()
  166.   turtle.drop(1)
  167.   turtle.select(1)
  168.   turtle.drop(tWood - 1)
  169.   for i = 3,16 do
  170.     turtle.select(i)
  171.     turtle.drop()
  172.   end
  173.   turtle.turnLeft()
  174.   turtle.turnLeft()
  175.     if turtle.detect() then
  176.         turtle.dig()
  177.     end
  178.     turtle.forward()
  179.   end
  180.   turtle.turnLeft()
  181. end
  182.  
  183.  
  184. local s = 10
  185.  
  186. while true do
  187. check()
  188. for i = 1,tArgs[1]-1 do
  189.   line()
  190.   switchLine()
  191. end
  192. line()
  193. deposit()
  194. failsafe()
  195. s = 10
  196. for i = 1,10 do
  197.   term.clear()
  198.   term.setCursorPos(1,1)
  199.   print("Waiting "..s.." minutes for the trees to grow")
  200.   s = 10 - i
  201.   sleep(60)
  202. end
  203. end
Add Comment
Please, Sign In to add comment