Advertisement
BookerTheGeek

CC Mob Farm Main

Feb 25th, 2025 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.58 KB | None | 0 0
  1. -- Color configuration for individual switches
  2. local switchColors = {
  3.     colors.white, colors.orange, colors.magenta,
  4.     colors.lightBlue, colors.yellow, colors.lime,
  5.     colors.pink, colors.gray, colors.lightGray
  6. }
  7.  
  8. -- Configuration of mob names that can be changed
  9. local mobNames = {
  10.     "Creeper", "Zombie", "Silverfish",
  11.     "Enderman", "Empty", "Empty",
  12.     "Death Tome", "Empty", "Empty"
  13. }
  14.  
  15. -- State of switches and grinder
  16. local switches = {}
  17. local grinderActive = false
  18.  
  19. -- Monitor and modem setup
  20. local monitor = peripheral.wrap("top") -- Monitor on the right side
  21. local modem = peripheral.wrap("right") -- Ender modem on the front
  22.  
  23. monitor.setTextScale(1) -- Set text scale to 1
  24.  
  25. -- Function to draw the GUI on the monitor
  26. local function drawGUI()
  27.     monitor.clear()
  28.     local width, height = monitor.getSize()
  29.     monitor.setCursorPos((width - 21) / 2, 1) -- Center the title
  30.     monitor.write("Mob Farm Control Panel")
  31.  
  32.     -- Draw switch buttons
  33.     for i = 1, 9 do
  34.         local x = 3 + ((i - 1) % 3) * 13
  35.         local y = 4 + math.floor((i - 1) / 3) * 3
  36.         monitor.setCursorPos(x, y)
  37.         if switches[i] then
  38.             monitor.setTextColor(colors.green)
  39.             monitor.write("ACTIVE")
  40.         else
  41.             monitor.setTextColor(colors.red)
  42.             monitor.write("INACTIVE")
  43.         end
  44.         monitor.setCursorPos(x, y + 1)
  45.         monitor.setTextColor(colors.white)
  46.         monitor.write(mobNames[i]) -- Displaying mob name
  47.     end
  48.  
  49.     -- Draw grinder button at position (12, 15)
  50.     monitor.setCursorPos(12, 15)
  51.     if grinderActive then
  52.         monitor.setTextColor(colors.green)
  53.         monitor.write("[ MASHERS ON ]")
  54.     else
  55.         monitor.setTextColor(colors.red)
  56.         monitor.write("[ MASHERS OFF ]")
  57.     end
  58.  
  59.     -- Buttons ALL (8, 17) and RESET (24, 17)
  60.     monitor.setCursorPos(8, 17)
  61.     monitor.setTextColor(colors.yellow)
  62.     monitor.write("[ MAX ]")
  63.  
  64.     monitor.setCursorPos(24, 17)
  65.     monitor.write("[ SCRAM ]")
  66.     monitor.setTextColor(colors.white)
  67. end
  68.  
  69. -- Function to send signals to the second computer
  70. local function sendSignal(id, state)
  71.     if modem then
  72.         modem.transmit(1, 1, {id = id, state = state})
  73.     end
  74. end
  75.  
  76. -- Function to toggle the state of a switch
  77. local function toggleSwitch(index)
  78.     switches[index] = not switches[index]
  79.     sendSignal(index, switches[index]) -- Send the switch signal
  80.     drawGUI()
  81. end
  82.  
  83. -- Function to handle the main grinder button
  84. local function toggleGrinder()
  85.     grinderActive = not grinderActive
  86.     rs.setOutput("bottom", grinderActive) -- Set redstone signal to the left side
  87.     drawGUI()
  88. end
  89.  
  90. -- Function to handle the ALL button
  91. local function activateAllSwitches()
  92.     for i = 1, 9 do
  93.         switches[i] = true
  94.         sendSignal(i, true) -- Activate each switch
  95.     end
  96.     drawGUI()
  97. end
  98.  
  99. -- Function to handle the RESET button
  100. local function resetAllSwitches()
  101.     for i = 1, 9 do
  102.         switches[i] = false
  103.         sendSignal(i, false) -- Deactivate each switch
  104.     end
  105.     drawGUI()
  106. end
  107.  
  108. -- Function to initialize all signals to 0 at the first startup
  109. local function initializeRedstone()
  110.     for i = 1, 9 do
  111.         sendSignal(i, false) -- Set each signal to 0
  112.     end
  113.     rs.setOutput("left", false) -- Turn off grinder signal
  114. end
  115.  
  116. -- Function to change mob names
  117. local function setMobName(index, newName)
  118.     mobNames[index] = newName
  119.     drawGUI()
  120. end
  121.  
  122. -- Main program loop to handle user touches on the monitor
  123. local function main()
  124.     -- Initialize switches and redstone
  125.     for i = 1, 9 do switches[i] = false end -- Set all switches to false
  126.     initializeRedstone() -- Set all signals to 0
  127.     drawGUI() -- Draw GUI
  128.  
  129.     while true do
  130.         local event, side, x, y = os.pullEvent("monitor_touch")
  131.  
  132.         -- Check for clicks on individual switch buttons
  133.         for i = 1, 9 do
  134.             local sx = 3 + ((i - 1) % 3) * 13
  135.             local sy = 4 + math.floor((i - 1) / 3) * 3
  136.             if x >= sx and x <= sx + 6 and y == sy then
  137.                 toggleSwitch(i)
  138.             end
  139.         end
  140.  
  141.         -- Check for click on the mashers button at position (12, 15)
  142.         if x >= 12 and x <= 24 and y == 15 then
  143.             toggleGrinder()
  144.         end
  145.  
  146.         -- Check for click on MAX button at position (8, 17)
  147.         if x >= 8 and x <= 14 and y == 17 then
  148.             activateAllSwitches()
  149.         end
  150.  
  151.         -- Check for click on SCRAM button at position (24, 17)
  152.         if x >= 24 and x <= 30 and y == 17 then
  153.             resetAllSwitches()
  154.         end
  155.     end
  156. end
  157.  
  158. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement