View difference between Paste ID: mJ1S30HC and 51sidpt8
SHOW: | | - or go back to the newest paste.
1
2
-- 
3
-- slots: seeds, fuel
4
-- maybe use glass slabs and an ender chest
5
6
7
local plotLength = 8
8
local plotWidth = 8
9
local harvestTime = 15
10
local growTime = 900
11
12
local useChest = false
13
14
local function wait(secs)
15
	for sec = secs, 0, -5 do
16
		term.clear()
17
		term.setCursorPos(1,1)
18
		print(sec)
19
		sleep(5)
20
	end
21
	term.clear()
22
end
23
24
local function resetPosition()
25
	repeat until not turtle.up()
26
	repeat until not turtle.forward()
27-
	repeat until not turtle.detect()
27+
	while turtle.detect() do turtle.turnRight() end
28
29
	while not rs.getInput("left") do
30
		if not turtle.forward() then
31
			turtle.turnRight()
32
		end
33
	end
34
end
35
36
local function dropExcess()
37
	for slot = 1, 16 do
38
		if turtle.getItemCount(slot) ~= 0 then
39
			turtle.select(slot)
40
			if slot == 1 then
41
				turtle.drop(turtle.getItemCount(slot) - 1)
42
			elseif slot ~= 2 then
43
				turtle.drop()
44
			end
45
		end
46
		sleep(0)
47
	end
48
	turtle.select(1)
49
end
50
51
local function harvest()
52
	rs.setOutput("top", true)
53
	wait(harvestTime)
54
	rs.setOutput("top", false)
55
56
	if useChest then
57
		repeat until turtle.forward()
58
		turtle.turnLeft()
59
		dropExcess()
60
		turtle.turnRight()
61
	end
62
63
	repeat until not turtle.forward()
64
	turtle.down()
65
	repeat until not turtle.suckDown()
66
	turtle.up()
67
	turtle.back()
68
	turtle.turnRight()
69
end
70
71
local function plant()
72
73
	turtle.select(1)
74
	local curX
75
	local curY
76
77
	curY = 1
78
	while curY <= plotLength do
79
	curX = 1
80
	while curX <= plotWidth do
81
82
		if turtle.getItemCount(1) > 1 then
83
			turtle.placeDown()
84
		end
85
86
		if curX == plotWidth then
87
			if curY < plotLength then
88
				if curY % 2 == 1 then
89
					turtle.turnRight()
90
					repeat until turtle.forward()
91
					turtle.turnRight()
92
				else
93
					turtle.turnLeft()
94
					repeat until turtle.forward()
95
					turtle.turnLeft()
96
				end
97
			end
98
		else
99
			repeat until turtle.forward()
100
		end
101
102
	curX = curX + 1
103
	end
104
	curY = curY + 1
105
	end
106
107
end
108
109
while turtle.getItemCount(1) ~= 0 do
110
111
	turtle.select(1)
112
	while turtle.getFuelLevel() < 128 do
113
		while turtle.getItemCount(2) < 2 do
114
			print("Out of Fuel")
115
			sleep(1)
116
		end
117
		turtle.select(2)
118
		turtle.refuel(1)
119
		turtle.select(1)
120
	end
121
122
	resetPosition()
123
	harvest()
124
	plant()
125
	wait(growTime)
126
127
128
end