-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrip.lua
248 lines (222 loc) · 5.7 KB
/
strip.lua
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
--[[
Created by: Just1689, Squire, Earv1
Lots of snippets take from farmer.lua (see notes)
]]--
-- TODO
-- ~~NOW~~
-- Go left or right
-- ~~LATER~~
-- refuel from fuel chest
-- refuel torches
-- ~~MUCH LATER~~
-- go get diamons if found
local INVENTORY_SIZE = 16
local length = 0
local deep = 0
local SLEEP_NO_TORCHES = 3
local REFUEL_MIN = 1000
local tileCount = 0
local tileColCount = 0
local tilesWalked = 0
local dir = 0
if #arg == 3 then
length = tonumber(arg[1])
deep = tonumber(arg[2])
dir = tonumber(arg[3])
else
print("Please enter the length SPACE width SPACE direction (1 for left, 2 for right)")
return
end
local TORCHES = {
"minecraft:torch"
}
local ACCEPTED_FUELS = {
"minecraft:coal_block",
"minecraft:coal",
"minecraft:dried_kelp_block",
"minecraft:charcoal"
}
function getTorchesCount()
local torchesCount = 0
for i = 1, INVENTORY_SIZE do
local currentItem = turtle.getItemDetail(i)
if currentItem ~= nil then
for x = 1, #TORCHES do
if currentItem.name == TORCHES[x] then
torchesCount = torchesCount + turtle.getItemCount(i)
end
end
end
end
return torchesCount
end
function checkTorchesCount()
local torchesCount = getTorchesCount()
if torchesCount <= 0 then
print("Out of torches, waiting for torches to be added. Checking for seeds every ".. SLEEP_NO_TORCHES .." seconds.")
return false
end
return true
end
function plantTorches()
for i = 1, INVENTORY_SIZE do
local currentItem = turtle.getItemDetail(i)
if currentItem ~= nil then
for x = 1, #TORCHES do
if currentItem.name == TORCHES[x] then
turtle.select(i)
turtle.placeDown()
turtle.select(1)
break
end
end
end
end
end
function goHomeRow()
print("Going home...")
turnAround()
for i = 0, tilesWalked - 1 do
turtle.forward()
end
turnAround()
print("I am home...")
tilesWalked = 0
end
function dumpInventory()
for i = 1, INVENTORY_SIZE do
local currentItem = turtle.getItemDetail(i)
if currentItem ~= nil then
local isFuel = false
local isTorch = false
for x = 1, #TORCHES do
if currentItem.name == TORCHES[x] then
isTorch = true
break
end
end
for x = 1, #ACCEPTED_FUELS do
if currentItem.name == ACCEPTED_FUELS[x] then
isFuel = true
break
end
end
if not isTorch and not isFuel then
turtle.select(i)
while turtle.dropDown() == false do
print("No room in target inventory, please clear some space. Checking target inventory every ".. SLEEP_NO_TORCHES .." seconds.")
sleep(SLEEP_NO_TORCHES)
end
turtle.select(1)
end
end
end
end
function isLava()
local isBlock, block = turtle.inspect()
if isBlock ~= false then
if block.name == "minecraft:lava" then
return true
end
end
isBlock, block = turtle.inspectUp()
if isBlock ~= false then
if block.name == "minecraft:lava" then
return true
end
end
end
function isGravel()
local isBlock, block = turtle.inspect()
if isBlock ~= false then
if block.name == "minecraft:gravel" then
return true
end
end
isBlock, block = turtle.inspectUp()
if isBlock ~= false then
if block.name == "minecraft:gravel" then
return true
end
end
end
function turnAround()
turtle.turnLeft()
turtle.turnLeft()
end
function turnToRow()
if dir == 1 then
turtle.turnLeft()
elseif dir == 2 then
turtle.turnRight()
end
end
function doColumn()
turtle.select(1)
print("Total fuel " .. turtle.getFuelLevel())
for c = 1, deep do
-- 3n - 2
next = (3 * c) - 2
print("next row is at " .. next)
for spaces = 1, next do
turtle.dig()
turtle.digUp()
turtle.forward()
tileColCount = tileColCount + 1
end
turnToRow()
print("now showing row " .. c)
--- do that rows
doRow()
goHomeRow()
-- go to home
turnToRow()
for spaces = 1, tileColCount do
turtle.forward()
end
turnAround()
tileColCount = 0
print("now at home position " .. c)
dumpInventory()
-- sleep(5)
end
end
function doRow()
tilesWalked = 0
tileCount = 0
for i = 0, length do
tilesWalked = tilesWalked + 1
local okTorches = checkTorchesCount()
if not okTorches then
print("no torches.. going home")
tilesWalked = tilesWalked - 1
break
end
if isLava() then
print("found lava.. going home")
tilesWalked = tilesWalked - 1
break
end
if isGravel() then
print("found gravel.. going home")
tilesWalked = tilesWalked - 1
break
end
turtle.dig()
turtle.digUp()
turtle.digDown()
tileCount = tileCount + 1
if tileCount == 6 then
tileCount = 0
plantTorches()
end
turtle.forward()
end
end
if turtle.getFuelLevel() < REFUEL_MIN then
print("trying to refuel")
turtle.refuel()
else
print("not going to refuel")
end
doColumn()