forked from GuitarMusashi616/SchematicTurtle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.lua
More file actions
249 lines (217 loc) · 6.61 KB
/
setup.lua
File metadata and controls
249 lines (217 loc) · 6.61 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
--redownload apis
--run apis
--initiate variables
Branch = "patch2"
--temp ease of access
local f = fs.open("update","w")
f.write([[
shell.run("SchematicBuilder/Debug")
local tArgs = {...}
if not tArgs[1] then
git.run("https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/]]..Branch..[[/setup.lua",{"update"})
else
git.run("https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/]]..Branch..[[/setup.lua",{tArgs[1]})
end
]])
f.close()
--make sure gzip is equipped
tArgs = {...}
if #tArgs ~= 1 then
print("Usage: schemSetup <gunzipped schematic file>")
return
end
--checkfuel
if turtle.getFuelLevel() == 0 then
print("No Fuel")
error()
elseif turtle.getFuelLevel() < 300 then
print("Low Fuel")
error()
end
function checkWrench()
local wrench = false
local mem = turtle.getSelectedSlot()
turtle.select(14)
local item = turtle.getItemDetail()
if item then
if item.name == "ThermalExpansion:wrench" then
wrench = true
else
wrench = false
end
end
turtle.select(mem)
return wrench
end
function checkTurtleType()
local advanced = term.isColor()
return advanced
end
function schemAPIs(run)
--dl and run or just run or just update
if not fs.isDir("SchematicBuilder") then
fs.makeDir("SchematicBuilder")
else
for i,v in pairs(fs.list("SchematicBuilder")) do
fs.delete("SchematicBuilder/"..v)
end
end
if run ~= "update" then
local deleteFiles = {"objective","reference","position","startup"}
for i,v in pairs(deleteFiles) do
if fs.exists(v) then
fs.delete(v)
end
end
end
local apis = {
GoTo = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/goto.lua",
GPS = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/gps.lua",
SchemParser = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/schemparser.lua",
LocationFinder = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/locationfinder.lua",
Refill = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/refill.lua",
Debug = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/debug.lua",
}
for i,v in pairs(apis) do
if run ~= "run" then
git.get(v,"SchematicBuilder/"..i)
end
shell.run("SchematicBuilder/"..i)
end
end
function deleteOldFiles()
if not fs.exists("reference") then
if fs.exists("position") then
fs.delete("position")
end
if fs.exists("objective") then
fs.delete("objective")
end
end
end
function copySetupVars()
local h = fs.open("reference",'w')
h.writeLine("Branch = \""..Branch.."\"")
h.writeLine("slots = {}")
h.writeLine("filename = ".."\""..tostring(filename).."\"")
for i,v in pairs(slots) do
h.writeLine("slots\["..i.."\] = {}")
for i2,v2 in pairs(v) do
h.writeLine("slots\["..i.."\]\["..i2.."\] = {}")
for i3,v3 in pairs(v2) do
h.writeLine("slots\["..i.."\]\["..i2.."\]\["..i3.."\] = "..tostring(v3))
end
end
end
h.writeLine("invList = {}")
for i,v in pairs(invList) do
h.writeLine("invList\["..i.."\] = {}")
for i2,v2 in pairs(v) do
h.writeLine("invList\["..i.."\]\[".."\""..i2.."\"".."\] = "..tostring(v2))
end
end
h.writeLine("height = "..tostring(height))
h.writeLine("width = "..tostring(width))
h.writeLine("length = "..tostring(length))
h.writeLine("chestOrder = "..tostring(chestOrder))
h.writeLine("enderchest1 = "..tostring(enderchest1))
h.writeLine("enderchest2 = "..tostring(enderchest2))
h.writeLine("wrench = "..tostring(wrench))
h.writeLine("origDir = ".."\""..tostring(origDir).."\"")
h.writeLine("Hoff, Koff, Loff = "..tostring(Hoff)..", "..tostring(Koff)..", "..tostring(Loff))
h.writeLine("blocks = {}")
for i,v in pairs(blocks) do
h.writeLine("blocks\["..i.."\] = "..tostring(v))
end
h.writeLine("data = {}")
for i,v in pairs(data) do
h.writeLine("data\["..i.."\] = "..tostring(v))
end
h.close()
end
function Initiate()
if tArgs[1] == "update" then
schemAPIs("update")
error()
end
deleteOldFiles()
schemAPIs()
--run new apis
--current location
heightPos = 0
widthPos = 0
lengthPos = 0
face = "south"
--current objective
x = 0
y = 0
z = 0
--refill vars
enderchest1 = 15
enderchest2 = 16
chestOrder = 1
--schematic vars
blocks = {}
data = {}
--initialize if available
openRednet()
gpsSetup()
wrench = checkWrench()
isAdvanced = checkTurtleType()
--make sure schematic is good to go
filename = tArgs[1]
if not fs.exists(filename) then
print("File does not exist.")
return
end
handle = fs.open(filename, "rb")
--corresponding item slots
shell.run("clr")
setup()
--copy down entire environment
copySetupVars()
if tArgs then
recordPos(0,1,1,"south")
recordObj(x,y,z)
recordObjSlot(1)
else
shell.run("reference")
shell.run("position")
shell.run("objective")
end
local h = fs.open("startup","w")
h.write([[
shell.run("reference")
local apis = {
GoTo = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/goto.lua",
GPS = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/gps.lua",
SchemParser = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/schemparser.lua",
LocationFinder = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/locationfinder.lua",
Refill = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/refill.lua",
Debug = "https://raw.githubusercontent.com/GuitarMusashi616/SchematicTurtle/"..Branch.."/.apis/debug.lua",
}
for i,v in pairs(apis) do
shell.run("SchematicBuilder/"..i)
end
openRednet()
checkIfRefill()
if gps.locate() then
gpsi = true
else
gpsi = false
end
resynchronize()
while true do
shell.run("position")
shell.run("objective")
shell.run("objectiveSlot")
goto(x+1,y,z)
findNextBlock(x,y,z)
checkIfAir()
end
shell.run("clr")
print("finished")
]])
h.close()
end
Initiate()