mining_setup.lua

340 lines ยท 10.1 KB

Open raw

eHydra Mining Setup System

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eHydra_wip/mining_setup.lua
1-- eHydra Mining Setup System
2-- Complete mining infrastructure deployment with GPS positioning
3
4local SLOT_COUNT = 16
5
6-- Infrastructure items needed for mining setup
7local REQUIRED_ITEMS = {
8 turtles = {"turtle", 1},
9 diskDrives = {"disk_drive", 1},
10 disks = {"floppy_disk", 1},
11 computers = {"computer", 1}, -- For monitoring/control
12 chests = {"chest", 3}, -- Coal chest, storage chest, spare chest
13 coal = {"coal", 64}, -- Fuel supply
14 enderChests = {"ender", 1} -- Optional for remote storage
15}
16
17local function scanForMiningSetup()
18 print("๐Ÿ” Scanning for complete mining setup components...")
19
20 local inventory = {}
21 local missing = {}
22
23 for category, requirement in pairs(REQUIRED_ITEMS) do
24 local pattern, minCount = requirement[1], requirement[2]
25 local found = {}
26
27 for slot = 1, SLOT_COUNT do
28 local item = turtle.getItemDetail(slot)
29 if item and item.name:find(pattern) then
30 table.insert(found, {slot = slot, name = item.name, count = item.count})
31 end
32 end
33
34 inventory[category] = found
35 local totalCount = 0
36 for _, item in ipairs(found) do
37 totalCount = totalCount + item.count
38 end
39
40 if totalCount < minCount then
41 table.insert(missing, category .. " (need " .. minCount .. ", have " .. totalCount .. ")")
42 end
43 end
44
45 return inventory, missing
46end
47
48local function getGPSPosition()
49 print("๐Ÿ“ Getting GPS coordinates...")
50 local x, y, z = gps.locate(5, false)
51
52 if x then
53 print("โœ… GPS Location: " .. x .. ", " .. y .. ", " .. z)
54 return {x = math.floor(x), y = math.floor(y), z = math.floor(z)}
55 else
56 print("โŒ GPS not available - using manual positioning")
57 return nil
58 end
59end
60
61local function calculateMiningArea(basePos, width, depth, height)
62 if not basePos then
63 print("โš ๏ธ No GPS - please manually position setup")
64 return nil
65 end
66
67 local area = {
68 start = {x = basePos.x, y = basePos.y - height, z = basePos.z},
69 finish = {x = basePos.x + width - 1, y = basePos.y - 1, z = basePos.z + depth - 1},
70 control = {x = basePos.x - 2, y = basePos.y + 1, z = basePos.z - 2}, -- Control station position
71 coalChest = {x = basePos.x - 1, y = basePos.y, z = basePos.z - 1},
72 storageChest = {x = basePos.x - 1, y = basePos.y, z = basePos.z + 1}
73 }
74
75 return area
76end
77
78local function deployInfrastructure(inventory, area)
79 print("๐Ÿ—๏ธ Deploying mining infrastructure...")
80
81 local currentX, currentY, currentZ = gps.locate()
82 if not currentX then
83 print("โŒ Cannot deploy without GPS")
84 return false
85 end
86
87 -- Deploy coal chest
88 print("โ›ฝ Placing coal chest...")
89 -- Navigate to coal chest position
90 -- Place chest and fill with coal
91 turtle.select(inventory.chests[1].slot)
92 turtle.place()
93
94 -- Fill coal chest
95 if #inventory.coal > 0 then
96 turtle.select(inventory.coal[1].slot)
97 turtle.drop(32) -- Drop half the coal
98 print("โœ… Coal chest stocked")
99 end
100
101 -- Deploy storage chest
102 print("๐Ÿ“ฆ Placing storage chest...")
103 -- Navigate to storage position and place
104 turtle.select(inventory.chests[2].slot)
105 turtle.place()
106
107 -- Deploy control computer
108 print("๐Ÿ–ฅ๏ธ Placing control computer...")
109 turtle.select(inventory.computers[1].slot)
110 turtle.place()
111
112 -- Setup disk with mining program
113 turtle.select(inventory.diskDrives[1].slot)
114 turtle.placeUp()
115
116 turtle.select(inventory.disks[1].slot)
117 turtle.dropUp()
118
119 return true
120end
121
122local function createMiningProgram(area, miningProgram, parameters)
123 print("๐Ÿ’พ Creating mining program disk...")
124
125 if not fs.exists("disk") then
126 print("โŒ Disk not mounted")
127 return false
128 end
129
130 -- Create comprehensive mining startup
131 local startupFile = fs.open("disk/startup", "w")
132 if not startupFile then
133 return false
134 end
135
136 startupFile.write(string.format([[
137-- eHydra Complete Mining Setup
138print("๐Ÿ—๏ธ eHydra Mining Setup v1.0")
139print("=============================")
140
141-- Get position
142local x, y, z = gps.locate(3, false)
143if x then
144 print("๐Ÿ“ Position: " .. x .. ", " .. y .. ", " .. z)
145else
146 print("๐Ÿ“ GPS not available")
147end
148
149-- Setup mining parameters
150local miningArea = {
151 start = {x = %d, y = %d, z = %d},
152 finish = {x = %d, y = %d, z = %d}
153}
154
155-- Copy mining program if available
156if fs.exists("disk/%s") then
157 fs.copy("disk/%s", "%s")
158 print("โœ… Mining program installed: %s")
159end
160
161-- Setup fuel management
162local function refuelFromChest()
163 -- Look for coal chest nearby
164 for _, direction in ipairs({"front", "back", "left", "right", "up", "down"}) do
165 if peripheral.isPresent(direction) and peripheral.getType(direction) == "minecraft:chest" then
166 local chest = peripheral.wrap(direction)
167 local items = chest.list()
168 for slot, item in pairs(items) do
169 if item.name:find("coal") then
170 chest.pushItems(peripheral.getName(turtle), slot, math.min(item.count, 32), 1)
171 turtle.select(1)
172 if turtle.refuel() then
173 print("โ›ฝ Refueled from chest")
174 return true
175 end
176 end
177 end
178 end
179 end
180 return false
181end
182
183-- Setup inventory management
184local function depositToStorage()
185 -- Find storage chest and deposit items
186 for _, direction in ipairs({"front", "back", "left", "right", "up", "down"}) do
187 if peripheral.isPresent(direction) and peripheral.getType(direction) == "minecraft:chest" then
188 local chest = peripheral.wrap(direction)
189 for slot = 2, 16 do -- Keep slot 1 for fuel
190 local item = turtle.getItemDetail(slot)
191 if item and not item.name:find("coal") then
192 turtle.select(slot)
193 turtle.drop()
194 end
195 end
196 end
197 end
198end
199
200-- Send status updates
201local function sendStatus(message)
202 local modem = peripheral.find("modem")
203 if modem then
204 rednet.open(peripheral.getName(modem))
205 rednet.broadcast({
206 id = os.getComputerID(),
207 status = message,
208 position = {x = x, y = y, z = z},
209 fuel = turtle.getFuelLevel(),
210 time = os.time()
211 }, "ehydra_mining")
212 print("๐Ÿ“ก Status sent: " .. message)
213 end
214end
215
216-- Main mining operation
217sendStatus("MINING_STARTED")
218
219-- Initial refuel
220refuelFromChest()
221
222-- Start mining program
223if fs.exists("%s") then
224 print("๐Ÿš€ Starting mining: %s %s")
225 shell.run("%s", "%s")
226else
227 print("โŒ Mining program not found")
228 sendStatus("ERROR_NO_PROGRAM")
229end
230
231sendStatus("MINING_COMPLETED")
232]],
233 area.start.x, area.start.y, area.start.z,
234 area.finish.x, area.finish.y, area.finish.z,
235 miningProgram, miningProgram, miningProgram, miningProgram,
236 miningProgram, miningProgram, parameters or ""
237))
238
239 startupFile.close()
240
241 -- Copy the actual mining program to disk
242 if fs.exists(miningProgram .. ".lua") then
243 fs.copy(miningProgram .. ".lua", "disk/" .. miningProgram)
244 print("โœ… Mining program copied to disk")
245 end
246
247 return true
248end
249
250local function deployCompleteMiningSetup(program, parameters, dimensions)
251 print("๐Ÿ—๏ธ eHydra Complete Mining Setup")
252 print("================================")
253
254 -- Get current position
255 local basePos = getGPSPosition()
256 if not basePos then
257 print("โŒ GPS required for automated setup")
258 return false
259 end
260
261 -- Scan inventory
262 local inventory, missing = scanForMiningSetup()
263
264 if #missing > 0 then
265 print("โŒ Missing required items:")
266 for _, item in ipairs(missing) do
267 print(" โ€ข " .. item)
268 end
269 return false
270 end
271
272 print("โœ… All required items available")
273
274 -- Calculate mining area
275 local width, depth, height = dimensions.width or 16, dimensions.depth or 16, dimensions.height or 10
276 local area = calculateMiningArea(basePos, width, depth, height)
277
278 print("๐Ÿ“Š Mining Area Calculated:")
279 print(" Start: " .. area.start.x .. ", " .. area.start.y .. ", " .. area.start.z)
280 print(" Finish: " .. area.finish.x .. ", " .. area.finish.y .. ", " .. area.finish.z)
281 print(" Size: " .. width .. "x" .. depth .. "x" .. height)
282
283 -- Deploy infrastructure
284 if not deployInfrastructure(inventory, area) then
285 print("โŒ Infrastructure deployment failed")
286 return false
287 end
288
289 -- Create mining program
290 if not createMiningProgram(area, program, parameters) then
291 print("โŒ Mining program setup failed")
292 return false
293 end
294
295 -- Deploy turtle
296 print("๐Ÿข Deploying mining turtle...")
297 turtle.select(inventory.turtles[1].slot)
298 turtle.place()
299 peripheral.call("front", "turnOn")
300
301 print("โœ… Complete mining setup deployed!")
302 print(" ๐Ÿข Turtle: Deployed and starting")
303 print(" โ›ฝ Coal chest: Stocked")
304 print(" ๐Ÿ“ฆ Storage chest: Ready")
305 print(" ๐Ÿ–ฅ๏ธ Control computer: Active")
306 print(" ๐Ÿ“ก Monitoring: Enabled")
307
308 return true
309end
310
311-- Parse command line arguments
312local args = {...}
313local program = args[1] or "quarry"
314local width = tonumber(args[2]) or 16
315local depth = tonumber(args[3]) or 16
316local height = tonumber(args[4]) or 10
317local parameters = table.concat({table.unpack(args, 5)}, " ")
318
319print("๐Ÿ—๏ธ eHydra Mining Setup Configuration")
320print("====================================")
321print("Program: " .. program)
322print("Dimensions: " .. width .. "x" .. depth .. "x" .. height)
323if parameters ~= "" then
324 print("Parameters: " .. parameters)
325end
326
327print()
328write("Proceed with setup? (y/n) [y]: ")
329local confirm = string.lower(read())
330
331if confirm ~= "n" then
332 deployCompleteMiningSetup(program, parameters, {
333 width = width,
334 depth = depth,
335 height = height
336 })
337else
338 print("Setup cancelled")
339end
340