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
- 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)
- ae2_type = ctype
- break
- end
- end
- -- CONFIG
- local PASSWORD = "admin"
- local SAVE_FILE = "/home/farm_config_v3.dat"
- -- ECHTE SEITENNAMEN STATT HIMMELSRICHTUNGEN
- local sides = { [0]="Unten", [1]="Oben", [2]="Vorne", [3]="Hinten", [4]="Links", [5]="Rechts" }
- local farms = {}
- local selected_idx = 1
- local current_tab = "farms"
- 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
- -- Standard-Dummy falls keine Datei existiert
- farms = {{name="Feld 1", redstone_uuid="HIER_UUID_EINTRAGEN", 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, 18) .. "..."
- draw_text(29, 5, "Block-UUID: " .. short_uuid, 0x00FF00)
- draw_text(29, 6, "Sower: " .. sides[f.sower_side] .. " | Ernter: " .. 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, 3, "AE2 NETZWERK-STATUS (Auto-Update: 5s)", 0x00E5FF, 0x000000)
- if not ae2 then
- draw_text(2, 5, "FEHLER: Kein AE2-Bauteil am Adapter erkannt!", 0xFF0000)
- return
- end
- local usage_ok, usage = pcall(ae2.getAvgPowerUsage)
- local stored_ok, stored = pcall(ae2.getStoredPower)
- local max_ok, max_p = pcall(ae2.getMaxPowerStorage)
- local p_str = "Stromverbrauch: " .. (usage_ok and string.format("%.1f RF/t", usage * 2) or "N/A")
- if stored_ok and max_ok then
- p_str = p_str .. string.format(" | Speicher-Puffer: %d/%d RF", stored * 2, max_p * 2)
- end
- draw_text(2, 4, p_str, 0xFFFF00)
- draw_text(2, 5, "Schnittstelle: " .. ae2_type, 0x888888)
- draw_text(1, 6, string.rep("-", 75), 0x555555)
- local item_ok, items = pcall(ae2.getItemsInNetwork)
- if not item_ok or not items then item_ok, items = pcall(ae2.getAvailableItems) end
- if not item_ok or not items then item_ok, items = pcall(ae2.getStoredItems) end
- local fluid_ok, fluids = pcall(ae2.getFluidsInNetwork)
- if not fluid_ok or not fluids then fluid_ok, fluids = pcall(ae2.getAvailableFluids) end
- if not fluid_ok or not fluids then fluid_ok, fluids = pcall(ae2.getStoredFluids) end
- for y = 7, 21 do gpu.set(38, y, "|") end
- -- Spalte 1: Items
- draw_text(2, 7, "[ GEGENSTAENDE / ITEMS ]", 0x00E5FF)
- draw_text(2, 8, "Name Menge", 0x555555)
- local item_row = 9
- local item_count = 0
- if item_ok and items then
- for _, item in pairs(items) do
- if item and (item.label or item.name) and item_count < 13 then
- local label = item.label or item.name
- local amount = item.size or item.amount or 0
- if amount > 0 then
- if #label > 22 then label = label:sub(1, 19) .. "..." end
- draw_text(2, item_row, label, 0xFFFFFF)
- draw_text(26, item_row, string.format("%d", amount), 0x00FF00)
- item_row = item_row + 1
- item_count = item_count + 1
- end
- end
- end
- if item_count == 0 then draw_text(2, 9, "Keine Items im System.", 0x888888) end
- else
- draw_text(2, 9, "[Fehler bei Item-Abfrage]", 0xFF0000)
- end
- -- Spalte 2: Fluids
- draw_text(40, 7, "[ FLUESSIGKEITEN / FLUIDS ]", 0x00E5FF)
- draw_text(40, 8, "Name Menge", 0x555555)
- local fluid_row = 9
- local fluid_count = 0
- if fluid_ok and fluids then
- for _, fluid in pairs(fluids) do
- if fluid and (fluid.label or fluid.name) and fluid_count < 13 then
- local label = fluid.label or fluid.name
- local amount = fluid.amount or fluid.size or 0
- if amount > 0 then
- if #label > 22 then label = label:sub(1, 19) .. "..." end
- local amt_str = ""
- if amount >= 1000 then
- amt_str = string.format("%.1f B", amount / 1000)
- else
- amt_str = amount .. " mB"
- end
- draw_text(40, fluid_row, label, 0xFFFFFF)
- draw_text(64, fluid_row, amt_str, 0x00FFFF)
- fluid_row = fluid_row + 1
- fluid_count = fluid_count + 1
- end
- end
- end
- if fluid_count == 0 then draw_text(40, 9, "Keine Fluids im System.", 0x888888) end
- else
- draw_text(40, 9, "[Fehler bei Fluid-Abfrage]", 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
- -- NEUES ANLEGE-MENÜ MIT MANUELLER UUID EINGABE
- local function add_farm_menu()
- term.clear()
- draw_text(5, 2, "=== NEUE FARM ANLEGEN ===", 0xFFFF00, 0x000000)
- draw_text(5, 5, "1. Name der Farm eingeben:")
- term.setCursor(5, 6)
- local name = safe_read()
- if name == "" then name = "Feld " .. (#farms + 1) end
- draw_text(5, 9, "2. Redstone-Block UUID eingeben:")
- term.setCursor(5, 10)
- local uuid = safe_read()
- if uuid == "" then uuid = "KEIN_BLOCK_GEFUNDEN" end
- local new_farm = {name=name, redstone_uuid=uuid, sower_side=2, gath_side=3, sower_on=false, gath_on=false}
- while true do
- term.clear()
- draw_text(5, 2, "=== SEITEN-KONFIGURATION ===", 0xFFFF00, 0x000000)
- draw_text(5, 4, "Farm: " .. name, 0x00FF00)
- draw_text(5, 5, "UUID: " .. uuid:sub(1, 20) .. "...", 0x888888)
- -- Strukturierte Klick-Flächen mit [ - ] und [ + ]
- draw_text(5, 8, "Sower-Seite : [ - ] " .. string.format("%-7s", sides[new_farm.sower_side]) .. " [ + ]", 0xFFFFFF)
- draw_text(5, 11, "Ernter-Seite: [ - ] " .. string.format("%-7s", sides[new_farm.gath_side]) .. " [ + ]", 0xFFFFFF)
- draw_text(5, 16, "[ SPEICHERN ]", 0x000000, 0x00FF00)
- draw_text(22, 16, "[ ABBRECHEN ]", 0xFFFFFF, 0xFF0000)
- local _, _, x, y = event.pull("touch")
- -- Klick-Erkennung für die Buttons
- if y == 8 then
- if x >= 20 and x <= 25 then new_farm.sower_side = (new_farm.sower_side - 1) % 6 end
- if x >= 37 and x <= 44 then new_farm.sower_side = (new_farm.sower_side + 1) % 6 end
- elseif y == 11 then
- if x >= 20 and x <= 25 then new_farm.gath_side = (new_farm.gath_side - 1) % 6 end
- if x >= 37 and x <= 44 then new_farm.gath_side = (new_farm.gath_side + 1) % 6 end
- elseif y == 16 and x >= 5 and x <= 17 then
- table.insert(farms, new_farm)
- save_data()
- selected_idx = #farms
- break
- elseif y == 16 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 id, _, x, y = event.pull(5, "touch")
- if id == "touch" then
- 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
- elseif id == nil then
- if current_tab == "ae2" then
- refresh_screen()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment