0
Web IDE main
10 commitsoaky Update ore-scanner
cffaa498 2026-09-25
main | 2026-09-25 |
Overview
MITOre Scanner
Quick Install on your ComputerCraft device
Type this command in the terminal:
hub get ore-scanner
main.lua main
-- ==========================================================
-- Block- / Ore-Finder (Radar-UI, mit Live-Suche + Verwaltung)
-- Fuer Advanced (Geo) Pocket Computer + Geo-Scanner
-- Benoetigt: CC:Tweaked + Advanced Peripherals (ATM10)
--
-- Bedienung:
-- [Tab] Suche <-> Verwalten
-- [Pfeile] in der Trefferliste navigieren
-- [Enter] ausgewaehltes Preset starten, oder (falls kein
-- Treffer markiert) direkt nach eingetipptem Text
-- suchen (ein einzelner exakter Name, Ad-hoc)
-- [Backspace] Zeichen loeschen
-- [Escape] Programm beenden (auf der Such-Seite)
-- Im Radar: [N] Neue Suche [Q] Quit
-- ==========================================================
local RADIUS = 16 -- Scan-Radius in Bloecken
local REFRESH = 1.5 -- Sekunden zwischen den Scans
local PRESETS_FILE = "ore_presets.dat"
-- ---- Farben -------------------------------------------------------------
local PRIMARY = colors.orange
local BACKGROUND = colors.black
local MUTED = colors.lightGray
local ACCENT = colors.white
pcall(term.setPaletteColour, PRIMARY, 0xffc245)
local UP = string.char(30)
local DOWN = string.char(31)
local DOT = string.char(7)
-- ---- Standard-Presets (beim allerersten Start angelegt) -----------------
-- IDs verifiziert aus Mod-Source (Allthemodium, Mystical Agriculture) bzw. Vanilla.
local DEFAULT_PRESETS = {
{ label = "Allthemodium", names = { "allthemodium:allthemodium_ore", "allthemodium:allthemodium_slate_ore" } },
{ label = "Vibranium", names = { "allthemodium:vibranium_ore", "allthemodium:other_vibranium_ore" } },
{ label = "Unobtainium", names = { "allthemodium:unobtainium_ore" } },
{ label = "Ancient Debris", names = { "minecraft:ancient_debris" } },
{ label = "Diamond", names = { "minecraft:diamond_ore", "minecraft:deepslate_diamond_ore" } },
{ label = "Prosperity", names = { "mysticalagriculture:prosperity_ore", "mysticalagriculture:deepslate_prosperity_ore" } },
}
-- ==========================================================
-- Persistenz
-- ==========================================================
local function loadPresets()
if fs.exists(PRESETS_FILE) then
local f = fs.open(PRESETS_FILE, "r")
local content = f.readAll()
f.close()
local ok, data = pcall(textutils.unserialize, content)
if ok and type(data) == "table" and #data > 0 then
return data
end
end
-- Datei fehlt oder ist kaputt -> mit Standard-Presets anlegen
local f = fs.open(PRESETS_FILE, "w")
f.write(textutils.serialize(DEFAULT_PRESETS))
f.close()
return DEFAULT_PRESETS
end
local function savePresets(presets)
local f = fs.open(PRESETS_FILE, "w")
f.write(textutils.serialize(presets))
f.close()
end
local PRESETS = loadPresets()
-- ==========================================================
-- Geo Scanner
-- ==========================================================
local function findScanner()
local s = peripheral.find("geoScanner")
if s then return s end
for _, side in ipairs({ "back", "front", "top", "bottom", "left", "right" }) do
if peripheral.isPresent(side) then
local p = peripheral.wrap(side)
if p and (p.scanBlocks or p.scan) then return p end
end
end
return nil
end
local scanner = findScanner()
if not scanner then
term.setBackgroundColor(colors.black); term.setTextColor(colors.white)
term.clear(); term.setCursorPos(1, 1)
print("Kein Geo Scanner gefunden!")
print("")
print("Pruefe am 'lua'-Prompt:")
print(" peripheral.getNames()")
print("Leer? Pocket Computer aus der")
print("Hotbar nehmen und neu einsetzen.")
return
end
local scanFn = scanner.scanBlocks or scanner.scan
-- ---- Suche (exakter Vollname-Match gegen ein Set von Namen) -------------
local function scanFor(names)
local blocks, err = scanFn(RADIUS)
if not blocks then return nil, (err or "Cooldown / kein Fuel") end
local set = {}
for _, n in ipairs(names) do set[n:lower()] = true end
local hits, nearest, nd = {}, nil, math.huge
for _, b in ipairs(blocks) do
if b.name and set[b.name:lower()] then
hits[#hits + 1] = b
local d = math.sqrt(b.x * b.x + b.y * b.y + b.z * b.z)
if d > 0 and d < nd then nd, nearest = d, b end
end
end
return hits, nil, nearest, nd
end
-- ==========================================================
-- Filter-Logik fuer die Live-Suche (eigenstaendig testbar)
-- ==========================================================
-- Ein Preset matcht eine Query, wenn die Query (klein geschrieben) als
-- Teilstring im Label ODER in mindestens einer hinterlegten ID vorkommt.
local function matchesQuery(preset, query)
if query == "" then return true end
local q = query:lower()
if preset.label:lower():find(q, 1, true) then return true end
for _, n in ipairs(preset.names) do
if n:lower():find(q, 1, true) then return true end
end
return false
end
local function filterPresets(presets, query)
local out = {}
for _, p in ipairs(presets) do
if matchesQuery(p, query) then out[#out + 1] = p end
end
return out
end
-- ==========================================================
-- Anzeige-Helfer (Radar)
-- ==========================================================
local W, H = term.getSize()
local mainTop, mainBottom = 2, H - 1
local mainH = mainBottom - mainTop + 1
local cx = math.floor(W / 2)
local cy = mainTop + math.floor(mainH / 2)
local halfCols = math.floor(W / 2) - 2
local halfRows = math.floor(mainH / 2) - 1
local cellR = math.max(1, math.min(halfCols, halfRows))
local scale = cellR / RADIUS
local function fillRow(y, bg)
term.setCursorPos(1, y); term.setBackgroundColor(bg); term.clearLine()
end
local function put(x, y, txt, bg, fg)
if y < 1 or y > H then return end
term.setCursorPos(x, y)
term.setBackgroundColor(bg or BACKGROUND)
term.setTextColor(fg or ACCENT)
term.write(txt)
end
local function marker(x, y, chevronChar)
for iy = 0, 1 do
for ix = 0, 1 do
local px, py = x + ix, y + iy
if px >= 1 and px <= W and py >= mainTop and py <= mainBottom then
term.setCursorPos(px, py)
term.setBackgroundColor(PRIMARY)
if chevronChar and ix == 0 and iy == 0 then
term.setTextColor(BACKGROUND)
term.write(chevronChar)
else
term.write(" ")
end
end
end
end
end
-- Chevron je nach Hoehenunterschied Block <-> Spieler (gleiche Schwelle wie
-- beim zentralen Naechster-Treffer-Indikator: +-1 Block Toleranz)
local function heightChevron(b)
if b.y > 1 then return UP
elseif b.y < -1 then return DOWN
else return DOT end
end
local function drawRadar(label, hits, nearest, nd, status)
term.setBackgroundColor(BACKGROUND); term.clear()
fillRow(1, PRIMARY)
local name = label
if #name > W - 2 then name = name:sub(1, W - 2) end
put(2, 1, name, PRIMARY, BACKGROUND)
if hits then
for _, b in ipairs(hits) do
local gx = cx + math.floor(b.x * scale + 0.5)
local gy = cy + math.floor(b.z * scale + 0.5)
marker(gx, gy, heightChevron(b))
end
end
put(cx, mainTop, "N", BACKGROUND, MUTED)
put(cx, mainBottom, "S", BACKGROUND, MUTED)
put(1, cy, "W", BACKGROUND, MUTED)
put(W, cy, "O", BACKGROUND, MUTED)
if nearest then
local ch = DOT
if nearest.y > 1 then ch = UP
elseif nearest.y < -1 then ch = DOWN end
put(cx, cy, ch, BACKGROUND, ACCENT)
else
put(cx, cy, DOT, BACKGROUND, MUTED)
end
if status then
put(1, mainBottom, status, BACKGROUND, MUTED)
elseif nearest then
put(1, mainBottom, ("d:%.1f n:%d"):format(nd, #hits), BACKGROUND, MUTED)
elseif hits then
put(1, mainBottom, "keine Treffer", BACKGROUND, MUTED)
end
fillRow(H, BACKGROUND)
put(1, H, "[N] Neue Suche", BACKGROUND, MUTED)
put(W - 8, H, "[Q] Quit", BACKGROUND, MUTED)
term.setCursorBlink(false)
end
-- ==========================================================
-- Tab 1: Suche (Live-Filter waehrend des Tippens)
-- ==========================================================
-- Rueckgabe: ("search", label, names) -> Scan starten
-- ("manage") -> zu Tab 2 wechseln
-- ("quit") -> Programm beenden
local function searchScreen()
local query = ""
local selected = 1
local function draw()
term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
term.clear()
fillRow(1, PRIMARY)
term.setCursorPos(2, 1); term.setBackgroundColor(PRIMARY); term.setTextColor(BACKGROUND)
term.write("Suche")
term.setCursorPos(W - 5, 1); term.write("[Tab]")
term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
term.setCursorPos(1, 3)
local shown = "> " .. query
local cursorCol
if #shown > W then
shown = "\187" .. shown:sub(-(W - 1)) -- Pfeil zeigt: Text geht nach links weiter
cursorCol = W + 1
else
cursorCol = #shown + 1
end
term.write(shown)
local matches = filterPresets(PRESETS, query)
if selected > #matches then selected = #matches end
if selected < 1 and #matches > 0 then selected = 1 end
local row = 5
if #matches == 0 then
term.setTextColor(MUTED); term.setCursorPos(1, row)
if query == "" then
term.write("Tippen zum Suchen...")
else
term.write("Kein Preset gefunden")
term.setCursorPos(1, row + 1); term.write("[Enter]=Direktsuche")
end
else
for i, p in ipairs(matches) do
if row > H - 2 then break end
local label = p.label
if #label > W - 2 then label = label:sub(1, W - 3) .. "\187" end
if i == selected then
fillRow(row, PRIMARY)
term.setCursorPos(2, row); term.setBackgroundColor(PRIMARY); term.setTextColor(BACKGROUND)
else
term.setCursorPos(2, row); term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
end
term.write(label)
row = row + 1
end
end
fillRow(H, BACKGROUND)
if #matches > 0 then
put(1, H, "Enter=Start F6=Loeschen", BACKGROUND, MUTED)
else
put(1, H, "Enter=Start Esc=Quit", BACKGROUND, MUTED)
end
term.setCursorPos(math.min(cursorCol, W), 3); term.setCursorBlink(true)
return matches
end
local matches = draw()
while true do
local e, p1 = os.pullEvent()
if e == "char" then
query = query .. p1
selected = 1
matches = draw()
elseif e == "key" then
if p1 == keys.backspace then
query = query:sub(1, -2)
selected = 1
matches = draw()
elseif p1 == keys.up then
if selected > 1 then selected = selected - 1 end
matches = draw()
elseif p1 == keys.down then
if selected < #matches then selected = selected + 1 end
matches = draw()
elseif p1 == keys.tab then
return "manage"
elseif p1 == keys.enter then
if #matches > 0 and matches[selected] then
return "search", matches[selected].label, matches[selected].names
elseif query:match("%S") then
local trimmed = query:match("^%s*(.-)%s*$")
return "search", trimmed, { trimmed }
end
elseif p1 == keys.escape then
return "quit"
elseif p1 == keys.delete or p1 == keys.f2 or p1 == keys.f6 then
if matches[selected] then
local target = matches[selected]
term.setCursorPos(1, H - 1); term.setBackgroundColor(BACKGROUND); term.clearLine()
term.setTextColor(colors.red)
local msg = "Loeschen: " .. target.label .. "?"
if #msg > W then msg = msg:sub(1, W - 1) .. "\187" end
term.write(msg)
term.setCursorPos(1, H); term.clearLine()
term.setTextColor(MUTED); term.write("Enter=Ja Esc=Nein")
local _, confirmKey = os.pullEvent("key")
if confirmKey == keys.enter then
for i, p in ipairs(PRESETS) do
if p == target then table.remove(PRESETS, i); break end
end
savePresets(PRESETS)
selected = 1
end
end
matches = draw()
end
end
end
end
-- ==========================================================
-- Generischer Text-Eingabe-Editor (fuer Suche + Verwalten)
-- ==========================================================
-- Zeichnet ab (x,y) "prefix" + getippten Text, scrollt horizontal
-- wenn der Text zu lang fuer den Bildschirm wird.
-- Rueckgabe: "enter"|"tab"|"quit", text
local function textField(x, y, prefix, maxWidth)
local text = ""
local function redraw()
term.setCursorPos(x, y); term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
term.clearLine()
term.setCursorPos(x, y)
local shown = prefix .. text
local cursorCol
if #shown > maxWidth then
shown = "\187" .. shown:sub(-(maxWidth - 1))
cursorCol = x + maxWidth
else
cursorCol = x + #shown
end
term.write(shown)
term.setCursorPos(math.min(cursorCol, x + maxWidth - 1), y)
term.setCursorBlink(true)
end
redraw()
while true do
local e, p1 = os.pullEvent()
if e == "char" then
text = text .. p1
redraw()
elseif e == "key" then
if p1 == keys.backspace then
text = text:sub(1, -2)
redraw()
elseif p1 == keys.enter then
return "enter", text
elseif p1 == keys.tab then
return "tab", text
elseif p1 == keys.escape then
return "quit", text
end
end
end
end
-- ==========================================================
-- Tab 2: Verwalten (neues Preset anlegen)
-- ==========================================================
-- Rueckgabe: "quit" -> Programm komplett beenden
-- nil -> zurueck zur Suche (abgebrochen oder gespeichert)
local function drawManageHeader()
term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
term.clear()
fillRow(1, PRIMARY)
term.setCursorPos(2, 1); term.setBackgroundColor(PRIMARY); term.setTextColor(BACKGROUND)
term.write("Verwalten")
term.setCursorPos(W - 5, 1); term.write("[Tab]")
term.setBackgroundColor(BACKGROUND); term.setTextColor(ACCENT)
end
local function manageScreen()
drawManageHeader()
term.setCursorPos(1, 3); term.write("Anzeigename:")
local action, label = textField(1, 4, "> ", W - 1)
if action == "quit" then return "quit" end
if action ~= "enter" then return end
label = label:match("^%s*(.-)%s*$")
if label == "" then return end
drawManageHeader()
term.setCursorPos(1, 3); term.write("Basis-ID:")
term.setTextColor(MUTED); term.setCursorPos(1, 4); term.write("z.B. mod:block_ore"); term.setTextColor(ACCENT)
local action2, base = textField(1, 6, "> ", W - 1)
if action2 == "quit" then return "quit" end
if action2 ~= "enter" then return end
base = base:match("^%s*(.-)%s*$")
if base == "" then return end
local names = { base }
while true do
drawManageHeader()
term.setCursorPos(1, 3); term.write(label)
term.setTextColor(MUTED); term.setCursorPos(1, 5); term.write("Weitere ID:"); term.setTextColor(ACCENT)
term.setCursorPos(1, 6); term.setTextColor(MUTED); term.write("(leer=fertig)"); term.setTextColor(ACCENT)
local a3, extra = textField(1, 8, "> ", W - 1)
if a3 == "quit" then return "quit" end
if a3 ~= "enter" then return end
extra = extra:match("^%s*(.-)%s*$")
if extra == "" then break end
names[#names + 1] = extra
end
PRESETS[#PRESETS + 1] = { label = label, names = names }
savePresets(PRESETS)
term.setTextColor(colors.lime)
term.setCursorPos(1, H - 1)
local msg = "Gespeichert: " .. label
if #msg > W then msg = msg:sub(1, W) end
term.write(msg)
os.sleep(1.0)
end
-- ==========================================================
-- Hauptschleife
-- ==========================================================
local function runRadar(label, names)
local lastHits, lastNear, lastND = nil, nil, math.huge
local timer = os.startTimer(0)
while true do
local e, p1 = os.pullEvent()
if e == "timer" and p1 == timer then
local hits, err, nearest, nd = scanFor(names)
if err then
drawRadar(label, lastHits, lastNear, lastND, "warte: " .. err)
else
lastHits, lastNear, lastND = hits, nearest, nd
drawRadar(label, hits, nearest, nd)
end
timer = os.startTimer(REFRESH)
elseif e == "key" then
if p1 == keys.q then
return "quit"
elseif p1 == keys.n then
return "new"
end
end
end
end
while true do
local mode = "search"
while mode ~= "search_result" and mode ~= "quit" do
if mode == "search" then
local action, a, b = searchScreen()
if action == "quit" then
mode = "quit"
elseif action == "manage" then
mode = "manage"
elseif action == "search" then
mode = "search_result"
label, names = a, b
end
elseif mode == "manage" then
local mResult = manageScreen()
if mResult == "quit" then
mode = "quit"
else
mode = "search"
end
end
end
if mode == "quit" then
pcall(function()
if term.nativePaletteColour then
term.setPaletteColour(PRIMARY, term.nativePaletteColour(PRIMARY))
end
end)
term.setBackgroundColor(colors.black); term.setTextColor(colors.white)
term.clear(); term.setCursorPos(1, 1); term.setCursorBlink(true)
print("Beendet.")
return
end
local result = runRadar(label, names)
if result == "quit" then
pcall(function()
if term.nativePaletteColour then
term.setPaletteColour(PRIMARY, term.nativePaletteColour(PRIMARY))
end
end)
term.setBackgroundColor(colors.black); term.setTextColor(colors.white)
term.clear(); term.setCursorPos(1, 1); term.setCursorBlink(true)
print("Beendet.")
return
end
-- result == "new" -> Schleife von vorn, zurueck zur Suche
end Usage
Once installed with hub get ore-scanner, run:
ore-scannerCareful what you run: This script was written by oaky, not by us.
It runs with full access to the computer you install it on — it can read and delete files there.
Read it before you run it.
About
No description provided.
MIT License
★ 0 stars
0 in-game downloads
Hardware Targets
computer