Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local f;
- local function saveStagelim(stage,lim)
- local ar={};
- local str;
- f=fs.open("fircutstage","w");
- ar[1]=stage;
- ar[2]=lim;
- str=textutils.serialize(ar);
- f.writeLine(str);
- f.close()
- end
- local function getStageLim()
- local ar;
- local str;
- if not fs.exists("fircutstage") then return 0,0 end
- f=fs.open("fircutstage","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()
- turtle.forward()
- turtle.select(1)
- turtle.place()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turtle.back()
- turtle.back()
- turtle.place()
- turtle.back()
- turtle.place()
- turtle.up()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- turtle.back()
- turtle.turnLeft()
- turtle.down()
- end
- local i=0;
- local sel=0;
- local temp=0;
- local fsexists;
- fsexists=fs.exists("fircutstage");
- --print("1 plant 2 cut")
- --sel= tonumber(read())
- while turtle.getItemCount(1)>4 do
- -- if in the middle of cutting restart cut
- if(turtle.detectDown()) then
- if(not turtle.detect()) then plantTree() end
- turtle.select(1)
- turtle.up()
- end
- while not turtle.detect() do
- --if(turtle.getItemCount(1)<32) then
- --turtle.turnRight();turtle.suck();turtle.turnRight();turtle.suck();
- --turtle.turnRight();turtle.suck();turtle.turnRight();turtle.suck();
- --else
- if(fsexists) then break end
- sleep(5)
- --end
- end
- if not fsexists then turtle.down() end
- --cutTree()
- fsexists=false;
- local stage,lim;
- stage,lim =getStageLim()
- print("Stage=",stage," lim= " , lim);
- stagedCutTree(stage,lim)
- fs.delete("fircutstage");
- turtle.back();turtle.turnRight();turtle.back();turtle.turnLeft()
- 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)
- end
- --cutTree()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement