Advertisement
Niseg

better recovery fir cutter

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