This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
warfar's profile picture

Tree Feller program

Started by warfar, 17 December 2012 - 04:39 PM
warfar #1
Posted 17 December 2012 - 05:39 PM
Hello! I made this program today and would like to share it.

To download it (Enable HTTP) type "pastebin get eZnjchhJ tree"
Then type tree for instructions.
IE: tree 20 when there is ALOT of lag
You need to setup a room like mine in order to use the program correctly
http://imgur.com/a/bXAIp
Here is the code:

print("Place saplings in slot 1 and bonemeal in slot 2")
print("Place 1 sapling in slot 13 and 1 bonemeal in slot 14")

local i = 1
local p = 1
local v = 1
local fuel = turtle.getFuelLevel()
local tArgs = { ... }

if #tArgs ~= 1 then
	print("Please rate lag 1-20 (20 being the worst)")
	return
end

local function bonemeal()
  turtle.forward()
  turtle.forward()
  turtle.select(1)
  turtle.place()
  sleep(.1)
  turtle.select(2)
  turtle.place()
  turtle.select(1)
end

local function checkdig()
	turtle.dig()
	turtle.forward()
	while true do
	  if turtle.detectUp() then
		turtle.digUp()
		turtle.up()
		else turtle.down()
		if turtle.detectDown() then
		  turtle.back()
		  turtle.back()
		  turtle.back()
		  break
		end
	  end
	end
end

local function checkfuel()
	term.clear()
	term.setCursorPos(1, 1)
	if turtle.getFuelLevel() < 100 then
	   print("Please add fuel (At least 100)")
	   print("Waiting for fuel, press the E key to refuel")
	   print("Press Q to continue.")
	   print("Press 1-8 to change slots")
	   while true do
	   local event, param1 = os.pullEvent("key")
	   if param1 > 1 and param1 < 10 then
		   local sel = param1 - 1
		   turtle.select(sel)
	   end
		  if param1 == 18 then
			  turtle.refuel()
			  fuel = turtle.getFuelLevel()
			 print(fuel.." Fuel")
		  elseif param1 == 16 and fuel > 100 then
			  print("Fuel Get!"..fuel.." fuel")
			  break
		  end
	   end
	end
end

local lag = tonumber(tArgs[1])

if lag > 20 then
	print("Error:")
	print("Only numbers 1-20")
end

if lag == nil then
	print("Error")
	print("Numbers Only")
	return
else
	print(lag.."Lag")
end

local lag2 = lag + 20
local lag3 = lag2 * 2

while true do


	if turtle.getItemCount(1) <= 4 then
		print("Not enough saplings. Please refill")
		return
	elseif turtle.getItemCount(2) <= 3 then
		print("Not enough bonemeal. Please refill")
		return
	else
	end
	turtle.select(1)
	if turtle.compareTo(13) == false then
		print("Only spalings in slot 1")
		return
	end
	turtle.select(2)
	if turtle.compareTo(14) == false then
		print("Only bonemeal in slot 2")
		return
	end


  checkfuel()
  bonemeal()
  checkdig()
  for i=1, lag3 do
	turtle.suck()
	sleep(1)
	rs.setOutput("bottom", true)
  end
  rs.setOutput("bottom", false)
  sleep(1)
end
Have fun!
Falco #2
Posted 21 December 2012 - 10:26 AM
I like the concept and im currently developing a tree farmer…