Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local serialization = require("serialization")
- local gpu = component.gpu
- -- AUTOMATISCHE AE2-SUCHE (Jetzt korrigiert!)
- local ae2 = nil
- local ae2_type = nil
- for addr, ctype in component.list() do
- if ctype and ctype:sub(1, 3) == "me_" then
- ae2 = component.proxy(addr) -- Holt sich die echte Steuerung fuer den Block
- ae2_type = ctype
- break
- end
- end
- -- CONFIG
- local PASSWORD = "admin"
- local SAVE_FILE = "/home/farm_config_v3.dat"
- local sides = { [0]="Unten", [1]="Oben", [2]="Norden", [3]="Sueden", [4]="Westen", [5]="Osten" }
- local farms = {}
- local selected_idx = 1
- local current_tab = "farms"
- local function get_redstone_devices()
- local list = {}
- for addr in component.list("redstone") do table.insert(list, addr) end
- return list
- end
- local function save_data()
- local f = io.open(SAVE_FILE, "w")
- if f then f:write(serialization.serialize(farms)); f:close() end
- end
- local function load_data()
- local f = io.open(SAVE_FILE, "r")
- if f then
- local content = f:read("*a")
- f:close()
- farms = serialization.unserialize(content) or {}
- else
- local devices = get_redstone_devices()
- local first_uuid = devices[1] or "KEIN_BLOCK_GEFUNDEN"
- farms = {{name="Feld 1", redstone_uuid=first_uuid, sower_side=2, gath_side=3, sower_on=false, gath_on=false}}
- save_data()
- end
- end
- local function update_redstone()
- for _, farm in ipairs(farms) do
- if farm.redstone_uuid and farm.redstone_uuid ~= "KEIN_BLOCK_GEFUNDEN" then
- if component.type(farm.redstone_uuid) == "redstone" then
- local proxy = component.proxy(farm.redstone_uuid)
- if proxy then
- proxy.setOutput(farm.sower_side, farm.sower_on and 15 or 0)
- proxy.setOutput(farm.gath_side, farm.gath_on and 15 or 0)
- end
- end
- end
- end
- end
- local function draw_text(x, y, text, fg, bg)
- if fg then gpu.setForeground(fg) end
- if bg then gpu.setBackground(bg) end
- gpu.set(x, y, tostring(text))
- end
- local function safe_read(mask)
- local status, result = pcall(term.read, nil, nil, nil, mask)
- if status and result then return result:gsub("\n", "") end
- return ""
- end
- local function do_login()
- while true do
- term.clear()
- draw_text(20, 5, "=== SECURITY LOGIN ===", 0x00FFFF, 0x000000)
- draw_text(15, 8, "Bitte Passwort eingeben:", 0xFFFFFF)
- gpu.set(15, 10, "[ ]")
- term.setCursor(16, 10)
- local input = safe_read("*")
- if input == PASSWORD then break end
- draw_text(17, 13, "FALSCHES PASSWORT!", 0xFF0000)
- os.sleep(1.5)
- end
- end
- local function draw_navigation()
- gpu.setResolution(75, 22)
- gpu.setBackground(0x222222)
- gpu.fill(1, 1, 75, 1, " ")
- local farms_bg = (current_tab == "farms") and 0x00E5FF or 0x222222
- local farms_fg = (current_tab == "farms") and 0x000000 or 0xFFFFFF
- draw_text(2, 1, " [1] FARMS & CONTROLLER ", farms_fg, farms_bg)
- local ae2_bg = (current_tab == "ae2") and 0x00E5FF or 0x222222
- local ae2_fg = (current_tab == "ae2") and 0x000000 or 0xFFFFFF
- draw_text(28, 1, " [2] AE2 SPEICHERANZEIGE ", ae2_fg, ae2_bg)
- gpu.setBackground(0x000000)
- draw_text(1, 2, string.rep("-", 75), 0x555555)
- end
- local function draw_dashboard()
- draw_text(2, 4, "FARMLISTE:", 0xFFFF00)
- for i, farm in ipairs(farms) do
- local y = 4 + i
- if i == selected_idx then
- draw_text(2, y, "> " .. farm.name, 0x00FF00)
- else
- draw_text(4, y, farm.name, 0xFFFFFF)
- end
- end
- draw_text(2, 19, "[+] NEUE FARM ANLEGEN", 0x000000, 0x00FF00)
- for y = 3, 20 do gpu.set(26, y, "|") end
- local f = farms[selected_idx]
- if f then
- draw_text(29, 4, "DETAILS: " .. f.name:upper(), 0x00E5FF, 0x000000)
- local short_uuid = tostring(f.redstone_uuid):sub(1, 8) .. "..."
- draw_text(29, 5, "Block-UUID: " .. short_uuid, 0x00FF00)
- draw_text(29, 6, "Sower-Seite: " .. sides[f.sower_side] .. " | Ernter-Seite: " .. sides[f.gath_side], 0x888888)
- if f.sower_on then
- draw_text(29, 9, " SOWER: AKTIV ", 0x000000, 0x00FF00)
- else
- draw_text(29, 9, " SOWER: INAKTIV ", 0xFFFFFF, 0xFF0000)
- end
- if f.gath_on then
- draw_text(51, 9, " ERNTER: AKTIV ", 0x000000, 0x00FF00)
- else
- draw_text(51, 9, " ERNTER: INAKTIV ", 0xFFFFFF, 0xFF0000)
- end
- draw_text(29, 13, "[ BEIDE AN ]", 0x000000, 0xAAAAAA)
- draw_text(46, 13, "[ BEIDE AUS ]", 0x000000, 0xAAAAAA)
- draw_text(29, 17, "[ FARM COMPLETE LOESCHEN ]", 0xFFFFFF, 0x993333)
- else
- draw_text(29, 9, "Keine Farm aktiv. Klicke links auf [+].", 0x888888, 0x000000)
- end
- end
- local function draw_ae2_storage()
- draw_text(2, 4, "AE2 NETZWERK-STATUS:", 0x00E5FF, 0x000000)
- if not ae2 then
- draw_text(2, 6, "FEHLER: Kein AE2-Bauteil am Adapter erkannt!", 0xFF0000)
- draw_text(2, 7, "Bitte ueberpruefe die OC-Verkabelung zum AE2-Netzwerk.", 0x888888)
- return
- end
- draw_text(2, 6, "Verbunden via: " .. ae2_type .. " (Lese Speicher...)", 0x00FF00)
- -- Probiere verschiedene AE2-API-Methoden aus (Versionsunabhaengig)
- local success, items = pcall(ae2.getItemsInNetwork)
- if not success or not items then success, items = pcall(ae2.getAvailableItems) end
- if not success or not items then success, items = pcall(ae2.getStoredItems) end
- if success and items then
- draw_text(2, 8, string.rep("-", 71), 0x555555)
- draw_text(2, 9, "Item Name", 0xFFFF00)
- draw_text(50, 9, "Anzahl im Lager", 0xFFFF00)
- draw_text(2, 10, string.rep("-", 71), 0x555555)
- local row = 11
- local count = 0
- for _, item in pairs(items) do
- if item and (item.label or item.name) then
- local label = item.label or item.name
- local amount = item.size or item.amount or 0
- if count < 10 and amount > 0 then
- if #label > 45 then label = label:sub(1, 42) .. "..." end
- draw_text(2, row, label, 0xFFFFFF)
- draw_text(50, row, string.format("%d", amount), 0x00FF00)
- row = row + 1
- count = count + 1
- end
- end
- end
- if count == 0 then
- draw_text(2, 11, "Keine Items mit einer Anzahl > 0 gefunden.", 0x888888)
- end
- else
- draw_text(2, 8, "Fehler beim Abrufen der Items. Methode nicht unterstuetzt.", 0xFF0000)
- end
- end
- local function refresh_screen()
- term.clear()
- draw_navigation()
- if current_tab == "farms" then draw_dashboard()
- elseif current_tab == "ae2" then draw_ae2_storage() end
- end
- local function add_farm_menu()
- term.clear()
- draw_text(5, 2, "=== NEUE FARM ANLEGEN ===", 0xFFFF00, 0x000000)
- draw_text(5, 5, "Name der Farm eingeben: ")
- term.setCursor(5, 6)
- local name = safe_read()
- if name == "" then name = "Feld " .. (#farms + 1) end
- local devices = get_redstone_devices()
- if #devices == 0 then
- term.clear()
- draw_text(5, 5, "FEHLER: Kein Redstone I/O Block gefunden!", 0xFF0000)
- os.sleep(3)
- return
- end
- local dev_idx = 1
- local new_farm = {name=name, redstone_uuid=devices[dev_idx], sower_side=2, gath_side=3, sower_on=false, gath_on=false}
- while true do
- term.clear()
- draw_text(5, 2, "=== KONFIGURATION: " .. name .. " ===", 0xFFFF00, 0x000000)
- local short_uuid = tostring(new_farm.redstone_uuid):sub(1, 8) .. "..."
- draw_text(5, 5, "1. I/O Block (UUID): < " .. short_uuid .. " > ("..dev_idx.."/"..#devices..")", 0xFFFFFF)
- draw_text(5, 7, "2. Seite Sower : < " .. sides[new_farm.sower_side] .. " >", 0xFFFFFF)
- draw_text(5, 9, "3. Seite Gatherer : < " .. sides[new_farm.gath_side] .. " >", 0xFFFFFF)
- draw_text(5, 14, "[ SPEICHERN ]", 0x000000, 0x00FF00)
- draw_text(22, 14, "[ ABBRECHEN ]", 0xFFFFFF, 0xFF0000)
- local _, _, x, y = event.pull("touch")
- if y == 5 then
- if x >= 26 and x <= 28 then
- dev_idx = dev_idx - 1; if dev_idx < 1 then dev_idx = #devices end
- new_farm.redstone_uuid = devices[dev_idx]
- end
- if x >= 42 and x <= 48 then
- dev_idx = dev_idx + 1; if dev_idx > #devices then dev_idx = 1 end
- new_farm.redstone_uuid = devices[dev_idx]
- end
- elseif y == 7 then
- if x >= 26 and x <= 28 then new_farm.sower_side = (new_farm.sower_side - 1) % 6 end
- if x >= 42 and x <= 47 then new_farm.sower_side = (new_farm.sower_side + 1) % 6 end
- elseif y == 9 then
- if x >= 26 and x <= 28 then new_farm.gath_side = (new_farm.gath_side - 1) % 6 end
- if x >= 42 and x <= 47 then new_farm.gath_side = (new_farm.gath_side + 1) % 6 end
- elseif y == 14 and x >= 5 and x <= 17 then
- table.insert(farms, new_farm)
- save_data()
- selected_idx = #farms
- break
- elseif y == 14 and x >= 22 and x <= 34 then
- break
- end
- end
- update_redstone()
- end
- load_data()
- do_login()
- update_redstone()
- refresh_screen()
- while true do
- local _, _, x, y = event.pull("touch")
- if y == 1 then
- if x >= 2 and x <= 25 then current_tab = "farms"; refresh_screen()
- elseif x >= 28 and x <= 52 then current_tab = "ae2"; refresh_screen() end
- end
- if current_tab == "farms" then
- if x >= 2 and x <= 24 and y >= 5 and y <= (4 + #farms) then
- selected_idx = y - 4
- refresh_screen()
- end
- if x >= 2 and x <= 24 and y == 19 then
- add_farm_menu()
- refresh_screen()
- end
- local f = farms[selected_idx]
- if f then
- if x >= 29 and x <= 45 and y == 9 then
- f.sower_on = not f.sower_on; update_redstone(); refresh_screen()
- elseif x >= 51 and x <= 67 and y == 9 then
- f.gath_on = not f.gath_on; update_redstone(); refresh_screen()
- elseif x >= 29 and x <= 40 and y == 13 then
- f.sower_on = true; f.gath_on = true; update_redstone(); refresh_screen()
- elseif x >= 46 and x <= 58 and y == 13 then
- f.sower_on = false; f.gath_on = false; update_redstone(); refresh_screen()
- elseif x >= 29 and x <= 55 and y == 17 then
- table.remove(farms, selected_idx)
- if selected_idx > #farms then selected_idx = #farms end
- if selected_idx == 0 then selected_idx = 1 end
- save_data(); update_redstone(); refresh_screen()
- end
- end
- elseif current_tab == "ae2" then
- refresh_screen()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment