Noldor

Mob Farm Controller

Jul 31st, 2025 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. -- Advanced Computer + Monitor + Bundled Cable Control Panel
  2.  
  3. -- Configuration
  4. local monitor = peripheral.wrap("top") -- replace "right" if your monitor is elsewhere
  5. local redstoneSide = "left"              -- bundled cable on this side
  6.  
  7. monitor.setTextScale(1)
  8. monitor.setBackgroundColor(colors.black)
  9. monitor.setTextColor(colors.white)
  10. monitor.clear()
  11.  
  12. -- Redirect paintutils and write functions to the monitor
  13. local oldTerm = term.current()
  14. term.redirect(monitor)
  15.  
  16. -- Device control buttons
  17. local devices = {
  18.   {label = "FAN",      color = colors.blue,   active = true },
  19.   {label = "LIGHT",    color = colors.white,  active = false},
  20.   {label = "MIXER",    color = colors.red,    active = true },
  21.   {label = "MONSTERS", color = colors.green,  active = true }
  22. }
  23.  
  24. -- Position helpers
  25. local function getDeviceButtonArea(index)
  26.   local x1 = 3
  27.   local y1 = 2 + (index - 1) * 4
  28.   local x2 = x1 + 20
  29.   local y2 = y1 + 2
  30.   return x1, y1, x2, y2
  31. end
  32.  
  33. -- Update bundled cable signal
  34. local function updateBundledOutput()
  35.   local signal = 0
  36.   for _, dev in ipairs(devices) do
  37.     if dev.active then
  38.       signal = bit.bor(signal, dev.color)
  39.     end
  40.   end
  41.   redstone.setBundledOutput(redstoneSide, signal)
  42. end
  43.  
  44. -- Draw device toggle button
  45. local function drawDeviceButton(index)
  46.   local dev = devices[index]
  47.   local x1, y1, x2, y2 = getDeviceButtonArea(index)
  48.   local bgColor = dev.active and dev.color or colors.gray
  49.  
  50.   paintutils.drawFilledBox(x1, y1, x2, y2, bgColor)
  51.  
  52.   local label = dev.label .. " [" .. (dev.active and "ON" or "OFF") .. "]"
  53.   local labelX = x1 + math.floor((x2 - x1 - #label) / 2)
  54.   term.setCursorPos(labelX, y1 + 1)
  55.   term.setTextColor(colors.black)
  56.   term.write(label)
  57. end
  58.  
  59. -- Redraw everything
  60. local function drawAllButtons()
  61.   term.setBackgroundColor(colors.black)
  62.   term.clear()
  63.  
  64.   for i = 1, #devices do
  65.     drawDeviceButton(i)
  66.   end
  67. end
  68.  
  69. -- Detect click on any button
  70. local function getClickedButton(x, y)
  71.   for i = 1, #devices do
  72.     local x1, y1, x2, y2 = getDeviceButtonArea(i)
  73.     if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
  74.       return i
  75.     end
  76.   end
  77.   return -1
  78. end
  79.  
  80. -- Initialize UI
  81. drawAllButtons()
  82. updateBundledOutput()
  83.  
  84. -- Event loop
  85. while true do
  86.   local event, side, x, y = os.pullEvent("monitor_touch")
  87.   local index = getClickedButton(x, y)
  88.  
  89.   if index >= 0 then
  90.     devices[index].active = not devices[index].active
  91.     drawDeviceButton(index)
  92.     updateBundledOutput()
  93.   end
  94. end
  95.  
Advertisement
Add Comment
Please, Sign In to add comment