Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load components
- local component = require("component")
- local sides = require("sides")
- local event = require("event")
- local term = require("term")
- local serialization = require("serialization")
- -- load peripherals
- local inventory_controller = component.inventory_controller
- local gpu = component.gpu
- local modem = component.modem
- local adapter_side = sides.east
- -- initialize variables
- local mobs = {}
- local selected = 1
- local dialogVisible = false
- -- Load function
- local function load()
- --scan for mob tool
- for slot = 1, inventory_controller.getInventorySize(1) do
- local item = inventory_controller.getStackInSlot(1, slot)
- if item and item.name == "industrialforegoing:mob_imprisonment_tool" then
- local nbt = item.nbt -- NBT data as a serialized string
- local mobName = item.label:gsub("Mob Imprisonment Tool ", "") -- Remove "Mob Imprisonment Tool "
- table.insert(mobs, mobName)
- end
- end
- end
- -- Function to draw the UI
- local function drawUI()
- term.clear()
- local width, height = gpu.getResolution()
- local boxWidth = 40
- local boxHeight = height - 6
- local boxX = math.floor((width - boxWidth) / 2)
- local boxY = math.floor((height - boxHeight) / 2)
- -- Draw the box
- gpu.setForeground(0xFFFFFF) -- White
- gpu.setBackground(0x000000) -- Black
- gpu.fill(boxX, boxY, boxWidth, boxHeight, " ")
- -- Draw the header
- term.setCursor(boxX + 2, boxY + 1)
- print("================================")
- term.setCursor(boxX + 2, boxY + 2)
- print(" MOB SPAWNER ")
- term.setCursor(boxX + 2, boxY + 3)
- print("================================")
- -- Draw the mobs
- for i, mob in ipairs(mobs) do
- local mobY = boxY + i + 3
- if i == selected then
- gpu.setForeground(0xFFFFFF) -- White
- gpu.setBackground(0x0000FF) -- Blue
- else
- gpu.setForeground(0x000000) -- Black
- gpu.setBackground(0xFFFFFF) -- White
- end
- term.setCursor(boxX + 2, mobY)
- term.write(mob)
- end
- -- Reset to default colors after drawing
- gpu.setForeground(0x000000) -- Black
- gpu.setBackground(0xFFFFFF) -- White
- end
- -- Function to draw the confirmation dialog
- local function drawDialog(mob)
- term.clear()
- local width, height = gpu.getResolution()
- local dialogWidth = 30
- local dialogHeight = 10
- local dialogX = math.floor((width - dialogWidth) / 2)
- local dialogY = math.floor((height - dialogHeight) / 2)
- -- Draw the dialog box
- gpu.setForeground(0xFFFFFF) -- White
- gpu.setBackground(0x000000) -- Black
- gpu.fill(dialogX, dialogY, dialogWidth, dialogHeight, " ")
- -- Draw the dialog content
- term.setCursor(dialogX + 2, dialogY + 1)
- print("================================")
- term.setCursor(dialogX + 2, dialogY + 2)
- print(" CONFIRMATION REQUIRED ")
- term.setCursor(dialogX + 2, dialogY + 3)
- print("================================")
- term.setCursor(dialogX + 2, dialogY + 5)
- print("Put " .. mob .. " in duplicator?")
- term.setCursor(dialogX + 2, dialogY + 7)
- print("Press 'Y' for YES")
- term.setCursor(dialogX + 2, dialogY + 8)
- print("Press 'C' for CANCEL")
- -- Reset to default colors after drawing
- gpu.setForeground(0x000000) -- Black
- gpu.setBackground(0xFFFFFF) -- White
- end
- -- Draw function
- local function draw()
- if not dialogVisible then
- drawUI()
- else
- drawDialog(mobs[selected])
- end
- end
- -- Update function
- local function update()
- local _, _, char, code = event.pull("key_down")
- if not dialogVisible then
- if code == 200 then -- Up arrow
- selected = math.max(selected - 1, 1)
- elseif code == 208 then -- Down arrow
- selected = math.min(selected + 1, #mobs)
- elseif code == 203 then -- Left arrow
- selected = selected - 1
- if selected < 1 then
- selected = #mobs
- end
- elseif code == 205 then -- Right arrow
- selected = selected + 1
- if selected > #mobs then
- selected = 1
- end
- elseif code == 28 then -- Enter
- if selected <= #mobs then
- dialogVisible = true
- end
- end
- else -- Handling events within the dialog
- if code == 28 then -- Enter
- modem.broadcast(123, mobs[selected])
- dialogVisible = false
- elseif code == 46 then -- C for CANCEL
- dialogVisible = false
- end
- end
- end
- -- Load the inventory first
- load()
- -- Main game loop
- while true do
- draw()
- update()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement