GLaDOS446

FARMCONTROL OC

Jun 10th, 2026 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.27 KB | Source Code | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local serialization = require("serialization")
  5.  
  6. local gpu = component.gpu
  7.  
  8. -- AUTOMATISCHE AE2-SUCHE (Jetzt korrigiert!)
  9. local ae2 = nil
  10. local ae2_type = nil
  11. for addr, ctype in component.list() do
  12.   if ctype and ctype:sub(1, 3) == "me_" then
  13.     ae2 = component.proxy(addr) -- Holt sich die echte Steuerung fuer den Block
  14.     ae2_type = ctype
  15.     break
  16.   end
  17. end
  18.  
  19. -- CONFIG
  20. local PASSWORD = "admin"
  21. local SAVE_FILE = "/home/farm_config_v3.dat"
  22.  
  23. local sides = { [0]="Unten", [1]="Oben", [2]="Norden", [3]="Sueden", [4]="Westen", [5]="Osten" }
  24. local farms = {}
  25. local selected_idx = 1
  26. local current_tab = "farms"
  27.  
  28. local function get_redstone_devices()
  29.   local list = {}
  30.   for addr in component.list("redstone") do table.insert(list, addr) end
  31.   return list
  32. end
  33.  
  34. local function save_data()
  35.   local f = io.open(SAVE_FILE, "w")
  36.   if f then f:write(serialization.serialize(farms)); f:close() end
  37. end
  38.  
  39. local function load_data()
  40.   local f = io.open(SAVE_FILE, "r")
  41.   if f then
  42.     local content = f:read("*a")
  43.     f:close()
  44.     farms = serialization.unserialize(content) or {}
  45.   else
  46.     local devices = get_redstone_devices()
  47.     local first_uuid = devices[1] or "KEIN_BLOCK_GEFUNDEN"
  48.     farms = {{name="Feld 1", redstone_uuid=first_uuid, sower_side=2, gath_side=3, sower_on=false, gath_on=false}}
  49.     save_data()
  50.   end
  51. end
  52.  
  53. local function update_redstone()
  54.   for _, farm in ipairs(farms) do
  55.     if farm.redstone_uuid and farm.redstone_uuid ~= "KEIN_BLOCK_GEFUNDEN" then
  56.       if component.type(farm.redstone_uuid) == "redstone" then
  57.         local proxy = component.proxy(farm.redstone_uuid)
  58.         if proxy then
  59.           proxy.setOutput(farm.sower_side, farm.sower_on and 15 or 0)
  60.           proxy.setOutput(farm.gath_side, farm.gath_on and 15 or 0)
  61.         end
  62.       end
  63.     end
  64.   end
  65. end
  66.  
  67. local function draw_text(x, y, text, fg, bg)
  68.   if fg then gpu.setForeground(fg) end
  69.   if bg then gpu.setBackground(bg) end
  70.   gpu.set(x, y, tostring(text))
  71. end
  72.  
  73. local function safe_read(mask)
  74.   local status, result = pcall(term.read, nil, nil, nil, mask)
  75.   if status and result then return result:gsub("\n", "") end
  76.   return ""
  77. end
  78.  
  79. local function do_login()
  80.   while true do
  81.     term.clear()
  82.     draw_text(20, 5, "=== SECURITY LOGIN ===", 0x00FFFF, 0x000000)
  83.     draw_text(15, 8, "Bitte Passwort eingeben:", 0xFFFFFF)
  84.     gpu.set(15, 10, "[                    ]")
  85.     term.setCursor(16, 10)
  86.     local input = safe_read("*")
  87.     if input == PASSWORD then break end
  88.     draw_text(17, 13, "FALSCHES PASSWORT!", 0xFF0000)
  89.     os.sleep(1.5)
  90.   end
  91. end
  92.  
  93. local function draw_navigation()
  94.   gpu.setResolution(75, 22)
  95.   gpu.setBackground(0x222222)
  96.   gpu.fill(1, 1, 75, 1, " ")
  97.  
  98.   local farms_bg = (current_tab == "farms") and 0x00E5FF or 0x222222
  99.   local farms_fg = (current_tab == "farms") and 0x000000 or 0xFFFFFF
  100.   draw_text(2, 1, " [1] FARMS & CONTROLLER ", farms_fg, farms_bg)
  101.  
  102.   local ae2_bg = (current_tab == "ae2") and 0x00E5FF or 0x222222
  103.   local ae2_fg = (current_tab == "ae2") and 0x000000 or 0xFFFFFF
  104.   draw_text(28, 1, " [2] AE2 SPEICHERANZEIGE ", ae2_fg, ae2_bg)
  105.  
  106.   gpu.setBackground(0x000000)
  107.   draw_text(1, 2, string.rep("-", 75), 0x555555)
  108. end
  109.  
  110. local function draw_dashboard()
  111.   draw_text(2, 4, "FARMLISTE:", 0xFFFF00)
  112.   for i, farm in ipairs(farms) do
  113.     local y = 4 + i
  114.     if i == selected_idx then
  115.       draw_text(2, y, "> " .. farm.name, 0x00FF00)
  116.     else
  117.       draw_text(4, y, farm.name, 0xFFFFFF)
  118.     end
  119.   end
  120.  
  121.   draw_text(2, 19, "[+] NEUE FARM ANLEGEN", 0x000000, 0x00FF00)
  122.   for y = 3, 20 do gpu.set(26, y, "|") end
  123.  
  124.   local f = farms[selected_idx]
  125.   if f then
  126.     draw_text(29, 4, "DETAILS: " .. f.name:upper(), 0x00E5FF, 0x000000)
  127.     local short_uuid = tostring(f.redstone_uuid):sub(1, 8) .. "..."
  128.     draw_text(29, 5, "Block-UUID: " .. short_uuid, 0x00FF00)
  129.     draw_text(29, 6, "Sower-Seite: " .. sides[f.sower_side] .. " | Ernter-Seite: " .. sides[f.gath_side], 0x888888)
  130.    
  131.     if f.sower_on then
  132.       draw_text(29, 9, "  SOWER: AKTIV   ", 0x000000, 0x00FF00)
  133.     else
  134.       draw_text(29, 9, "  SOWER: INAKTIV ", 0xFFFFFF, 0xFF0000)
  135.     end
  136.    
  137.     if f.gath_on then
  138.       draw_text(51, 9, " ERNTER: AKTIV   ", 0x000000, 0x00FF00)
  139.     else
  140.       draw_text(51, 9, " ERNTER: INAKTIV ", 0xFFFFFF, 0xFF0000)
  141.     end
  142.    
  143.     draw_text(29, 13, "[ BEIDE AN ]", 0x000000, 0xAAAAAA)
  144.     draw_text(46, 13, "[ BEIDE AUS ]", 0x000000, 0xAAAAAA)
  145.     draw_text(29, 17, "[ FARM COMPLETE LOESCHEN ]", 0xFFFFFF, 0x993333)
  146.   else
  147.     draw_text(29, 9, "Keine Farm aktiv. Klicke links auf [+].", 0x888888, 0x000000)
  148.   end
  149. end
  150.  
  151. local function draw_ae2_storage()
  152.   draw_text(2, 4, "AE2 NETZWERK-STATUS:", 0x00E5FF, 0x000000)
  153.  
  154.   if not ae2 then
  155.     draw_text(2, 6, "FEHLER: Kein AE2-Bauteil am Adapter erkannt!", 0xFF0000)
  156.     draw_text(2, 7, "Bitte ueberpruefe die OC-Verkabelung zum AE2-Netzwerk.", 0x888888)
  157.     return
  158.   end
  159.  
  160.   draw_text(2, 6, "Verbunden via: " .. ae2_type .. " (Lese Speicher...)", 0x00FF00)
  161.  
  162.   -- Probiere verschiedene AE2-API-Methoden aus (Versionsunabhaengig)
  163.   local success, items = pcall(ae2.getItemsInNetwork)
  164.   if not success or not items then success, items = pcall(ae2.getAvailableItems) end
  165.   if not success or not items then success, items = pcall(ae2.getStoredItems) end
  166.  
  167.   if success and items then
  168.     draw_text(2, 8, string.rep("-", 71), 0x555555)
  169.     draw_text(2, 9, "Item Name", 0xFFFF00)
  170.     draw_text(50, 9, "Anzahl im Lager", 0xFFFF00)
  171.     draw_text(2, 10, string.rep("-", 71), 0x555555)
  172.    
  173.     local row = 11
  174.     local count = 0
  175.     for _, item in pairs(items) do
  176.       if item and (item.label or item.name) then
  177.         local label = item.label or item.name
  178.         local amount = item.size or item.amount or 0
  179.        
  180.         if count < 10 and amount > 0 then
  181.           if #label > 45 then label = label:sub(1, 42) .. "..." end
  182.           draw_text(2, row, label, 0xFFFFFF)
  183.           draw_text(50, row, string.format("%d", amount), 0x00FF00)
  184.           row = row + 1
  185.           count = count + 1
  186.         end
  187.       end
  188.     end
  189.     if count == 0 then
  190.       draw_text(2, 11, "Keine Items mit einer Anzahl > 0 gefunden.", 0x888888)
  191.     end
  192.   else
  193.     draw_text(2, 8, "Fehler beim Abrufen der Items. Methode nicht unterstuetzt.", 0xFF0000)
  194.   end
  195. end
  196.  
  197. local function refresh_screen()
  198.   term.clear()
  199.   draw_navigation()
  200.   if current_tab == "farms" then draw_dashboard()
  201.   elseif current_tab == "ae2" then draw_ae2_storage() end
  202. end
  203.  
  204. local function add_farm_menu()
  205.   term.clear()
  206.   draw_text(5, 2, "=== NEUE FARM ANLEGEN ===", 0xFFFF00, 0x000000)
  207.   draw_text(5, 5, "Name der Farm eingeben: ")
  208.   term.setCursor(5, 6)
  209.  
  210.   local name = safe_read()
  211.   if name == "" then name = "Feld " .. (#farms + 1) end
  212.  
  213.   local devices = get_redstone_devices()
  214.   if #devices == 0 then
  215.     term.clear()
  216.     draw_text(5, 5, "FEHLER: Kein Redstone I/O Block gefunden!", 0xFF0000)
  217.     os.sleep(3)
  218.     return
  219.   end
  220.  
  221.   local dev_idx = 1
  222.   local new_farm = {name=name, redstone_uuid=devices[dev_idx], sower_side=2, gath_side=3, sower_on=false, gath_on=false}
  223.  
  224.   while true do
  225.     term.clear()
  226.     draw_text(5, 2, "=== KONFIGURATION: " .. name .. " ===", 0xFFFF00, 0x000000)
  227.    
  228.     local short_uuid = tostring(new_farm.redstone_uuid):sub(1, 8) .. "..."
  229.     draw_text(5, 5,  "1. I/O Block (UUID): < " .. short_uuid .. " > ("..dev_idx.."/"..#devices..")", 0xFFFFFF)
  230.     draw_text(5, 7,  "2. Seite Sower      : < " .. sides[new_farm.sower_side] .. " >", 0xFFFFFF)
  231.     draw_text(5, 9,  "3. Seite Gatherer   : < " .. sides[new_farm.gath_side] .. " >", 0xFFFFFF)
  232.    
  233.     draw_text(5, 14, "[ SPEICHERN ]", 0x000000, 0x00FF00)
  234.     draw_text(22, 14, "[ ABBRECHEN ]", 0xFFFFFF, 0xFF0000)
  235.    
  236.     local _, _, x, y = event.pull("touch")
  237.    
  238.     if y == 5 then
  239.       if x >= 26 and x <= 28 then
  240.         dev_idx = dev_idx - 1; if dev_idx < 1 then dev_idx = #devices end
  241.         new_farm.redstone_uuid = devices[dev_idx]
  242.       end
  243.       if x >= 42 and x <= 48 then
  244.         dev_idx = dev_idx + 1; if dev_idx > #devices then dev_idx = 1 end
  245.         new_farm.redstone_uuid = devices[dev_idx]
  246.       end
  247.     elseif y == 7 then
  248.       if x >= 26 and x <= 28 then new_farm.sower_side = (new_farm.sower_side - 1) % 6 end
  249.       if x >= 42 and x <= 47 then new_farm.sower_side = (new_farm.sower_side + 1) % 6 end
  250.     elseif y == 9 then
  251.       if x >= 26 and x <= 28 then new_farm.gath_side = (new_farm.gath_side - 1) % 6 end
  252.       if x >= 42 and x <= 47 then new_farm.gath_side = (new_farm.gath_side + 1) % 6 end
  253.     elseif y == 14 and x >= 5 and x <= 17 then
  254.       table.insert(farms, new_farm)
  255.       save_data()
  256.       selected_idx = #farms
  257.       break
  258.     elseif y == 14 and x >= 22 and x <= 34 then
  259.       break
  260.     end
  261.   end
  262.   update_redstone()
  263. end
  264.  
  265. load_data()
  266. do_login()
  267. update_redstone()
  268. refresh_screen()
  269.  
  270. while true do
  271.   local _, _, x, y = event.pull("touch")
  272.  
  273.   if y == 1 then
  274.     if x >= 2 and x <= 25 then current_tab = "farms"; refresh_screen()
  275.     elseif x >= 28 and x <= 52 then current_tab = "ae2"; refresh_screen() end
  276.   end
  277.  
  278.   if current_tab == "farms" then
  279.     if x >= 2 and x <= 24 and y >= 5 and y <= (4 + #farms) then
  280.       selected_idx = y - 4
  281.       refresh_screen()
  282.     end
  283.     if x >= 2 and x <= 24 and y == 19 then
  284.       add_farm_menu()
  285.       refresh_screen()
  286.     end
  287.    
  288.     local f = farms[selected_idx]
  289.     if f then
  290.       if x >= 29 and x <= 45 and y == 9 then
  291.         f.sower_on = not f.sower_on; update_redstone(); refresh_screen()
  292.       elseif x >= 51 and x <= 67 and y == 9 then
  293.         f.gath_on = not f.gath_on; update_redstone(); refresh_screen()
  294.       elseif x >= 29 and x <= 40 and y == 13 then
  295.         f.sower_on = true; f.gath_on = true; update_redstone(); refresh_screen()
  296.       elseif x >= 46 and x <= 58 and y == 13 then
  297.         f.sower_on = false; f.gath_on = false; update_redstone(); refresh_screen()
  298.       elseif x >= 29 and x <= 55 and y == 17 then
  299.         table.remove(farms, selected_idx)
  300.         if selected_idx > #farms then selected_idx = #farms end
  301.         if selected_idx == 0 then selected_idx = 1 end
  302.         save_data(); update_redstone(); refresh_screen()
  303.       end
  304.     end
  305.   elseif current_tab == "ae2" then
  306.     refresh_screen()
  307.   end
  308. end
Advertisement
Add Comment
Please, Sign In to add comment