Advertisement
Wassaa

quartzHunter

Jun 27th, 2025 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- quartz-hunter-verbose.lua
  2. local TARGET = "ae2:quartz_cluster"
  3.  
  4. -- Direction names so the log reads nicely
  5. local directions = { "north", "east", "south", "west" }
  6. local heading    = 1                     -- assume we start facing north
  7.  
  8. -- Simple coloured logger (falls back to white on colourless terminals)
  9. local function log(msg, colour)
  10.   local old = term.getTextColor and term.getTextColor() or colours.white
  11.   if term.isColor and term.isColor() and colour then
  12.     term.setTextColor(colour)
  13.   end
  14.   print(("[%s] %s"):format(textutils.formatTime(os.time(), true), msg))
  15.   if term.isColor and term.isColor() then
  16.     term.setTextColor(old)
  17.   end
  18. end
  19.  
  20. -- Look with inspectFn; if it’s the TARGET, mine it with digFn.
  21. local function checkAndMine(label, inspectFn, digFn)
  22.   local ok, info = inspectFn()
  23.   if not ok then
  24.     log(label .. ": nothing there", colours.lightGrey)
  25.     return
  26.   end
  27.  
  28.   if info.name == TARGET then
  29.     log(label .. ": found " .. info.name .. " → mining", colours.lime)
  30.     if digFn() then
  31.       log(label .. ": mined successfully", colours.green)
  32.     else
  33.       log(label .. ": dig failed!", colours.red)
  34.     end
  35.   else
  36.     log(label .. ": saw " .. info.name .. " (ignored)", colours.grey)
  37.   end
  38. end
  39.  
  40. while true do
  41.   for _ = 1, 4 do                    -- do a full spin
  42.     log(("=== Facing %s ==="):format(directions[heading]), colours.yellow)
  43.  
  44.     checkAndMine("front", turtle.inspect,     turtle.dig)
  45.     checkAndMine("above", turtle.inspectUp,   turtle.digUp)
  46.     checkAndMine("below", turtle.inspectDown, turtle.digDown)
  47.  
  48.     turtle.turnRight()
  49.     heading = heading % 4 + 1        -- keep heading in 1-4
  50.   end
  51.  
  52.   sleep(1)                           -- short breather before next sweep
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement