Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program is for OpenCCSensors 0.1.2
- os.loadAPI("ocs/apis/sensor")
- local sides = rs.getSides();
- local width = 0
- local height = 0
- local monitor = nil
- local function findPeripheralSide(type)
- for key, side in pairs(sides) do
- if peripheral.isPresent(side) and peripheral.getType(side) == type then
- return side;
- end
- end
- end
- local function findMonitor()
- local side = findPeripheralSide("monitor")
- if side then
- return peripheral.wrap(side)
- end
- end
- local function findSensor()
- local side = findPeripheralSide("sensor")
- if side then
- return sensor.wrap(side)
- end
- end
- local function getColorIndex(x, y)
- return ((x-1) + (y-1) * 128) + 1
- end
- local function drawPixel(x, y, color)
- monitor.setCursorPos(x, y)
- monitor.setBackgroundColor(color)
- monitor.write(" ")
- end
- local function displayMapColors(colors)
- for x=1, width do
- for y=1, height do
- local index = getColorIndex(x, y)
- local color = colors[index]
- drawPixel(x, y, color)
- end
- end
- end
- local function findPossibleTargets(sen)
- local maps = {};
- for key, data in pairs(sen.getTargets()) do
- local details = sen.getTargetDetails(key)
- for slot, slotd in pairs(details.Slots) do
- if slotd.Name == "item.map" then
- table.insert(maps, { target = key, slot = slot })
- end
- end
- end
- return maps;
- end
- while true do
- monitor = findMonitor();
- monitor.setTextScale(0.5)
- if monitor == nil then
- error("no monitor attached")
- end
- width, height = monitor.getSize()
- local inventory = findSensor()
- if inventory == nil then
- error("no sensor attached")
- end
- local possibleMaps = findPossibleTargets(inventory)
- local firstMap = table.remove(possibleMaps, 1)
- if firstMap ~= nil then
- local width, height = monitor.getSize()
- local mapData = inventory.sensorCardCall("getMapData", firstMap.target, firstMap.slot)
- displayMapColors(mapData.Colors, offsetX, offsetY)
- monitor.setCursorPos(1, height)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.write(mapData.MapName)
- end
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement