Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Color configuration for individual switches
- local switchColors = {
- colors.white, colors.orange, colors.magenta,
- colors.lightBlue, colors.yellow, colors.lime,
- colors.pink, colors.gray, colors.lightGray
- }
- -- Configuration of mob names that can be changed
- local mobNames = {
- "Creeper", "Zombie", "Silverfish",
- "Enderman", "Empty", "Empty",
- "Death Tome", "Empty", "Empty"
- }
- -- State of switches and grinder
- local switches = {}
- local grinderActive = false
- -- Monitor and modem setup
- local monitor = peripheral.wrap("top") -- Monitor on the right side
- local modem = peripheral.wrap("right") -- Ender modem on the front
- monitor.setTextScale(1) -- Set text scale to 1
- -- Function to draw the GUI on the monitor
- local function drawGUI()
- monitor.clear()
- local width, height = monitor.getSize()
- monitor.setCursorPos((width - 21) / 2, 1) -- Center the title
- monitor.write("Mob Farm Control Panel")
- -- Draw switch buttons
- for i = 1, 9 do
- local x = 3 + ((i - 1) % 3) * 13
- local y = 4 + math.floor((i - 1) / 3) * 3
- monitor.setCursorPos(x, y)
- if switches[i] then
- monitor.setTextColor(colors.green)
- monitor.write("ACTIVE")
- else
- monitor.setTextColor(colors.red)
- monitor.write("INACTIVE")
- end
- monitor.setCursorPos(x, y + 1)
- monitor.setTextColor(colors.white)
- monitor.write(mobNames[i]) -- Displaying mob name
- end
- -- Draw grinder button at position (12, 15)
- monitor.setCursorPos(12, 15)
- if grinderActive then
- monitor.setTextColor(colors.green)
- monitor.write("[ MASHERS ON ]")
- else
- monitor.setTextColor(colors.red)
- monitor.write("[ MASHERS OFF ]")
- end
- -- Buttons ALL (8, 17) and RESET (24, 17)
- monitor.setCursorPos(8, 17)
- monitor.setTextColor(colors.yellow)
- monitor.write("[ MAX ]")
- monitor.setCursorPos(24, 17)
- monitor.write("[ SCRAM ]")
- monitor.setTextColor(colors.white)
- end
- -- Function to send signals to the second computer
- local function sendSignal(id, state)
- if modem then
- modem.transmit(1, 1, {id = id, state = state})
- end
- end
- -- Function to toggle the state of a switch
- local function toggleSwitch(index)
- switches[index] = not switches[index]
- sendSignal(index, switches[index]) -- Send the switch signal
- drawGUI()
- end
- -- Function to handle the main grinder button
- local function toggleGrinder()
- grinderActive = not grinderActive
- rs.setOutput("bottom", grinderActive) -- Set redstone signal to the left side
- drawGUI()
- end
- -- Function to handle the ALL button
- local function activateAllSwitches()
- for i = 1, 9 do
- switches[i] = true
- sendSignal(i, true) -- Activate each switch
- end
- drawGUI()
- end
- -- Function to handle the RESET button
- local function resetAllSwitches()
- for i = 1, 9 do
- switches[i] = false
- sendSignal(i, false) -- Deactivate each switch
- end
- drawGUI()
- end
- -- Function to initialize all signals to 0 at the first startup
- local function initializeRedstone()
- for i = 1, 9 do
- sendSignal(i, false) -- Set each signal to 0
- end
- rs.setOutput("left", false) -- Turn off grinder signal
- end
- -- Function to change mob names
- local function setMobName(index, newName)
- mobNames[index] = newName
- drawGUI()
- end
- -- Main program loop to handle user touches on the monitor
- local function main()
- -- Initialize switches and redstone
- for i = 1, 9 do switches[i] = false end -- Set all switches to false
- initializeRedstone() -- Set all signals to 0
- drawGUI() -- Draw GUI
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- -- Check for clicks on individual switch buttons
- for i = 1, 9 do
- local sx = 3 + ((i - 1) % 3) * 13
- local sy = 4 + math.floor((i - 1) / 3) * 3
- if x >= sx and x <= sx + 6 and y == sy then
- toggleSwitch(i)
- end
- end
- -- Check for click on the mashers button at position (12, 15)
- if x >= 12 and x <= 24 and y == 15 then
- toggleGrinder()
- end
- -- Check for click on MAX button at position (8, 17)
- if x >= 8 and x <= 14 and y == 17 then
- activateAllSwitches()
- end
- -- Check for click on SCRAM button at position (24, 17)
- if x >= 24 and x <= 30 and y == 17 then
- resetAllSwitches()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement