Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local f;
- local fcfn="fircutstage"
- local fpfn="firrplantstage"
- local mpfn="firmainstage"
- local function saveStagelim(stage,lim,fn)
- local ar={};
- local str;
- if fn== nil then fn="fircutstage" end
- f=fs.open(fn,"w");
- ar[1]=stage;
- ar[2]=lim;
- str=textutils.serialize(ar);
- f.writeLine(str);
- f.close()
- end
- local function getStageLim(fn)
- local ar;
- local str;
- if fn==nil then fn="fircutstage" end
- if not fs.exists(fn) then return 0,0 end
- f=fs.open(fn,"r");
- str=f.readLine();
- f.close()
- ar=textutils.unserialize(str);
- return ar[1],ar[2];
- end
- local function stagedCutTree(init_stage,init_lim)
- local stage=init_stage;
- local lim=init_lim;
- local firstrun=true;
- while stage<12 do
- if stage==0 then turtle.dig();stage=stage+1
- elseif stage==1 then turtle.forward();stage=stage+1
- elseif stage==2 then
- if turtle.detectUp() then stage=stage+1
- else
- stage=6;
- end
- elseif stage==3 then
- turtle.dig();stage=stage+1;
- elseif stage==4 then
- turtle.digUp();stage=stage+1;
- elseif stage==5 then
- turtle.up();
- lim=lim+1;
- stage=2;
- elseif stage==6 then turtle.turnRight();stage=stage+1;
- elseif stage==7 then turtle.dig();stage=stage+1;
- elseif stage==8 then turtle.forward();stage=stage+1;
- elseif stage==9 then turtle.turnLeft();stage=stage+1;
- elseif stage==10 then
- if lim>0 then
- turtle.digDown();turtle.dig();turtle.down();
- lim=lim-1;
- else
- stage=stage+1
- end
- elseif stage== 11 then
- turtle.dig();stage=stage+1
- else
- return
- end
- firstrun=false;
- saveStagelim(stage,lim)
- end
- end
- local function cutTree()
- local lim=0;
- turtle.dig()
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp();turtle.dig();turtle.up();
- lim=lim+1
- end
- turtle.turnRight();turtle.dig();turtle.forward();turtle.turnLeft()
- while lim>0 do
- turtle.digDown();turtle.dig();turtle.down();
- lim=lim-1;
- end
- turtle.dig()
- end
- local function plantTree(stage)
- if stage==nil then stage=1 end
- if stage==0 then stage=1 end
- while stage<22 do
- if (stage==1 ) then turtle.forward();stage=stage+1;
- elseif (stage==2 ) then turtle.select(1);stage=stage+1;
- elseif (stage==3 ) then turtle.place();stage=stage+1;
- elseif (stage==4 ) then turtle.back();stage=stage+1;
- elseif (stage==5 ) then turtle.place();stage=stage+1;
- elseif (stage==6 ) then turtle.turnRight();stage=stage+1;
- elseif (stage==7 ) then turtle.forward();stage=stage+1;
- elseif (stage==8 ) then turtle.turnRight();stage=stage+1;
- elseif (stage==9 ) then turtle.back();stage=stage+1;
- elseif (stage==10) then turtle.back();stage=stage+1;
- elseif (stage==11) then turtle.place();stage=stage+1;
- elseif (stage==12) then turtle.back();stage=stage+1;
- elseif (stage==13) then turtle.place();stage=stage+1;
- elseif (stage==14) then turtle.up();stage=stage+1;
- elseif (stage==15) then turtle.forward();stage=stage+1;
- elseif (stage==16) then turtle.forward();stage=stage+1;
- elseif (stage==17) then turtle.forward();stage=stage+1;
- elseif (stage==18) then turtle.turnLeft();stage=stage+1;
- elseif (stage==19) then turtle.back();stage=stage+1;
- elseif (stage==20) then turtle.turnLeft();stage=stage+1;
- elseif (stage==21) then turtle.down();stage=stage+1;
- end
- saveStagelim(stage,0,fpfn)
- print("stage "..stage)
- end
- end
- local i=0;
- local sel=0;
- local temp=0;
- local fsexists;
- local stage=0;
- local lim;
- local cstage;
- print("Niseg's Fir cutter/planter")
- stage,lim =getStageLim(mpfn)
- --print("1 plant 2 cut")
- --sel= tonumber(read())
- while turtle.getItemCount(1)>4 do
- -- if in the middle of cutting restart cut
- if (stage==0) then
- cstage,lim=getStageLim(fpfn)
- plantTree(cstage)
- stage=stage+1;
- elseif (stage==1) then fs.delete(fpfn);stage=stage+1;
- elseif (stage==2) then turtle.select(1);turtle.up(); stage=stage+1;
- elseif (stage==3) then
- if not turtle.detect() then
- sleep(5)
- else
- stage=stage+1
- end
- elseif (stage==4) then turtle.down(); stage=stage+1
- cstage,lim =getStageLim()
- print("Stage=",cstage," lim= " , lim);
- stagedCutTree(cstage,lim)
- stage=stage+1;
- elseif (stage==5) then
- fs.delete("fircutstage");stage=stage+1;
- elseif(stage==6) then turtle.back();stage=stage+1;
- elseif(stage==7) then turtle.turnRight();stage=stage+1;
- elseif(stage==8) then turtle.back();stage=stage+1;
- elseif(stage==9) then turtle.turnLeft();stage=stage+1;
- elseif(stage==10) then
- if(turtle.getFuelLevel() <300) then turtle.select(2);turtle.refuel(20); end
- for i=2,16 do turtle.select(i);turtle.dropDown(); end
- turtle.select(1)
- stage=0;
- end
- saveStagelim(stage,lim,mpfn)
- --cutTree()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement