-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunbuild.lua
333 lines (296 loc) · 6.74 KB
/
unbuild.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
os.loadAPI("JoshAPI.lua")
local tArgs = { ... }
function getArg(num)
a = JoshAPI.parse(tArgs[num])
if a == nil then
print("Arugments error")
print("Use unbuild with no arguments if you don't know what you're doing")
error()
end
return a
end
function slot()
function slotsHaveSpace()
for n=1,16 do
if turtle.getItemSpace(n) > 0 then
return true
end
end
turtle.select(1)
return false
end
if not slotsHaveSpace() then
print("Empty inventory to continue.")
while not slotsHaveSpace() do
sleep(1)
end
end
end
function inputNum()
a = io.read()
a = tonumber(a)
if a == nil or a <=0 then
print("Number error")
error()
else
return a
end
end
function inputStr()
a = io.read()
a = tostring(a)
if a == nil then
print("String error")
error()
else
return string.lower(a)
end
end
function line(L)
for i=1,L-1 do
slot()
JoshAPI.forwardA()
end
end
function lineUp(H,goDown)
for i=1,H-1 do
slot()
JoshAPI.upA()
end
if goDown then
lineDown(H)
end
end
function lineDown(H)
for i=1,H-1 do
slot()
JoshAPI.downA()
end
end
function stairsUp(H)
for i=1,H-1 do
slot()
turtle.digDown()
JoshAPI.upA()
JoshAPI.forwardA()
end
slot()
turtle.digDown()
end
function stairsDown(H)
for i=1,H-1 do
slot()
turtle.digDown()
JoshAPI.forwardA()
JoshAPI.downA()
end
slot()
turtle.digDown()
end
function wallA(L,H)
for i=1, math.floor((L)/2) do --math.floor((L-1)/2)
lineUp(H, false)
JoshAPI.forwardA()
lineDown(H)
if i == math.floor((L)/2) then --on last one
if L%2 == 1 then
JoshAPI.forwardA()
end
else
JoshAPI.forwardA()
end
end
if L%2 == 1 then
lineUp(H, true)
end
end
function wallB(L,H)
JoshAPI.upA()
for i=1,H-1 do
line(L)
JoshAPI.upA()
turtle.turnRight()
turtle.turnRight()
end
line(L)
end
function box(D,W,H,makeRoof)
function getDown()
for x=1,H-1 do
JoshAPI.downA()
end
end
for i=1,W do
wallA(D, H)
if i%2 == 1 then
turtle.turnRight()
JoshAPI.forwardA()
turtle.turnRight()
elseif i%2 == 0 then
turtle.turnLeft()
JoshAPI.forwardA()
turtle.turnLeft()
end
end
end
function platform(D,W)
for i=1,W-1 do
line(D)
if i%2 == 1 then
turtle.turnRight()
JoshAPI.forwardA()
turtle.turnRight()
elseif i%2 == 0 then
turtle.turnLeft()
JoshAPI.forwardA()
turtle.turnLeft()
end
end
line(D)
end
JoshAPI.cleanTerm()
if #tArgs == 0 then
doText = true
else
doText = false
end
if doText then
print("Shape unmaker")
print("Warning: This program is mostly untested")
print("Fuel in slot 1")
print("Materials will be in slots 2-16")
print("-----------------------")
print("What Shape?")
print("Options:")
print("line, wallA, wallB, box, platform, stairs, stairsDown, lineUp")
choice = inputStr()
term.clear()
term.setCursorPos(1,1)
else
choice = getArg(1)
end
if choice == "line" then
if doText then
print("Place turtle facing build direction.")
print("------------------------------------")
print("Length?")
l = inputNum()
else
l = getArg(2)
end
line(l)
elseif choice == "stairs" then
if doText then
print("Place turtle facing build direction.")
print("Stair starts with block below turtle.")
print("------------------------------------")
print("Length/height?")
h = inputNum()
else
h = getArg(2)
end
stairs(h)
elseif choice == "stairsdown" then
if doText then
print("Place turtle facing build direction.")
print("Stair starts with block below turtle.")
print("------------------------------------")
print("Length/height?")
h = inputNum()
else
h = getArg(2)
end
stairsDown(h)
elseif choice == "walla" then
if doText then
print("Method A - build line by line")
print("Place turtle facing build direction.")
print("------------------------------------")
print("Length?")
l = inputNum()
print("Height?")
h = inputNum()
else
l = getArg(2)
h = getArg(3)
end
wallA(l,h)
elseif choice == "wallb" then
if doText then
print("Method B - start from bottom layer and go up")
print("Place turtle facing build direction.")
print("------------------------------------")
print("Length?")
l = inputNum()
print("Height?")
h = inputNum()
else
l = getArg(2)
h = getArg(3)
end
wallB(l,h)
elseif choice == "box" then
if doText then
print("Place turtle in lower left corner.")
print("----------------------------------")
print("Depth? (Sides perpendicular to front of turtle)")
d = inputNum()
print("Width? (Sides parallel to front of turtle)")
w = inputNum()
print("Height?")
h = inputNum()
else
d = getArg(2)
w = getArg(3)
h = getArg(4)
end
box(d,w,h)
elseif choice == "platform" then
if doText then
print("Place turtle in bottom left corner.")
print("-----------------------------------")
print("Depth? (Sides perpendicular to front of turtle)")
d = inputNum()
print("Width? (Sides parallel to front of turtle)")
w = inputNum()
else
d = getArg(2)
w = getArg(3)
end
platform(d,w)
elseif choice == "lineup" then
if doText then
print("Height?")
h = inputNum()
print("Go down after? y/n")
local r = inputStr()
if r == "y" or r == "yes" then
d = true
elseif r == "n" or r == "no" then
d = false
else
print("Boolean error, will go down")
d = false
end
else
h = getArg(2)
d = getArg(3)
end
lineUp(h,d)
elseif choice == "linedown" then
if doText then
print("Height (Depth)?")
h = inputNum()
else
h = getArg(2)
end
lineDown(h)
else
if doText then
print("Not an option")
else
print("Arguments error")
print("Use unbuild with no arguments if you don't know what you're doing")
end
error()
end