View difference between Paste ID: 5uf2DFRa and RaeRwV0r
SHOW: | | - or go back to the newest paste.
1
--[[ Running this script on a turtle with saplings in slot 1, bone-meal in slot 2 and coal in slot 16 and a chest behind the turtle for the wood drop off point will create an automatic tree farm. combining this with a chest to the left of the turtle for sapling replenishment and chest to the right for coal replenishment will ensure a long running automated process.]]
2
3
print("Sup, Made By TEC_NO!")
4
sleep(1)
5
shell.run('clear')
6
print("Biff The Auto Tree Farmer, Made By TEC_NO!")
7
os.setComputerLabel("Biff The Farmer, By TEC_NO!")
8
label = ("Biff The Farmer, By TEC_NO!")
9
10
-- This function lays saplings and applies bone-meal
11
function plant()
12
	turtle.select(1)				--selects sapling
13
	turtle.place()					--places sapling
14
	turtle.select(2)				--selects bone-meal
15
	turtle.place()					--fertilizes sapling
16
	turtle.suck()					--picks up any saplings that have fallen
17
end
18
19
-- This function checks fuel level and refuels
20
function fuel()
21
	if turtle.getFuelLevel() < 50 then		--checks fuel level and refuels
22
		turtle.select(16)
23
		turtle.refuel(5)			--picks up any saplings that have fallen
24
	end
25
	print( turtle.getFuelLevel() .. " fuel left.")	--displays fuel level to user
26
end
27
28
-- This function cuts a column directly above the turtle and then returns to ground level
29
function column()
30
	while turtle.detectUp() == true do 		--cut tree down
31
		turtle.digUp()
32
		turtle.up()
33
		turtle.suck()				--picks up any saplings that have fallen
34
	end
35
	while turtle.detectDown() == false do		-- return to ground level
36
		turtle.down()
37
		turtle.suck()				--picks up any saplings that have fallen
38
	end
39
end
40
41
-- This function moves from start position, runs column and returns to start position
42
function fell()
43
	turtle.dig()					--breaks bottom block of tree
44
	turtle.forward()				--move into gap
45
	column()					--run column function
46
	turtle.turnRight()				--return to start
47
	turtle.turnRight()
48
	turtle.forward()
49
end
50
51
-- This function empties all collected wood into chest, checks sapling and fuel supplies and restocks
52
function empty()
53
	for j = 3, 15 do				-- empty slots 3 to 15 into chest
54
		turtle.select(j)
55
		turtle.drop()
56
	end
57
	turtle.turnLeft()
58
	if turtle.getItemCount(16) < 5 then		-- replenish fuel stocks
59
		turtle.select(16)
60
		turtle.suck(10)
61
	end
62
	turtle.turnLeft()
63
	if turtle.getItemCount(1) < 5 then		--replenish sapling stocks 
64
		turtle.turnLeft()
65
		turtle.select(1)
66
		turtle.suck()
67
		turtle.turnRight()
68
	end
69
end
70
71
-- This function checks to see if the sapling has been fertilized into a full tree
72
function compare()
73
	turtle.select(1)
74
	if turtle.compare() == true then
75
		return true	-- false could indicate that there is no bonemeal or saplings
76
	else
77
		return false  
78
	end
79
end
80
81
-- This block triggers the appropriate functions in the correct order.
82
repeat							--start loop
83
	fuel()						--check fuel
84
	plant()						--plant and fertilize tree
85
	fuel()						--check fuel again
86
	if compare() == false then			--if tree has grown cut down tree
87
		fell()
88
	else 						--if tree hasn't grown display error
89
		print("error")
90
		repeat
91
			sleep(1)
92
			turtle.select(2)
93
		until turtle.getItemCount() > 20	--this will terminate script
94
	end 
95
	empty()						--empty harvest and restock fuel and materials
96
until 1 > 2						-- always false creating infinite loop