Skip to content

Instantly share code, notes, and snippets.

@tomjn
Created May 27, 2013 14:32
Show Gist options
  • Select an option

  • Save tomjn/5657380 to your computer and use it in GitHub Desktop.

Select an option

Save tomjn/5657380 to your computer and use it in GitHub Desktop.
Computercraft tree farm chops down and grows a tree given saplings and bonemeal, place a chest underneath
local slots ={}
function plantTree()
turtle.select(1)
turtle.place()
end
function chopTree()
turtle.select(4)
turtle.dig()
turtle.forward()
while turtle.detectUp() do
turtle.digUp()
turtle.up()
end
while not turtle.detectDown() do
turtle.down()
end
turtle.back()
end
function hasTreeGrown()
turtle.select(3)
return turtle.compare()
end
function bonemealTree()
turtle.select(2)
turtle.place()
end
function dropOffResources()
for i=4, 16, 1 do
turtle.select( i )
turtle.dropDown( 64 )
end
end
function checkSlot( slot )
if turtle.getItemCount(2) == 0 then
if slots[ slot ] == true then
print( "Slot " + slot + " empty" )
slots[ slot ] = false
end
else
slots[ slot ] = true
end
end
while true do
if hasTreeGrown() then
chopTree()
dropOffResources()
else
plantTree()
bonemealTree()
end
sleep(1)
checkSlot( 1 )
checkSlot( 2 )
checkSlot( 3 )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment