-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
250 lines (225 loc) · 6.33 KB
/
main.lua
File metadata and controls
250 lines (225 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--[[
--NOT FINISHED WORK IN PROGRESS!!!
if you want to cut trees here is the setup
1. turtle on the left side of tree if it is a 2x2
--NOTE-- DO NOT SET THE TURTLE ON THE NORTH OR WEST SIDE OF THE TREE
2. chest the block behind the turtle for saplings
3. chest below the block for wood
4a. first slot is fuel
4b. second slot is wood
4c. third slot is saplings
OPTIONAL -- You can have a collection system for the saplings and put them in the chest
setup for Mining
1. will start one block off the ground on the left side of the area/tunnel
2a. first slot is fuel
2b. second slot is chests
2c. third slot is torches
]]
--local variables
local height = 0
local width = 0
local length = 0
local lastPart = "Down"
local count = 1
local type = "M"
local amount = 0;
--what function do you want the turtle to do
print("Tree felling (T) or mining (M): ")
type = io.read()
--the mining function
if type == "M" then
--gets the mining settings
print("Tunnel height: ")
height = io.read()
print("Tunnel width: ")
width = io.read()
print("Tunnel length (if infinite type \"i\"): ")
length = io.read()
--mines a part horizontaly going in the up direction
local function mineUpPart()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.digUp()
for i = 4, height do
turtle.up()
turtle.digUp()
end
lastPart = "Up"
end
--mines a part horizontaly going in the down direction
local function mineDownPart()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
for i = 4, height do
turtle.down()
turtle.digDown()
end
lastPart = "Down"
end
--mines a slice deep going to the left
local function mineLeftSlice()
if lastPart == "Down" then
mineUpPart()
else
mineDownPart()
end
turtle.turnLeft()
for i = 2, width do
if lastPart == "Down" then
mineUpPart()
else
mineDownPart()
end
end
turtle.turnRight()
end
--mines a slice deep going to the right
local function mineRightSlice()
if lastPart == "Down" then
mineUpPart()
else
mineDownPart()
end
turtle.turnRight()
for i = 2, width do
if lastPart == "Down" then
mineUpPart()
else
mineDownPart()
end
end
turtle.turnLeft()
end
turtle.refuel(1)
if length == "i" then
turtle.select(3)
turtle.placeDown()
while true do
if count % 2 ~= 0 then
mineRightSlice()
else
mineLeftSlice()
end
turtle.select(1)
if turtle.getFuelLevel() < (width * (height - 2)) + 2 then
turtle.refuel(1)
end
count = count + 1
if turtle.getItemCount(16) > 0 and count % 20 ~= 0 then
turtle.select(2)
turtle.placeDown()
for i = 4, 16 do
turtle.select(i)
turtle.dropDown()
end
turtle.select(4)
end
if count % 20 == 0 then
turtle.select(3)
turtle.placeDown()
end
end
else
for i = 1, length do
if i % 2 ~= 0 then
mineRightSlice()
else
mineLeftSlice()
end
turtle.select(1)
if turtle.getFuelLevel() < (width * (height - 2)) + 2 then
turtle.refuel(1)
end
end
end
elseif type == "T" then
local function dock()
turtle.back()
turtle.turnLeft()
turtle.turnLeft()
amount = 64 - turtle.getItemCount(3)
turtle.suck(amount)
for i = 4, 16 do
turtle.select(i)
turtle.dropDown()
end
turtle.turnLeft()
turtle.turnLeft()
turtle.select(3)
end
--for a 2x2 tree it will test for the one log that is one block higher than the rest
turtle.select(1)
turtle.refuel()
local function testForLoneLog()
for i = 1, 4 do
if turtle.compareUp then
turtle.digUp()
end
turtle.forward()
turtle.turnLeft()
end
end
turtle.select(2)
--forever loop
while true do
--tests to see if the tree has grown by comparing the selected slot to the wood in front of it
if turtle.compare() then
turtle.dig()
turtle.forward()
is2x2 = turtle.compare()
if is2x2 == true then
turtle.dig()
while turtle.compareUp() do
turtle.digUp()
turtle.up()
turtle.dig()
count = count + 1
end
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
testForLoneLog()
while turtle.compareDown() do
turtle.digDown()
turtle.down()
turtle.dig()
end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
dock()
turtle.forward()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.back()
turtle.place()
turtle.turnLeft()
turtle.back()
turtle.place()
turtle.select(2)
else
while turtle.compareUp() do
turtle.digUp()
turtle.up()
count = count + 1
end
for i = 1, count do
turtle.down()
end
dock()
turtle.place()
end
turtle.select(2)
count = 0
end
end
end