Advertisement
Niseg

fir farm better recovery 3

Apr 5th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.57 KB | None | 0 0
  1. local f;
  2. local fcfn="fircutstage"
  3. local fpfn="firrplantstage"
  4. local mpfn="firmainstage"
  5. local function saveStagelim(stage,lim,fn)
  6. local ar={};
  7. local str;
  8. if fn== nil then fn="fircutstage" end
  9. f=fs.open(fn,"w");
  10. ar[1]=stage;
  11. ar[2]=lim;
  12. str=textutils.serialize(ar);
  13. f.writeLine(str);
  14. f.close()
  15. end
  16. local function getStageLim(fn)
  17. local ar;
  18. local str;
  19. if fn==nil then fn="fircutstage" end
  20. if not fs.exists(fn) then return 0,0 end
  21. f=fs.open(fn,"r");
  22.  
  23. str=f.readLine();
  24. f.close()
  25.  
  26. ar=textutils.unserialize(str);
  27. return ar[1],ar[2];
  28. end
  29.  
  30. local function stagedCutTree(init_stage,init_lim)
  31. local stage=init_stage;
  32. local lim=init_lim;
  33. local firstrun=true;
  34. while stage<12 do
  35. if stage==0 then turtle.dig();stage=stage+1
  36. elseif stage==1 then turtle.forward();stage=stage+1
  37. elseif stage==2 then
  38.      if turtle.detectUp() then stage=stage+1
  39.      else
  40.         stage=6;
  41.      end
  42. elseif stage==3 then
  43.         turtle.dig();stage=stage+1;
  44. elseif stage==4 then
  45.         turtle.digUp();stage=stage+1;
  46. elseif stage==5 then
  47.         turtle.up();
  48.         lim=lim+1;
  49.         stage=2;
  50. elseif stage==6 then turtle.turnRight();stage=stage+1;
  51. elseif stage==7 then turtle.dig();stage=stage+1;
  52. elseif stage==8 then turtle.forward();stage=stage+1;
  53. elseif stage==9 then turtle.turnLeft();stage=stage+1;
  54. elseif stage==10 then
  55.     if lim>0 then
  56.     turtle.digDown();turtle.dig();turtle.down();
  57.     lim=lim-1;
  58.     else
  59.     stage=stage+1
  60.     end
  61. elseif stage== 11 then
  62.     turtle.dig();stage=stage+1
  63.     else
  64.     return
  65.     end
  66.     firstrun=false;
  67.     saveStagelim(stage,lim)
  68.     end
  69. end
  70.  
  71.  
  72.  
  73.  
  74.  
  75.     local function cutTree()
  76.     local lim=0;
  77.     turtle.dig()
  78.     turtle.forward()
  79.     while turtle.detectUp() do
  80.     turtle.digUp();turtle.dig();turtle.up();
  81.     lim=lim+1
  82.     end
  83.     turtle.turnRight();turtle.dig();turtle.forward();turtle.turnLeft()
  84.     while lim>0 do
  85.     turtle.digDown();turtle.dig();turtle.down();
  86.     lim=lim-1;
  87.     end
  88.     turtle.dig()
  89.     end
  90.  
  91.     local function plantTree(stage)
  92.     if stage==nil then stage=1 end
  93.     if stage==0 then stage=1 end
  94.     while stage<22 do
  95.         if      (stage==1 ) then turtle.forward();stage=stage+1;
  96.         elseif  (stage==2 ) then turtle.select(1);stage=stage+1;
  97.         elseif  (stage==3 ) then turtle.place();stage=stage+1;
  98.         elseif  (stage==4 ) then turtle.back();stage=stage+1;
  99.         elseif  (stage==5 ) then turtle.place();stage=stage+1;
  100.         elseif  (stage==6 ) then turtle.turnRight();stage=stage+1;
  101.         elseif  (stage==7 ) then turtle.forward();stage=stage+1;
  102.         elseif  (stage==8 ) then turtle.turnRight();stage=stage+1;
  103.         elseif  (stage==9 ) then turtle.back();stage=stage+1;
  104.         elseif  (stage==10) then turtle.back();stage=stage+1;
  105.         elseif  (stage==11) then turtle.place();stage=stage+1;
  106.         elseif  (stage==12) then turtle.back();stage=stage+1;
  107.         elseif  (stage==13) then turtle.place();stage=stage+1;
  108.         elseif  (stage==14) then turtle.up();stage=stage+1;
  109.         elseif  (stage==15) then turtle.forward();stage=stage+1;
  110.         elseif  (stage==16) then turtle.forward();stage=stage+1;
  111.         elseif  (stage==17) then turtle.forward();stage=stage+1;
  112.        
  113.         elseif  (stage==18) then turtle.turnLeft();stage=stage+1;
  114.         elseif  (stage==19) then turtle.back();stage=stage+1;
  115.         elseif  (stage==20) then turtle.turnLeft();stage=stage+1;
  116.         elseif  (stage==21) then turtle.down();stage=stage+1;
  117.         end
  118.         saveStagelim(stage,0,fpfn)
  119.         print("stage "..stage)
  120.     end
  121. end
  122.  
  123.  
  124.     local i=0;
  125.     local sel=0;
  126.     local temp=0;
  127.     local fsexists;
  128.     local stage=0;
  129.     local lim;
  130.     local cstage;
  131.     print("Niseg's Fir cutter/planter")
  132.     stage,lim =getStageLim(mpfn)
  133.     --print("1 plant 2 cut")
  134.     --sel= tonumber(read())
  135.     while turtle.getItemCount(1)>4 do
  136.     -- if in the middle of cutting restart cut
  137.     if      (stage==0) then
  138.     cstage,lim=getStageLim(fpfn)
  139.             plantTree(cstage)
  140.             stage=stage+1;
  141.     elseif  (stage==1) then fs.delete(fpfn);stage=stage+1;
  142.     elseif  (stage==2) then turtle.select(1);turtle.up(); stage=stage+1;
  143.     elseif  (stage==3) then
  144.         if not turtle.detect() then
  145.         sleep(5)
  146.         else
  147.         stage=stage+1
  148.         end
  149.     elseif  (stage==4)   then   turtle.down(); stage=stage+1
  150.     cstage,lim =getStageLim()
  151.     print("Stage=",cstage," lim= " , lim);
  152.     stagedCutTree(cstage,lim)
  153.     stage=stage+1;
  154.     elseif (stage==5) then
  155.     fs.delete("fircutstage");stage=stage+1;
  156.     elseif(stage==6)  then turtle.back();stage=stage+1;
  157.     elseif(stage==7) then  turtle.turnRight();stage=stage+1;
  158.     elseif(stage==8) then  turtle.back();stage=stage+1;
  159.     elseif(stage==9)  then turtle.turnLeft();stage=stage+1;
  160.     elseif(stage==10) then
  161.     if(turtle.getFuelLevel() <300) then turtle.select(2);turtle.refuel(20); end
  162.     for i=2,16 do turtle.select(i);turtle.dropDown(); end
  163.     turtle.select(1)
  164.     stage=0;
  165.    
  166.     end
  167.     saveStagelim(stage,lim,mpfn)
  168.     --cutTree()
  169.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement