Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wrap peripherals
- local detector = peripheral.wrap("back") -- Change if needed
- local monitor = peripheral.wrap("top")
- -- Monitor setup
- monitor.setTextScale(0.5)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- -- Radar and monitor parameters
- local monWidth, monHeight = monitor.getSize()
- local centerX, centerY = math.floor(monWidth / 2), math.floor(monHeight / 2)
- local maxRange = 10
- -- Click detection and display state
- local iconMap = {} -- screenX,screenY => entity
- local infoEntityUUID = nil -- UUID of selected entity
- local currentEntity = nil -- Cached entity data
- local infoBoxLines = 5
- local infoBoxXBtn = {x = monWidth - 2, y = 1} -- Position of [X] button
- -- Convert relative world position to screen
- local function toScreen(x, z)
- local scale = maxRange
- local screenX = centerX + math.floor(x / scale * centerX)
- local screenY = centerY + math.floor(z / scale * centerY)
- return screenX, screenY
- end
- -- Draw the info panel
- local function drawInfo(entity)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- for i = 1, infoBoxLines do
- monitor.setCursorPos(1, i)
- monitor.write(string.rep(" ", monWidth))
- end
- -- Draw [X] close button
- monitor.setCursorPos(infoBoxXBtn.x, infoBoxXBtn.y)
- monitor.setTextColor(colors.red)
- monitor.write("[X]")
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.white)
- monitor.write("Name: " .. (entity.name or "unknown"))
- monitor.setCursorPos(1, 2)
- monitor.write("Type: " .. (entity.type or "unknown"))
- monitor.setCursorPos(1, 3)
- monitor.write("Player: " .. tostring(entity.isPlayer))
- monitor.setCursorPos(1, 4)
- monitor.write(string.format("Pos: %.1f, %.1f, %.1f", entity.x, entity.y, entity.z))
- monitor.setBackgroundColor(colors.black)
- end
- -- Redraw radar and info panel
- local function drawRadar(entities)
- iconMap = {}
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- -- Radar center
- monitor.setCursorPos(centerX, centerY)
- monitor.setTextColor(colors.white)
- monitor.write("+")
- -- Plot entities
- for _, entity in ipairs(entities) do
- -- Skip armor stands
- if entity.type ~= "Armor Stand" then
- local screenX, screenY = toScreen(entity.x, entity.z)
- if screenX >= 1 and screenX <= monWidth and screenY >= 1 and screenY <= monHeight then
- local key = screenX .. "," .. screenY
- iconMap[key] = entity
- monitor.setCursorPos(screenX, screenY)
- if entity.isPlayer then
- monitor.setTextColor(colors.lime)
- monitor.write("P")
- else
- monitor.setTextColor(colors.red)
- monitor.write("E")
- end
- end
- -- Update selected entity if matched
- if infoEntityUUID and entity.uuid == infoEntityUUID then
- currentEntity = entity
- end
- end
- end
- if currentEntity then
- drawInfo(currentEntity)
- end
- monitor.setTextColor(colors.white)
- end
- -- Main loop
- while true do
- local entities = detector.nearbyEntities()
- drawRadar(entities)
- local timer = os.startTimer(1)
- while true do
- local event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- if x >= infoBoxXBtn.x and x <= infoBoxXBtn.x + 2 and y == infoBoxXBtn.y then
- infoEntityUUID = nil
- currentEntity = nil
- drawRadar(entities)
- else
- local key = x .. "," .. y
- if iconMap[key] then
- infoEntityUUID = iconMap[key].uuid
- currentEntity = iconMap[key]
- drawRadar(entities)
- end
- end
- elseif event == "timer" and side == timer then
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement