View difference between Paste ID: QBHnGps7 and D7ZJwd4K
SHOW: | | - or go back to the newest paste.
1
--by ToFran
2
3
local function DigAndForward(times)
4
		times = times or 1
5
		for i = 1,times do
6
			turtle.dig()
7
			turtle.forward()
8
		end
9
end
10
11
local function DigDownAndForward(times)
12
		times = times or 1
13
		for i = 1,times do
14
			turtle.digDown()
15
			turtle.dig()
16
			turtle.forward()
17
		end
18
end
19
20
local function DigUpDownAndForward(times)
21
		times = times or 1
22
		for i = 1,times do
23
			turtle.digUp()
24
			turtle.digDown()
25
			turtle.dig()
26
			turtle.forward()
27
		end
28
end
29
30
31
local function Leftarino()
32
		turtle.turnLeft()
33
		DigAndForward()
34
		turtle.turnLeft()
35
end
36
37
local function Rightarino()
38
		turtle.turnRight()
39
		DigAndForward()
40
		turtle.turnRight()
41
end
42
43
local function SpecialRightarino()
44
		turtle.digUp()
45
		turtle.digDown()
46
		turtle.turnRight()
47
		DigUpDownAndForward()
48
		turtle.turnRight()
49
		DigUpDownAndForward()
50
end
51
52
local function clearConsole()
53
		term.clear()
54
		term.setCursorPos(1,1)
55
end
56
local function MineBase()
57
		DigAndForward(2)
58
		turtle.forward()
59
		Rightarino()
60
		DigDownAndForward(1)
61
		DigUpDownAndForward(2)
62
		DigDownAndForward(1)
63
		Leftarino()
64
		DigAndForward(1)
65
		DigUpDownAndForward(4)
66
		Rightarino()
67
		DigAndForward(1)
68
		DigUpDownAndForward(4)
69
		Leftarino()
70
		DigAndForward(1)
71
		DigUpDownAndForward(4)
72
		Rightarino()
73
		DigAndForward(3)
74
		-- 2 layer
75
		turtle.up()
76
		turtle.up()
77
		turtle.turnRight()
78
		DigAndForward(2)
79
		turtle.turnLeft()
80
		DigAndForward(1)
81
		Rightarino()
82
		DigAndForward(1)
83
		turtle.turnLeft()
84
		DigAndForward(1)
85
		Rightarino()
86
		DigAndForward(1)
87
		turtle.turnLeft()
88
		DigAndForward(1)
89
		Rightarino()
90
		DigAndForward(1)
91
		turtle.turnLeft()
92
		turtle.dig()
93
		turtle.turnRight()
94
end
95
96
local function UpLoop(times)
97
		times = times or 1
98
		for i = 1,times do
99
			turtle.digUp()
100
			turtle.up()
101
			turtle.dig()
102
		end
103
end
104
105
local function DownLoop(times)
106
		times = times or 1
107
		for i = 1,times do
108
			turtle.digDown()
109
			turtle.down()
110
			turtle.dig()
111
		end
112
end
113
114
local function LoopDerivation()
115
		turtle.turnLeft()
116
		DigAndForward(3)
117
		Rightarino()
118
		DigAndForward(3)
119
end
120
121
local function MineDerivation()
122
		turtle.digUp()
123
		turtle.up()
124
		LoopDerivation()
125
		LoopDerivation()
126
		LoopDerivation()
127
		LoopDerivation()
128
end
129
130
local function GoToTheOtherSideOfTheLogOnTop()
131
		turtle.turnRight()
132
		DigAndForward()
133
		turtle.turnLeft()
134
		turtle.dig()
135
end
136
137
local function GoToTheOtherSideOfTheLogOnBottom()
138
		turtle.turnLeft()
139
		DigAndForward()
140
		turtle.turnRight()
141
		turtle.dig()
142
end
143
144
145
local function RemoveRootAndCreateItemCavity()
146
		turtle.digDown()
147
		turtle.down()
148
		turtle.digDown()
149
		turtle.down()
150
		DigDownAndForward(2)
151
		SpecialRightarino()
152
		DigDownAndForward(2)
153
		turtle.turnRight()
154
		DigDownAndForward(3)
155
		turtle.turnRight()
156
		DigDownAndForward(3)
157
		SpecialRightarino()
158
		DigDownAndForward(2)
159
end
160
161
local function PlaceAndforward(times)
162
		times = times or 1
163
		for i = 1,times do
164
			turtle.placeDown()
165
			turtle.forward()
166
		end
167
end
168
169
local function Replant()
170
		turtle.up()
171
		turtle.up()
172-
		--
172+
173
		turtle.select(16) -- Select the dirt
174-
		print("Sleeping to allow items to flow.")
174+
175-
		clearConsole()
175+
176-
		sleep(10)
176+
177
		turtle.turnLeft()
178-
		--
178+
179
		turtle.turnLeft()
180
		PlaceAndforward(2)
181
		turtle.turnRight()
182
		PlaceAndforward(1)
183
		turtle.turnRight()
184
		PlaceAndforward(2)
185
		turtle.turnLeft()
186
		PlaceAndforward(1)
187
		turtle.turnLeft()
188
		PlaceAndforward(3)
189
		turtle.placeDown()
190
		-- End of Placing Dirt, lets plant!
191
		turtle.up()
192
		turtle.turnLeft()
193
		turtle.forward()
194
		turtle.turnLeft()
195
		turtle.forward()
196
		turtle.select(15) -- Select The Saplings
197
		PlaceAndforward(1)
198
		turtle.turnRight()
199
		PlaceAndforward(1)
200
		turtle.turnRight()
201
		PlaceAndforward(1)
202
		turtle.placeDown()
203
end
204
205
local function GoToChest()
206
	turtle.turnLeft()
207
	DigAndForward(2)
208
	turtle.turnLeft()
209
	DigAndForward(8)
210
	-- Drop The Wood
211
	turtle.select(1)
212
	turtle.drop()
213
	turtle.select(2)
214
	turtle.drop()
215
	turtle.select(3)
216-
	DigAndForward(10)
216+
217
	turtle.select(4)
218
	turtle.drop()
219
	turtle.select(5) 
220
	turtle.drop() -- Drop remaining dirt
221
	turtle.select(1)
222
	-- Go to the chopping spot
223
	turtle.turnRight()
224
	turtle.turnRight()
225
	DigAndForward(6)
226
	turtle.down()
227
end
228
229
local function TreeCheck()
230
		notreeWarning = 0
231
        turtle.select(1)
232
        while turtle.compare() do
233
			sleep(1)
234
			if notreeWarning==0 then
235
				print("No tree detected, waiting...")
236
				notreeWarning = 1
237
			end
238
        end
239
		if notreeWarning==1 then
240
			print("Detected! Chopping started.")
241
		end
242
end
243
				
244
-- UI Stuff
245
clearConsole()
246
print("Rainbow Tree Chopper by ToFran\nChoose one of the following options:\n [1] Chop down the tree.\n [2] Start the tree farm.")
247
local input = read()
248
clearConsole()
249
250
if input=="1" then -- Chop down the tree.
251
	if turtle.getFuelLevel() > 155 then
252
		write("Fuel level is ")
253
		write(turtle.getFuelLevel())
254
		write("\n")
255
		MineBase()
256
		UpLoop(6)
257
		MineDerivation()
258
		UpLoop(4)
259
		MineDerivation()
260
		UpLoop(10)
261
		GoToTheOtherSideOfTheLogOnTop()
262
		DownLoop(27)
263
		GoToTheOtherSideOfTheLogOnBottom()
264
		UpLoop(2)
265
		turtle.back()
266
	else
267
		print("Not enough fuel :(")
268
	end
269
elseif input=="2" then
270
	if turtle.getFuelLevel() > 200 then
271
		print("Please place dirt on slot 16 and rainbow saplings on slot 15. \nPress enter to continue...")	
272
		local input = read()	
273
			while true do -- Its an farm, so its infinite :P
274
				if turtle.getItemCount(15) < 4 or turtle.getItemCount(16) < 1 then
275
				print("Unable to continue, lack of resources\nTerminating!")
276
				print(turtle.getItemCount(15))
277
				print(turtle.getItemCount(16))
278
				return
279
				end
280
				
281
				clearConsole()
282
				write("Fuel level is ")
283
				write(turtle.getFuelLevel())
284
				write("\n")
285
				TreeCheck() -- Sleeps the program until a tree is detected
286
				MineBase()
287
				UpLoop(6)
288
				MineDerivation()
289
				UpLoop(4)
290
				MineDerivation()
291
				UpLoop(10)
292
				GoToTheOtherSideOfTheLogOnTop()
293
				DownLoop(24)
294
				RemoveRootAndCreateItemCavity()
295
				Replant()
296
				GoToChest()
297
			end		
298
	else
299
		print("Not enough fuel :(")
300
	end
301
end
302
303
write("Remaining fuel: ")
304
write(turtle.getFuelLevel())
305
write("\n")
306
307
308
--by ToFran