Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load libraries
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local serialization = require("serialization")
- local rs = component.redstone
- local mobChest = "44f855ef-3668-484f-bde5-75b175ef4c5d"
- local duplicatorInv = "587a6a6b-21b4-410a-a530-08392b4daa68"
- -- Load peripherals
- local chest = component.proxy(mobChest)
- local dup = component.proxy(duplicatorInv)
- local gpu = component.gpu
- local modem = component.modem
- local colors = {
- ["black"] = 0x000000,
- ["charcoal"] = 0x282828,
- ["darkGray"] = 0x555555,
- ["gray"] = 0x808080,
- ["silver"] = 0xBFBFBF,
- ["lightGray"] = 0xD3D3D3,
- ["ghostWhite"] = 0xF8F8FF,
- ["white"] = 0xFFFFFF,
- ["navy"] = 0x000080,
- ["darkBlue"] = 0x0000AA,
- ["mediumBlue"] = 0x0000CD,
- ["blue"] = 0x0000FF,
- ["dodgerBlue"] = 0x1E90FF,
- ["lightBlue"] = 0xADD8E6,
- ["skyBlue"] = 0x87CEEB,
- ["babyBlue"] = 0x89CFF0,
- ["darkGreen"] = 0x006400,
- ["green"] = 0x008000,
- ["mediumSeaGreen"] = 0x3CB371,
- ["limeGreen"] = 0x32CD32,
- ["lime"] = 0x00FF00,
- ["lightGreen"] = 0x90EE90,
- ["paleGreen"] = 0x98FB98,
- ["teal"] = 0x008080,
- ["darkCyan"] = 0x008B8B,
- ["cyan"] = 0x00FFFF,
- ["mediumAquamarine"] = 0x66CDAA,
- ["aquamarine"] = 0x7FFFD4,
- ["maroon"] = 0x800000,
- ["darkRed"] = 0x8B0000,
- ["red"] = 0xFF0000,
- ["firebrick"] = 0xB22222,
- ["indianRed"] = 0xCD5C5C,
- ["lightCoral"] = 0xF08080,
- ["salmon"] = 0xFA8072,
- ["lightSalmon"] = 0xFFA07A,
- ["darkMagenta"] = 0x8B008B,
- ["darkViolet"] = 0x9400D3,
- ["darkPurple"] = 0x800080,
- ["mediumPurple"] = 0x9370DB,
- ["purple"] = 0x800080,
- ["violet"] = 0xEE82EE,
- ["orchid"] = 0xDA70D6,
- ["thistle"] = 0xD8BFD8,
- ["darkGoldenrod"] = 0xB8860B,
- ["gold"] = 0xFFD700,
- ["khaki"] = 0xF0E68C,
- ["lightGoldenrod"] = 0xFAFAD2,
- ["darkOrange"] = 0xFF8C00,
- ["orange"] = 0xFFA500,
- ["lightOrange"] = 0xFFAD60,
- ["darkYellow"] = 0xDAA520,
- ["yellow"] = 0xFFFF00,
- ["lightYellow"] = 0xFFFFE0,
- ["lemon"] = 0xFFFACD
- }
- --╔════════════════════════╗
- --║ set/load functions ║
- --╚════════════════════════╝
- function setBG(color)
- gpu.setBackground(color)
- end
- function setFG(color)
- gpu.setForeground(color)
- end
- function setCursorPos(x, y)
- term.setCursor(x, y)
- end
- function openDoor()
- rs.setBundledOutput(3, 4, 255)
- enableRedLight() -- Enable the red light when the door is open
- diableGreenLight()
- end
- function closeDoor()
- rs.setBundledOutput(3, 4, 0)
- diableRedLight() -- Disable the red light when the door is closed
- enableGreenLight()
- end
- function enableRedLight()
- rs.setBundledOutput(3, 2, 255)
- end
- function diableRedLight()
- rs.setBundledOutput(3, 2, 0)
- end
- function enableGreenLight()
- rs.setBundledOutput(3, 3, 255)
- end
- function diableGreenLight()
- rs.setBundledOutput(3, 3, 0)
- end
- function enableGrinder()
- if rs.getBundledInput(3, 4) > 0 then
- -- The door is open, so do not enable the grinder
- return
- end
- rs.setBundledOutput(3, 1, 255)
- end
- function diableGrinder()
- if rs.getBundledInput(3, 4) > 0 then
- -- The door is open, so do not enable the duplicator
- return
- end
- rs.setBundledOutput(3, 1, 0)
- end
- function enableDuplicator()
- rs.setBundledOutput(3, 0, 255)
- end
- function disableDuplicator()
- rs.setBundledOutput(3, 0, 0)
- end
- function loadMobDuplicator()
- mobDupPosX = 25
- mobDupPosY = 38
- mobDupSizeX = 20
- mobDupSizeY = 10
- mobDupPrimaryColor = colors["white"]
- mobDupSecondaryColor = colors["cyan"]
- end
- function drawMobDuplicator()
- renderLine(mobDupPosX, mobDupPosY, mobDupSizeX, mobDupSizeY, mobDupPrimaryColor)
- renderLine(mobDupPosX+1, mobDupPosY, mobDupSizeX-2, 1, colors["teal"])
- renderLine(mobDupPosX+2, mobDupPosY+1, mobDupSizeX-4, 1, colors["charcoal"])
- renderLine(mobDupPosX+3, mobDupPosY+2, mobDupSizeX-6, 1, colors["charcoal"])
- renderLine(mobDupPosX+4, mobDupPosY+3, mobDupSizeX-8, 1, colors["charcoal"])
- renderLine(mobDupPosX+5, mobDupPosY+4, mobDupSizeX-10, 1, colors["charcoal"])
- renderLine(mobDupPosX+5, mobDupPosY+1, 1, mobDupSizeY-6, colors["teal"])
- renderLine(mobDupPosX+14, mobDupPosY+1, 1, mobDupSizeY-6, colors["teal"])
- renderLine(mobDupPosX+6, mobDupPosY+3, 8, 1, colors["teal"])
- end
- function updateMobDuplicator()
- end
- function loadMobGrinder()
- mobGrindPosX = 25
- mobGrindPosY = 25
- mobGrindSizeX = 20
- mobGrindSizeY = 10
- mobGrindPrimaryColor = colors["white"]
- mobGrindSecondaryColor = colors["cyan"]
- end
- function drawMobGrinderWheels()
- -- Draw two simple "wheels" in the center of the black box
- -- This assumes that the box is empty apart from the border
- -- Remember, the wheels won't look perfect due to text-based graphics limitations
- local wheelSymbol = "*"
- local wheelColor = colors["gray"]
- -- Calculate the center positions for the wheels
- local wheel1PosX = mobGrindPosX + 3
- local wheel2PosX = mobGrindPosX + 7
- local wheelPosY = mobGrindPosY + 2
- -- Draw the wheels
- renderLine(wheel1PosX, wheelPosY, 1, 1, colors["orchid"])
- --renderLine(wheel1PosX+1, wheelPosY, 1, 1, wheelColor)
- --renderLine(wheel1PosX, wheelPosY+1, 1, 1, wheelColor)
- --renderLine(wheel1PosX+1, wheelPosY+1, 1, 1, wheelColor)
- --renderLine(wheel2PosX, wheelPosY, 1, 1, wheelColor)
- --renderLine(wheel2PosX+1, wheelPosY, 1, 1, wheelColor)
- --renderLine(wheel2PosX, wheelPosY+1, 1, 1, wheelColor)
- --renderLine(wheel2PosX+1, wheelPosY+1, 1, 1, wheelColor)
- end
- function drawMobGrinder()
- renderLine(mobGrindPosX, mobGrindPosY, mobGrindSizeX, mobGrindSizeY, mobGrindPrimaryColor)
- renderLine(mobGrindPosX+1, mobGrindPosY+1, mobGrindSizeX-2, mobGrindSizeY-2, colors["charcoal"])
- renderLine(mobGrindPosX+1, mobGrindPosY+1, 1, 1, colors["white"])
- renderLine(mobGrindPosX+mobGrindSizeX-2, mobGrindPosY+1, 1, 1, colors["white"])
- renderLine(mobGrindPosX+1, mobGrindPosY+mobGrindSizeY-2, 1, 1, colors["white"])
- renderLine(mobGrindPosX+mobGrindSizeX-2, mobGrindPosY+mobGrindSizeY-2, 1, 1, colors["white"])
- drawMobGrinderWheels()
- end
- function updateMobGrinder()
- end
- function loadMainPanel()
- mainPanelX = 120
- mainPanelY = 8
- mainPanelSizeX = 32
- mainPanelSizeY = 31
- mainPanelPrimaryColor = colors["aquamarine"]
- mainPanelSecondaryColor = colors["black"]
- mobs = {}
- lookForMobTools()
- end
- function lookForMobTools()
- --scan for mob tool
- for slot = 1, 27 do
- local item = chest.getStackInSlot(1, slot)
- if item and item.name == "industrialforegoing:mob_imprisonment_tool" then
- local mobName = item.label:gsub("Mob Imprisonment Tool ", "") -- Remove "Mob Imprisonment Tool "
- if mobName == "(thermalfoundation.blitz)" then
- mobName = "(blitz)" -- Modify the mobName to just say "blitz"
- end
- table.insert(mobs, mobName)
- elseif item == nil then
- table.insert(mobs, "EMPTY")
- end
- end
- end
- function testFunc(text)
- setCursorPos(1, 2)
- setBG(0x000000)
- renderText(1, 2, 0xFF0000, text)
- end
- function buttonNew(label, posX, posY, sizeX, sizeY, ShowLabel, labelColor, buttonColor, func, func_DATA, buttonTable)
- local button = {
- label = label,
- posX =posX,
- posY = posY,
- sizeX = sizeX,
- sizeY = sizeY,
- ShowLabel = ShowLabel,
- labelColor = labelColor,
- buttonColor = buttonColor,
- func = func,
- func_DATA = func_DATA
- }
- table.insert(buttonTable, button)
- end
- function buttonLoad()
- mainMenuButtons = {}
- buttonNew("open door", 10, 10, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], openDoor, _, mainMenuButtons)
- buttonNew("close door", 10, 12, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], closeDoor, _, mainMenuButtons)
- buttonNew("enable spawner", 10, 14, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], enableDuplicator, _, mainMenuButtons)
- buttonNew("disable spawner", 10, 16, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], disableDuplicator, _, mainMenuButtons)
- buttonNew("enable grinder", 10, 18, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], enableGrinder, _, mainMenuButtons)
- buttonNew("disable grinder", 10, 20, 6, 1, true, colors["ghostWhite"], colors["darkBlue"], diableGrinder, _, mainMenuButtons)
- local line = 1
- for i =1, #mobs do
- buttonNew(mobs[i], mainPanelX+1, mainPanelY+i, string.len(mobs[i])+2, 1, true, colors["black"], colors["white"], testFunc, mobs[i], mainMenuButtons)
- end
- end
- function buttonDraw(buttonTable)
- for i = 1, #buttonTable do
- renderLine(buttonTable[i].posX, buttonTable[i].posY+1, string.len(buttonTable[i].label)+2, buttonTable[i].sizeY, buttonTable[i].buttonColor)
- renderText(buttonTable[i].posX+1, buttonTable[i].posY+1, buttonTable[i].labelColor, buttonTable[i].label)
- end
- end
- --╔════════════════════════╗
- --║ set/load functions ║
- --╚════════════════════════╝
- --╔════════════════════════╗
- --║ ui/draw Functions ║
- --╚════════════════════════╝
- function renderText(x, y, TextColor, text)
- setCursorPos(x, y)
- setFG(TextColor)
- term.write(text)
- end
- function renderLine (x, y, w, h, color)
- setBG(color)
- gpu.fill(x, y, w, h, " ")
- end
- function drawLine(x0, y0, x1, y1, color)
- local dx = math.abs(x1 - x0)
- local sx = x0 < x1 and 1 or -1
- local dy = -math.abs(y1 - y0)
- local sy = y0 < y1 and 1 or -1
- local err = dx + dy -- error value e_xy
- while true do
- renderLine(x0, y0, 1, 1, 0xff00ff)
- if x0 == x1 and y0 == y1 then break end
- local e2 = 2 * err
- if e2 >= dy then
- err = err + dy
- x0 = x0 + sx
- end
- if e2 <= dx then
- err = err + dx
- y0 = y0 + sy
- end
- end
- end
- --Progress Bar
- ProgressBar = {}
- ProgressBar.__index = ProgressBar
- -- create a new progress bar
- function ProgressBar.new(id, maxVal, len, color)
- local self = setmetatable({}, ProgressBar)
- self.id = id
- self.maxVal = maxVal
- self.currVal = 0
- self.len = len
- self.color = color
- return self
- end
- -- update progress bar value
- function ProgressBar:update(val)
- if val > self.maxVal then
- self.currVal = self.maxVal
- else
- self.currVal = val
- end
- self:draw()
- end
- -- draw the progress bar
- function ProgressBar:draw()
- local filledLen = math.floor((self.currVal / self.maxVal) * self.len)
- local unfilledLen = self.len - filledLen
- -- draw filled part
- renderLine(1, self.id, filledLen, 1, self.color)
- -- draw unfilled part
- if unfilledLen > 0 then
- renderLine(filledLen + 1, self.id, unfilledLen, 1, 0xFFFFFF) -- assuming 0xFFFFFF is background color
- end
- end
- -- handle multiple progress bars
- ProgressBarManager = {}
- ProgressBarManager.bars = {}
- -- add a new progress bar
- function ProgressBarManager.addBar(id, maxVal, len, color)
- local bar = ProgressBar.new(id, maxVal, len, color)
- ProgressBarManager.bars[id] = bar
- end
- -- update a specific progress bar
- function ProgressBarManager.updateBar(id, val)
- if ProgressBarManager.bars[id] then
- ProgressBarManager.bars[id]:update(val)
- else
- print("Invalid progress bar ID.")
- end
- end
- function drawMainPanel()
- renderLine(1, 1, 160, 50, mainPanelPrimaryColor)
- renderLine(mainPanelX, mainPanelY, mainPanelSizeX, mainPanelSizeY, mainPanelSecondaryColor)
- end
- --╔════════════════════════╗
- --║ ui/draw Functions ║
- --╚════════════════════════╝
- --╔══════════════════════╗
- --║ LOOP functions ║
- --╚══════════════════════╝
- -- Check for various events and handle them accordingly
- function checkForEvents()
- -- Open channel 5 on the modem
- --modem.open(5)
- -- Wait for the next event to occur and store the event information in eventData
- local eventData = {event.pull(0.1)}
- -- Check the type of event
- if eventData[1] == "key_down" then
- -- Handle keyboard events
- -- eventData[2] will contain the ASCII value of the key that was pressed
- elseif eventData[1] == "touch" then
- -- Handle touch events
- -- eventData[3] and eventData[4] will contain the X and Y coordinates of the touch event, respectively
- buttonCheck(eventData[3], eventData[4], mainMenuButtons)
- elseif eventData[1] == "modem_message" then
- -- Handle modem message events
- -- eventData[6] will contain the message sent over the modem
- local message = serialization.unserialize(eventData[6])
- if type(message) == "table" then
- end
- end
- -- Return true to continue checking for events
- return true
- end
- -- Check for button presses
- function buttonCheck(posX, posY, buttonTable)
- -- t is a flag to keep track of button presses
- local t = false
- -- Loop through all buttons in the buttonTable
- for i = 1, #buttonTable do
- -- Check if the touch event is within the bounds of the button
- local buttonPosX = posX >= buttonTable[i].posX and posX <= buttonTable[i].posX + buttonTable[i].sizeX
- local buttonPosY = posY >= buttonTable[i].posY and posY <= buttonTable[i].posY + buttonTable[i].sizeY
- -- If the touch event is within the bounds of the button
- if buttonPosX and buttonPosY then
- -- If the flag t is not set
- if not t then
- -- Set the flag t to true
- t = true
- -- Call the function stored in the button's `func` field and pass it the data stored in the `func_DATA` field
- buttonTable[i].func(buttonTable[i].func_DATA)
- end
- else
- -- If the touch event is not within the bounds of the button, set the flag t to false
- t = false
- end
- end
- end
- function updateMainPanel()
- end
- --╔══════════════════════╗
- --║ LOOP functions ║
- --╚══════════════════════╝
- --╔══════════════════════╗
- --║ MAIN functions ║
- --╚══════════════════════╝
- function load()
- -- This is where you would put any setup code that needs to run before the main loop starts.
- -- For example, you might want to clear the terminal screen:
- term.clear()
- loadMainPanel()
- buttonLoad()
- loadMobDuplicator()
- loadMobGrinder()
- end
- function update()
- checkForEvents()
- updateMainPanel()
- updateMobDuplicator()
- end
- function draw()
- -- This is where you would put any code that needs to update the display.
- -- For example, you might want to print a message to the screen:
- renderText(1, 1, 0xFFFFFF, "Listening for events...")
- drawMainPanel()
- buttonDraw(mainMenuButtons)
- drawMobDuplicator()
- drawMobGrinder()
- end
- --╔══════════════════════╗
- --║ MAIN functions ║
- --╚══════════════════════╝
- function main()
- load()
- draw()
- while true do
- update()
- os.sleep(0.0) -- Add a small delay to prevent the program from using 100% CPU.
- end
- end
- -- Start the program
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement