SHARE
TWEET

edited kaikaku treefarm 2

a guest May 23rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --{program="aTreeFarm",version="1.04b",date="2018-01-07"}
  2. ---------------------------------------
  3. -- aTreeFarm           by Kaikaku
  4. -- 2018-01-07, v1.04   bugfix (turtle start position)
  5. -- 2018-01-05, v1.03   bugfix (turtle digged drop chest)
  6. -- 2017-12-02, v1.02   start with craft fuel and empty to allow tHome
  7. -- 2015-01-31, v1.01   fixed initial refuelling
  8. -- 2015-01-31, v1.00   finalized UI + counter
  9. -- 2015-01-30, v0.80   auto set-up option
  10. -- 2015-01-26, v0.70   preparing for video
  11. -- 2014-01-12, v0.61   replant limited tries
  12. -- 2014-01-04, v0.60   redstone stop
  13. -- 2013-12-15, v0.51   initial
  14. ---------------------------------------
  15.  
  16.  
  17. ---------------------------------------
  18. ---- DESCRIPTION ----------------------
  19. ---------------------------------------
  20. -- Turtle-automated tree farm.
  21. -- Details see information during program
  22. --   execution or YouTube video.
  23.  
  24.  
  25. ---------------------------------------
  26. ---- PARAMETERS -----------------------
  27. ---------------------------------------
  28. local cVersion  ="1.04"
  29. local cPrgName  ="aTreeFarm"
  30. local cMinFuel  = 960*2      -- 2 stacks of planks
  31.  
  32. local minRandomCheckSapling=0.1 -- below this will check replant
  33. local actRandomCheckSapling=minRandomCheckSapling*2
  34. local cIncreaseCheckSapling_Sapling=0.02
  35. local cIncreaseCheckSapling_Stub=0.04
  36. local cMaxCheckSapling=0.6
  37. local strC="tReeTreESdig!diG;-)FaRmKaIKAKUudIgYdIgyTreEAndsOrRygUYsd"
  38.  
  39. local cSlotChest=16           -- chest for crafty turtle
  40. local cCraftRefuelMaxItems=32 -- use how many logs to refuel at max
  41. local cSlotRefuel=15          -- where to put fuel
  42. local cExtraDigUp=1           -- go how many extra levels to reach jungle branches
  43. local cLoopEnd=56             -- one loop
  44. local cWaitingTime=20         -- if redstone signal in back is on
  45.  
  46. ---------------------------------------
  47. ---- VARIABLES ------------------------
  48. ---------------------------------------
  49. local strC_now=""
  50. local strC_next=""
  51.  
  52. local tmpResult=""
  53. local blnAskForParameters=true
  54. local blnShowUsage=false
  55. local blnAutoSetup=false
  56. local strSimpleCheck="Press enter to start:"
  57. local intCounter=0
  58. local maxCounter=0
  59.  
  60. ---------------------------------------
  61. ---- tArgs ----------------------------
  62. ---------------------------------------
  63. local tArgs = {...}
  64. if #tArgs >= 1 then -- no error check
  65.   blnAskForParameters=false
  66.   if tArgs[1]=="help" then blnShowUsage=true end
  67.   if tArgs[1]=="setup" then blnAutoSetup=true end
  68.   if tArgs[1]=="set-up" then blnAutoSetup=true end
  69.   if tonumber(tArgs[1])~=nil then
  70.     maxCounter=tonumber(tArgs[1])
  71.   end
  72. end
  73.  
  74. if blnShowUsage then
  75.   print("+-------------------------------------+")
  76.   print("  "..cPrgName..", by Kaikaku")
  77.   print("+-------------------------------------+")
  78.   print("Usage: aTreeFarm [setup/set-up]")
  79.   print("   or: aTreeFarm [maxCounter]")
  80.   print("setup or set-up:")
  81.   print("   Will start auto set-up")
  82.   print("maxCounter:")
  83.   print("   0=will farm infinitely")
  84.   print("   x=will farm x rounds")
  85.   print("More details on YouTube ;)")
  86.   return  
  87. end
  88.  
  89. ---------------------------------------
  90. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  91. ---------------------------------------
  92. local function gf(n)
  93.   if n==nil then n=1 end
  94.   for i=1,n,1 do while not  turtle.forward() do turtle.sleep(1) end end
  95. end
  96. local function gb(n)
  97.   if n==nil then n=1 end
  98.   for i=1,n,1 do while not turtle.back() do turtle.sleep(1) end end
  99. end
  100. local function gu(n)
  101.   if n==nil then n=1 end
  102.   for i=1,n,1 do while not turtle.up() do turtle.sleep(1) end end
  103. end
  104. local function gd(n)
  105.   if n==nil then n=1 end
  106.   for i=1,n,1 do while not turtle.down() do turtle.sleep(1) end end
  107. end
  108. local function gl(n)
  109.   if n==nil then n=1 end
  110.   for i=1,n,1 do while not turtle.turnLeft() do turtle.sleep(1) end end
  111. end
  112. local function gr(n)
  113.   if n==nil then n=1 end
  114.   for i=1,n,1 do while not turtle.turnRight() do turtle.sleep(1) end end
  115. end
  116. local function pf(n)
  117.   -- moves backwards if n>1
  118.   if n==nil then n=1 end
  119.   for i=1,n,1 do if i~=1 then gb() end turtle.sleep(1) turtle.place() end
  120. end
  121. local function pu()  turtle.placeUp() turtle.sleep(1)     end
  122. local function pd()  turtle.placeDown() turtle.sleep(1)   end
  123. local function df()  return turtle.dig() turtle.sleep(1)  end
  124. local function du()  turtle.digUp()  turtle.sleep(1)      end
  125. local function dd()  turtle.digDown() turtle.sleep(1)     end
  126. local function sf()  turtle.suck()   turtle.sleep(1)      end
  127. local function su()  turtle.suckUp()   turtle.sleep(1)    end
  128. local function sd(n)
  129.   if n==nil then
  130.     while turtle.suckDown() do turtle.sleep(1) end
  131.   else
  132.     for i=1,n do
  133.       turtle.sleep(1)
  134.       turtle.suckDown()
  135.     end
  136.   end
  137. end
  138. local function Df()  turtle.drop()      turtle.sleep(1)  end
  139. local function Du(n) if n==nil then n=64 end turtle.sleep(1) turtle.dropUp(n) end
  140. local function Dd(n) if n==nil then n=64 end turtle.sleep(1) turtle.dropDown(n) end
  141. local function ss(s) turtle.select(s)   turtle.sleep(1)  end
  142.  
  143. local function askForInputText(textt)
  144.   local at=""
  145.   -- check prompting texts
  146.   if textt==nil then textt="Enter text:" end
  147.  
  148.   -- ask for input
  149.   write(textt)
  150.   at=read()
  151.   return at
  152. end
  153.  
  154. local function checkFuel()
  155.   local tmp=turtle.getFuelLevel()
  156.   return tmp
  157. end
  158.  
  159. function checkRefuel(minFuel, slotFuel)
  160.   if slotFuel==nil then slotFuel=16 end
  161.   if minFuel==nil then minFuel=1000 end
  162.   local tmpFuel=0 tmpFuel2=0
  163.   local tmpItems=65 --turtle.getItemCount(slotFuel)
  164.   local cSleep=5
  165.  
  166.   -- step 1 check if more fuel is required
  167.   tmpFuel=turtle.getFuelLevel()
  168.   tmpFuel2=tmpFuel-1 -- triggers print at least once
  169.   if tmpFuel<minFuel then
  170.     ss(slotFuel)
  171.     -- step 2 refuel loop
  172.     while tmpFuel<minFuel do
  173.       -- step 2.1 need to update fuel level?
  174.       if tmpFuel2~=tmpFuel then --tmpItems~=turtle.getItemCount(slotFuel) then
  175.         -- fuel still too low and there have been items consumed
  176.         print("Need more fuel ("..tmpFuel.."/"..minFuel..") in slot "..slotFuel)
  177.       end
  178.       -- step 2.2 try to refuel
  179.       if tmpItems>0 then
  180.         -- try to refuel this items
  181.          turtle.sleep(1)
  182.          turtle.refuel()
  183.       else
  184.         os.sleep(cSleep)       
  185.       end
  186.       -- step 2.3 update variables
  187.       tmpItems=turtle.getItemCount(slotFuel)
  188.       tmpFuel2=tmpFuel
  189.       tmpFuel=turtle.getFuelLevel()
  190.     end
  191.   end
  192.   -- step 3 either no need to refuel
  193.   --        or successfully refuelled
  194.   print("Fuel level ok  ("..tmpFuel.."/"..minFuel..")")
  195. end
  196.  
  197.  
  198. ---------------------------------------
  199. ---- functions ------------------------
  200. ---------------------------------------
  201.  
  202. local function cutTree()
  203. local tmpExtraDigUp=cExtraDigUp
  204.  
  205.   ---- assumptions
  206.   -- turtle faces trunk one block below bottom
  207.   ---- variables
  208.   local intUpCount = 0
  209.   local intFace = 0 -- -1=left, 1=right
  210.   local blnDigSomething=false
  211.  
  212.   term.write("  cutting tree: ")
  213.  
  214.   -- get into tree column
  215.   df()
  216.   while not turtle.forward() do df() end
  217.   gr() df() gl() df() gl() df()
  218.   local intFace=-1
  219.  
  220.   -- cut and go up
  221.   repeat
  222.     blnDigSomething=false
  223.     du()
  224.     while not turtle.up() do du()  turtle.sleep(1) end
  225.     blnDigSomething=df() or blnDigSomething
  226.     if intFace==-1 then
  227.       turtle.sleep(1)
  228.       gr()
  229.       blnDigSomething=df() or blnDigSomething
  230.       turtle.sleep(1)
  231.       gr()
  232.     elseif intFace==1 then
  233.       turtle.sleep(1)
  234.       gl()
  235.       blnDigSomething=df() or blnDigSomething
  236.       turtle.sleep(1)
  237.       gl()
  238.     end
  239.     intFace=intFace * -1
  240.     blnDigSomething=df() or blnDigSomething
  241.     intUpCount = intUpCount +1
  242.     term.write(".")
  243.    
  244.     -- check for 2 conditions
  245.     -- either
  246.     -- 1) nothing above the turtle
  247.     -- or
  248.     -- 2) nothing dig on the other columns blnDigSomething
  249.     turtle.sleep(1)
  250.     if not (turtle.detectUp() or blnDigSomething) then
  251.       tmpExtraDigUp=tmpExtraDigUp-1  
  252.     else
  253.       tmpExtraDigUp=cExtraDigUp -- restore it  
  254.     end    
  255.   until tmpExtraDigUp<0 --not (turtle.detectUp() or blnDigSomething) ----- NOT kai_2
  256.  
  257.   -- go off tree column  
  258.   if intFace==-1 then
  259.     turtle.sleep(1)
  260.     gl()
  261.   elseif intFace==1 then
  262.     turtle.sleep(1)
  263.     gr()
  264.   end
  265.   df()
  266.   while not turtle.forward() do turtle.sleep(1) df() end
  267.   turtle.sleep(1)
  268.   gl()
  269.   intFace = 0
  270.  
  271.   intFace = 1 -- 1=forward,-1=backwards
  272.   -- go back down  
  273.   -- hint: only digging front and back in order
  274.   --       to not cut into larger neighbouring,
  275.   --       as this may leave upper tree parts left
  276.   for i = 1,intUpCount+1 do
  277.     turtle.sleep(1) dd() turtle.sleep(1) df() turtle.sleep(1) gl(2) turtle.sleep(1) df()
  278.     intFace=intFace* -1
  279.     while not turtle.down() do dd() end
  280.   end
  281.   if intFace==1 then
  282.     gl()
  283.   elseif intFace==-1 then
  284.     gr()
  285.   end
  286.   sf() df() term.write(".")
  287.   print(" done!")
  288.  
  289.   -- plant new
  290.   turtle.sleep(1) plantTree()
  291.   while not turtle.up() do turtle.sleep(1) du() end
  292.   turtle.sleep(1) sd()  
  293. end
  294.  
  295. ---------------------------------------
  296. function plantTree()
  297. local tmpCount=0
  298.   ---- assumptions
  299.   -- turtle faces place to plant
  300.  
  301.   -- check for enough saplings
  302.   sf()
  303.   if turtle.getItemCount(1) > 1 then
  304.     -- plant
  305.     print("  plant new sapling")
  306.     while not turtle.place() do
  307.       print("  hard to plant here...")
  308.       tmpCount=tmpCount+1
  309.       if tmpCount>3 then break end
  310.       os.sleep(1)
  311.     end  -- NOT kai_2
  312.   else
  313.     -- error
  314.     print("  Out of saplings...") -- prog name
  315.     os.sleep(5)
  316.     actRandomCheckSapling=cMaxCheckSapling
  317.     return
  318.   end
  319. end
  320.  
  321. ---------------------------------------
  322. local function replantStub()
  323.   ss(2) -- compare with wood in slot 2
  324.   turtle.sleep(1)
  325.   if turtle.compare() then
  326.     -- assumption: there is only a stub left, so replant
  327.     -- if there is a tree on top of it, it will be harvested next round
  328.     print("  Replanting a stub")
  329.     turtle.sleep(1) df() turtle.sleep(1) ss(1)
  330.     if pf() then
  331.       turtle.sleep(1)
  332.       actRandomCheckSapling=actRandomCheckSapling+cIncreaseCheckSapling_Stub
  333.     else
  334.       print("    failure!")  
  335.     end
  336.   else
  337.     turtle.sleep(1)
  338.     ss(1)
  339.     end
  340.   end
  341.   local function eS(sI,sA,eA)
  342.   local sO=""
  343.   local sR=""
  344.   if sA==nil then sA=1 end
  345.   if eA==nil then eA=string.len(sI) end
  346.   for i=sA,eA,1 do
  347.     sO=string.sub(sI,i,i)
  348.     if sR~="" then break end
  349.     if sO=="a" then
  350.       gl()
  351.     elseif sO=="d" then
  352.       turtle.sleep(1)
  353.       gr()
  354.     else
  355.       while not turtle.forward() do turtle.sleep(1) df() end
  356.     end
  357.   end
  358.   return sR
  359. end
  360.  
  361. ---------------------------------------
  362. local function randomReplant()
  363. local intSuccess=0
  364.   if turtle.getItemCount(1) > 10 then
  365.     -- try to plant
  366.     while not turtle.down() do turtle.sleep(1) dd() end
  367.     turtle.sleep(1) sf() turtle.sleep(1) gl() turtle.sleep(1) sf()
  368.     if turtle.place() then
  369.       turtle.sleep(1)
  370.         actRandomCheckSapling=actRandomCheckSapling+cIncreaseCheckSapling_Sapling
  371.     else
  372.     turtle.sleep(1)  
  373.     if turtle.detect() then replantStub() end
  374.     end
  375.     turtle.sleep(1) gl() turtle.sleep(1) sf() turtle.sleep(1) gl() turtle.sleep(1) sf()
  376.     if turtle.place() then
  377.       turtle.sleep(1)
  378.         actRandomCheckSapling=actRandomCheckSapling+cIncreaseCheckSapling_Sapling
  379.     else
  380.       turtle.sleep(1)
  381.       if turtle.detect() then replantStub() end
  382.     end
  383.     turtle.sleep(1) gl() turtle.sleep(1) sf()
  384.     while not turtle.up() do du() end
  385.     -- ensure min probability and max 100%
  386.     turtle.sleep(1)
  387.     actRandomCheckSapling=math.max(actRandomCheckSapling-0.01,minRandomCheckSapling)
  388.     turtle.sleep(1)
  389.     actRandomCheckSapling=math.min(actRandomCheckSapling,cMaxCheckSapling)
  390.     print((actRandomCheckSapling*100).."% check probability")
  391.   else
  392.     -- extra suck
  393.     while not turtle.down() do turtle.sleep(1) dd() end
  394.     turtle.sleep(1) sf() turtle.sleep(1) gr() turtle.sleep(1) sf() turtle.sleep(1) gr() turtle.sleep(1) sf() turtle.sleep(1) gr() turtle.sleep(1)  sf() turtle.sleep(1) gr()    turtle.sleep(1) sf()
  395.     while not turtle.up() do turtle.sleep(1) du() end
  396.     turtle.sleep(1)
  397.     sd()
  398.   end
  399. end
  400.  
  401. ---------------------------------------
  402. local function craftFuel()
  403. local tmpFuelItems=turtle.getItemCount(2)
  404.  
  405.   -- step 1 need fuel?
  406.   if (turtle.getFuelLevel()<cMinFuel) and (turtle.getItemCount(cSlotChest)==1) then
  407.   -- no refuelling if not exactly 1 item in slot cSlotChest (=chest)
  408.     print("Auto refuel    ("..turtle.getFuelLevel().."/"..cMinFuel..") ...")
  409.  
  410.     -- step 2 enough mats to refuel?
  411.     --        assumption: slot 2 has wood
  412.     if tmpFuelItems>1 then  
  413.       -- step 2 store away stuff!
  414.       ss(cSlotChest) while not turtle.placeUp() do du() end
  415.      
  416.       for i=1,15,1 do
  417.         turtle.sleep(1)
  418.         ss(i)
  419.         if i~=2 then
  420.           turtle.sleep(1)
  421.             Du()
  422.         else
  423.           -- cCraftRefuelMaxItems
  424.           turtle.sleep(1)
  425.             Du(math.max(1,turtle.getItemCount(2)-cCraftRefuelMaxItems)) -- to keep the wood
  426.         end
  427.       end
  428.      
  429.       -- step 3 craft planks!
  430.       turtle.craft()
  431.       turtle.sleep(1)
  432.       -- step 4 refuel!
  433.       for i=1,16,1 do
  434.         turtle.sleep(1)
  435.         ss(i)
  436.         turtle.sleep(1)
  437.         turtle.refuel()
  438.       end
  439.       print("New fuel level ("..turtle.getFuelLevel().."/"..cMinFuel..")")
  440.      
  441.       -- step 5 get back stuff!
  442.       ss(1) --su(64)
  443.       while turtle.suckUp() do turtle.sleep(1) end
  444.       ss(cSlotChest) turtle.sleep(1) du() turtle.sleep(1) ss(1)
  445.     else   
  446.       print("Ups, not enough wood for auto refuel!")
  447.     end
  448.   end
  449. end
  450.  
  451.  
  452. ---------------------------------------
  453. local function emptyTurtle()
  454.   print("  Drop what I've harvested!")
  455.   while not turtle.down() do turtle.sleep(1) dd() end
  456.   turtle.sleep(1)
  457.     ss(2)
  458.   turtle.sleep(1)
  459.   if turtle.compareTo(1) then
  460.     print("Error: Ups, in slot 2 is the same as in slot 1??")
  461.     --Dd()
  462.   else
  463.     -- if slot 2 has other item (wood) than slot 1
  464.     --   keep one of them for comparison
  465.     turtle.sleep(1)
  466.     if turtle.getItemCount(2)>1 then
  467.       turtle.sleep(1)
  468.         Dd(math.max(turtle.getItemCount(2)-1,0))
  469.     end
  470.   end
  471.   for i=3,15,1 do
  472.     -- assumption slot 16 contains a chest
  473.     turtle.sleep(1)
  474.     ss(i)
  475.     turtle.sleep(1)
  476.     Dd()
  477.   end
  478.   os.sleep(0)
  479.   turtle.sleep(1)
  480.     ss(1)
  481. end
  482.  
  483. ---------------------------------------
  484. ---- main -----------------------------
  485. ---------------------------------------
  486. -- step 0 info and initial check
  487. term.clear() term.setCursorPos(1,1)
  488. repeat
  489.  print("+-------------------------------------+")
  490.  print("| aTreeFarm "..cVersion..", by Kaikaku (1/2)    |")
  491.  print("+-------------------------------------+")
  492.  print("| Farm set-up: Place crafty felling   |")
  493.  print("|   turtle down (e.g. bottom left     |")
  494.  print("|   corner of chunk). Run program with|")
  495.  print("|   parameter 'setup' (one time).     |")
  496.  print("| Materials for auto set-up:          |")
  497.  print("|   slot 3: chest   (1)               |")
  498.  print("|   slot 4: cobble  (47)              |")
  499.  print("|   slot 5: torches (8)               |")
  500.  print("+-------------------------------------+")
  501.  
  502. if blnAutoSetup then
  503.   if turtle.getItemCount(3)~=1 or turtle.getItemCount(4)<47 or turtle.getItemCount(5)<8 then
  504.   -- inventory not ready for set-up
  505.     strSimpleCheck="Fill in slots 3-5 and press enter:"
  506.   else
  507.     strSimpleCheck="Press enter to start:"
  508.   end
  509. else  
  510.   strSimpleCheck="Press enter to start:"
  511. end
  512. if not blnAskForParameters and strSimpleCheck=="Press enter to start:" then break end
  513. until askForInputText(strSimpleCheck)=="" and strSimpleCheck=="Press enter to start:"
  514.  
  515.  
  516.  
  517. term.clear() term.setCursorPos(1,1)
  518. repeat
  519.  print("+-------------------------------------+")
  520.  print("| aTreeFarm "..cVersion..", by Kaikaku (2/2)    |")
  521.  print("+-------------------------------------+")
  522.  print("| Running the farm:                   |")
  523.  print("|   Felling turtle sits above chest   |")
  524.  print("|   (as after running set-up). Turtle |")
  525.  print("|   needs some initial fuel to start. |")
  526.  print("| Turtle inventory:                   |")
  527.  print("|   slot  1: saplings          (20+x) |")
  528.  print("|   slot  2: wood from sapling (1+x)  |")
  529.  print("|   slot 16: chest             (1)    |")
  530.  print("+-------------------------------------+")
  531.  
  532. if turtle.getItemCount(1)<11 or turtle.getItemCount(2)==0 or turtle.getItemCount(16)~=1 then
  533.   -- inventory not ready
  534.   strSimpleCheck="Provide materials and press enter:"
  535. else  
  536.   strSimpleCheck="Press enter to start:"
  537. end
  538. --strSimpleCheck="Press enter to start:"
  539. if not blnAskForParameters and strSimpleCheck=="Press enter to start:" then break end
  540. if blnAutoSetup then strSimpleCheck="Press enter to start:" end
  541. until askForInputText(strSimpleCheck)=="" and strSimpleCheck=="Press enter to start:"
  542.  
  543.  
  544. ---------------------------------------
  545. ---- set-up farm ----------------------
  546. ---------------------------------------
  547. -- set-up = not running the farm
  548. if blnAutoSetup then
  549.   write("Setting up tree farm...")
  550.   checkRefuel(cMinFuel,cSlotRefuel)
  551.   -- chest
  552.   gf(3) gr() gf(3) gl() ss(3) dd() pd()
  553.   -- path
  554.   ss(4)
  555.   for i=1,9,1 do gf() dd() pd() end gr()
  556.   for i=1,3,1 do gf() dd() pd() end gr()
  557.   for i=1,6,1 do gf() dd() pd() end gl()
  558.   for i=1,3,1 do gf() dd() pd() end gl()
  559.   for i=1,6,1 do gf() dd() pd() end gr()
  560.   for i=1,3,1 do gf() dd() pd() end gr()
  561.   for i=1,9,1 do gf() dd() pd() end gr()
  562.   for i=1,8,1 do gf() dd() pd() end
  563.   -- torches
  564.   ss(5) gf(2) gl() pf() gu() gb(10) pd()
  565.   gl() gf(5) pd() gf() pd() gf(5) pd() gr() gf(11) pd()
  566.   gb(3) gr() gf(3) pd() gf(5) pd() gf(2) gr() gb(2) gd()
  567.   print(" done!")
  568.   print("You can now run the tree farm with: ",cPrgName)
  569.   return
  570. end
  571.  
  572.  
  573. ---------------------------------------
  574. ---- tree farm ------------------------
  575. ---------------------------------------
  576. strC_next=string.sub(strC,1,1)
  577.  
  578. -- initial up
  579. while not turtle.up() do du() end  
  580.  
  581. while true do  
  582.    
  583.   -- step 6 need to craft some fuel?
  584.   craftFuel()
  585.  
  586.   -- step 7 empty into chest
  587.   emptyTurtle()
  588.  
  589.   -- step 0 check exit
  590.   if maxCounter>0 then
  591.     if intCounter==maxCounter then
  592.       print("Completed all ",maxCounter,"  farming rounds.")
  593.       print("I'm awaiting new commands, master!")
  594.       --while not turtle.up() do du() end
  595.       return
  596.     end
  597.   end
  598.  
  599.   -- step 1 check fuel
  600.   checkRefuel(cMinFuel,cSlotRefuel)
  601.  
  602.   -- step 2 wait if redstone signal
  603.   while rs.getInput("back") do
  604.     print("Waiting due to redstone signal ",cWaitingTime,"s.")
  605.     os.sleep(cWaitingTime)
  606.   end
  607.  
  608.   -- step 3 new round
  609.   while not turtle.up() do turtle.sleep(1) du() end
  610.   ss(1)
  611.   intCounter=intCounter+1
  612.   print("Starting round ",intCounter," with "..turtle.getItemCount(1).." saplings.")
  613.  
  614.   for i=1,cLoopEnd,1 do
  615.  
  616.     -- update commands
  617.     strC_now=strC_next
  618.     if i<cLoopEnd then
  619.       strC_next=string.sub(strC,i+1,i+1)
  620.     else
  621.       strC_next=string.sub(strC,1,1)
  622.     end
  623.    
  624.     -- step 4 one step on the road
  625.     tmpResult=eS(strC,i,i)
  626.     if tmpResult~="" then
  627.       print("found special command: "..tmpResult)
  628.     end
  629.    
  630.     -- step 5 check for blocks
  631.     -- step 5.1 check left hand side
  632.     if strC_now~="a" and strC_next~="a" then
  633.       -- now  a=>just turned left
  634.       -- next a=>will turned left
  635.       gl()
  636.       turtle.sleep(1)
  637.       if turtle.detect() then cutTree() end
  638.       gr()
  639.     end
  640.     -- step 5.2 check right hand side
  641.     if strC_now~="d" and strC_next~="d" then   
  642.       -- now  d=>just turned right
  643.       -- next d=>will turn right
  644.       gr()
  645.       turtle.sleep(1)
  646.       if turtle.detect() then cutTree() end
  647.       gl()
  648.     end
  649.     sd()  
  650.    
  651.     if math.random()<=actRandomCheckSapling then
  652.       if strC_now~="d" and strC_now~="a" then  
  653.         randomReplant()
  654.       end
  655.     end
  656.   end
  657. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top