-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildtunnel.cc.lua
174 lines (158 loc) · 3.39 KB
/
buildtunnel.cc.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
-- This is buildtunnel
-- It will build a tunnel centered on the turtle going forward
-- it uses 2 building material slots
-- build_slot (1) takes what you want for the floor and solid parts of the tunnel
-- window_slot (2) takes what you want for wall and ceiling window slots (glass)
-- it will build tunnel_len long tunnel at a time.
--
-- version 1.1 2013-07-14
--
-- buildtunnel posted on turtlescripts.com
-- market get gjdhl6 buildtunnel y
local tunnel_len = 8
local build_slot = 1
local window_slot = 3
local junk_slot = 4
local fuel_slot = 16
function checkRefuel()
while turtle.getFuelLevel() == 0 do
turtle.select(fuel_slot)
turtle.refuel(1)
end
end
function resupply(slot,count)
if turtle.getItemCount(slot) < count then
for check_slot = 1,16 do
turtle.select(check_slot)
if check_slot ~= build_slot and
check_slot ~= window_slot
then
if turtle.compareTo(slot)
then
turtle.transferTo(slot)
end
end
end
end
print(turtle.getItemCount(slot).." "..count)
return turtle.getItemCount(slot) >= count
end
function goUp()
while not turtle.up() do
turtle.select(junk_slot)
turtle.digUp()
checkRefuel()
sleep(1)
end
end
function goDown()
while not turtle.down() do
turtle.select(junk_slot)
turtle.digDown()
checkRefuel()
sleep(1)
end
end
function digUp()
turtle.select(junk_slot)
turtle.digUp()
end
function digDown()
turtle.select(junk_slot)
turtle.digDown()
end
function goBack()
if not turtle.back() then
turtle.turnRight()
turtle.turnRight()
goForward()
turtle.turnRight()
turtle.turnRight()
end
end
function goForward()
while not turtle.forward() do
turtle.select(junk_slot)
turtle.dig()
checkRefuel()
sleep(1)
end
end
function place(slot)
turtle.select(slot)
turtle.place()
end
function placeDown(slot)
turtle.select(slot)
turtle.placeDown()
end
function placeUp(slot)
turtle.select(slot)
turtle.placeUp()
end
function doPlaceWall(slot)
turtle.select(slot)
while not turtle.compare() and not turtle.place() do
turtle.select(junk_slot)
turtle.dig()
turtle.select(slot)
end
end
function buildone()
turtle.turnLeft()
-- grab the bottom center block
digUp()
placeDown(build_slot)
goForward()
placeDown(build_slot)
goForward()
placeDown(build_slot)
goBack()
doPlaceWall(build_slot)
goUp()
doPlaceWall(window_slot)
goUp()
doPlaceWall(build_slot)
goUp()
doPlaceWall(build_slot)
goBack()
doPlaceWall(build_slot)
-- grab the top center block
digDown()
goBack()
doPlaceWall(window_slot)
turtle.turnRight()
turtle.turnRight()
doPlaceWall(build_slot)
goDown()
placeUp(build_slot)
doPlaceWall(build_slot)
goDown()
doPlaceWall(window_slot)
goDown()
placeDown(build_slot)
goForward()
placeDown(build_slot)
goBack()
doPlaceWall(build_slot)
goBack()
placeDown(build_slot)
turtle.turnLeft()
end
print("Solid in slot "..build_slot)
print("Window stuff in slot "..window_slot)
print("Fuel in slot "..fuel_slot)
for len = 1,tunnel_len do
while not resupply(build_slot,14) do
print("Need Building materials in slot ".. build_slot)
sleep(5)
end
while not resupply(window_slot,4) do
print("Need Window material in slot "..window_slot)
sleep(5)
end
goForward()
buildone()
end
-- vim: set filetype=lua et sts=2 sw=2 ts=2 sr sta