View difference between Paste ID: YSfqfygc and mHU0Uhb6
SHOW: | | - or go back to the newest paste.
1
--pastebin:YSfqfygc
2
3
local wood, sapling = 1, 2
4
local treeHeight = 0
5
local treeCount = 0
6
local plantCount = 6
7-
	while turtle.getFuelLevel() < 200 do
7+
local rowCount = 1
8-
		turtle.select(wood) --charcol in this slot
8+
local pauseLength = 60
9-
		turtle.refuel(1)
9+
10-
		print("Refueled")
10+
11-
	end
11+
    while turtle.getFuelLevel() < 200 do
12-
	print( "Fuel Level: ", turtle.getFuelLevel() )
12+
        turtle.select(wood) --charcol in this slot
13
        turtle.refuel(1)
14
        print("Refueled")
15
    end
16-
	while not turtle.forward() do
16+
    print( "Fuel Level: ", turtle.getFuelLevel() )
17-
		-- turtle blocked from moving forward
17+
18-
		print( "Turtle blocked from moving forward" )
18+
19-
		sleep(3) -- wait 3 seconds to let mob move away
19+
20-
	end
20+
    while not turtle.forward() do
21
        -- turtle blocked from moving forward
22
        print( "Turtle blocked from moving forward" )
23
        sleep(3) -- wait 3 seconds to let mob move away
24-
	for i = 1, 4 do
24+
    end
25-
		turtle.turnLeft()
25+
26-
		turtle.suck()
26+
27-
	end
27+
28-
	turtle.suckUp() -- in case a sapling fell on turtle's head:D
28+
    for i = 1, 4 do
29
        turtle.turnLeft()
30
        turtle.suck()
31
    end
32
    turtle.suckUp() -- in case a sapling fell on turtle's head:D
33
end
34-
	tRefuel()
34+
35-
	print( "Tree Count: ", treeCount )
35+
local function harvestTree()
36-
	-- check all trees for any that have grown
36+
    treeCount = treeCount + 1
37-
	for i = 1, plantCount do
37+
    while turtle.compare() do
38-
		turtle.turnRight()
38+
        turtle.dig()
39-
		turtle.select(wood)
39+
        if turtle.detectUp() then
40-
		-- if the tree has grown
40+
            turtle.digUp()
41-
		if turtle.compare() then
41+
        end
42-
			-- harvest the tree
42+
        turtle.up()
43-
			treeCount = treeCount + 1
43+
        treeHeight = treeHeight + 1
44-
			while turtle.compare() do
44+
    end
45-
				turtle.dig()
45+
    -- return to the ground
46-
				if turtle.detectUp() then
46+
    -- if blocked, dig
47-
					turtle.digUp()  
47+
    while treeHeight > 0 do
48-
				end
48+
        if turtle.down() then
49-
				turtle.up()
49+
            treeHeight = treeHeight - 1
50-
				treeHeight = treeHeight + 1
50+
        else
51-
			end
51+
            turtle.digDown()
52-
			-- return to the ground
52+
        end
53-
			-- if blocked, dig
53+
    end
54-
			while treeHeight > 0 do
54+
55-
				if turtle.down() then
55+
56-
					treeHeight = treeHeight - 1
56+
57-
				else
57+
local function moveNextTree()
58-
					turtle.digDown()
58+
    for i=1,4 do
59-
				end
59+
        tVacume()
60-
			end
60+
        tF()
61-
			-- plant a new sapling
61+
    end
62-
			turtle.select(sapling)
62+
63-
			turtle.place()
63+
64-
		else
64+
function harvestRow()
65-
			turtle.select(sapling)
65+
    tF()
66-
			if not turtle.compare() then
66+
    -- check all trees for any that have grown
67-
				turtle.place()
67+
    for i = 1, plantCount do
68-
			end
68+
        turtle.turnRight()
69-
		end
69+
        turtle.select(wood)
70-
		-- move to next tree location
70+
        -- if the tree has grown
71-
		turtle.turnLeft()
71+
        if turtle.compare() then
72-
		tVacume()
72+
            -- harvest the tree
73-
		tF()
73+
            harvestTree()
74-
		tVacume()
74+
75-
		tF()
75+
            -- plant a new sapling
76-
		tVacume()
76+
            turtle.select(sapling)
77-
		tF()
77+
            turtle.place()
78-
		tVacume()
78+
        else
79-
		tF()
79+
            turtle.select(sapling)
80-
		tVacume()
80+
            if not turtle.compare() then
81-
	end
81+
                turtle.place()
82-
	-- round the corner
82+
            end
83-
	tF()
83+
        end
84-
	-- dump excess items into chest if a chest is present
84+
        -- move to next tree location
85-
	if turtle.detect() then
85+
        turtle.turnLeft()
86-
		for i = 3, 16 do
86+
87-
			turtle.select(i)
87+
        if i < plantCount then
88-
			turtle.drop()
88+
            moveNextTree()
89-
		end
89+
        end
90-
		print( "Dropped off Excess Items")
90+
    end
91-
	end
91+
    -- round the corner
92-
	turtle.turnRight()
92+
    tF()
93-
	tF()
93+
    turtle.turnRight()
94-
	tF()
94+
    tF()
95-
	turtle.turnRight()
95+
    tF()
96-
	tF()
96+
    turtle.turnRight()
97-
	sleep(60) -- wait for trees to grow and saplings to fall
97+
    tRefuel()
98
end
99
100
local function returnRow()
101
    tF()
102
    for i = 1, plantCount-1 do
103
        moveNextTree()
104
    end
105
    tF()
106
    turtle.turnRight()
107
    tF()
108
    tF()
109
    turtle.turnRight()
110
end
111
112
113
local function dumpExcess()
114
    turtle.turnRight()
115
    turtle.turnRight()
116
    -- dump excess items into chest if a chest is present
117
    if turtle.detect() then
118
        for i = 3, 16 do
119
            turtle.select(i)
120
            turtle.drop()
121
        end
122
        print( "Dropped off Excess Items")
123
    end
124
    turtle.turnRight()
125
    turtle.turnRight()
126
end
127
128
local function moveNextRow()
129
    turtle.turnRight()
130
    for i=1,4 do
131
        tF()
132
    end
133
    turtle.turnLeft()
134
end
135
136
local function returnToStart()
137
    turtle.turnLeft()
138
    for row = 1,rowCount-1 do
139
        for i=1,4  do
140
            tF()
141
        end
142
    end
143
    turtle.turnRight()
144
end
145
146
147
-- main loop
148
print( "Tree Area (plants x rows): ", plantCount, " x ", rowCount )
149
while true do
150
    tRefuel()
151
    for row = 1,rowCount do
152
        harvestRow()
153
        returnRow()
154
        if (row < rowCount) then
155
            moveNextRow()
156
        end
157
    end
158
    returnToStart()
159
    print( "Tree Count: ", treeCount )
160
    dumpExcess()
161
    sleep(pauseLength) -- wait for trees to grow and saplings to fall
162
end