local a=require("robot")local b=require("component")local c=b.tractor_beam local d=b.inventory_controller local e="minecraft:sapling"local f=0 local g="minecraft:dye"local h=15 local i=false local function j()print("#--------------------------------#")print("# Tree Chopping Program exited. #")os.exit()end local function k(t,u)for v=1,16 do local w=d.getStackInInternalSlot(v)if(w~=nil and w.name==t and w.damage==u)then a.select(v)return true end end return false end local function l(t,u)local v=k(t,u)if i and not v then print("Out of "..t..", exiting.")j()end while not v do print("Cannot find "..t.." in inventory. Please add some, and press enter.")io.read()v=k(t,u)end end local function m()l(e,f)local t=a.place()while not t do print("Unable to place the sapling. Please remove any blocks in front of the robot, and press enter.")io.read()t=a.place()end end local function n()local t,u=a.detect()while u~="solid"do l(g,h)a.place()t,u=a.detect()end end local function o()local t=a.durability()if i and(t==nil or t<0.1)then print("Inadequate tool to chop trees, exiting.")j()end while(t==nil)or(t<0.1)do print("Please ensure that a lumber axe with at least 10% durability is equipped in the tool slot, and press enter.")io.read()t=a.durability()end a.swing()end local function p()local t=c.suck()while t do t=c.suck()end end local function q()m()n()end local function r()q()o()os.sleep(2)p()end local function s()print("# Andrew's Tree Chopping Program #")print("# Copyright 2018 Andrew Lalis #")print("#--------------------------------#")print("Please enter the number of trees to chop, or -1 to chop until out of resources.")local t=tonumber(io.read())if(t==nil or t==-1)then i=true print(" Chopping trees until out of resources.")while i do r()end else print(" Chopping "..t.." trees.")for u=1,t do r()end end j()end s()