SHOW:
|
|
- or go back to the newest paste.
| 1 | -- This program is for OpenCCSensors 0.1.2 | |
| 2 | -- Monitor to be placed above the computer | |
| 3 | -- Sensor peripheral to be placed below the computer | |
| 4 | -- Inventory sensor card in the sensor (any level of card) | |
| 5 | -- A chest should be below the sensor, with a map in slot 1 | |
| 6 | ||
| 7 | os.loadAPI("ocs/apis/sensor")
| |
| 8 | local sides = rs.getSides(); | |
| 9 | - | local monitor = peripheral.wrap("top")
|
| 9 | + | |
| 10 | - | local inventory = sensor.wrap("bottom")
|
| 10 | + | local width = 0 |
| 11 | local height = 0 | |
| 12 | - | local width, height = monitor.getSize() |
| 12 | + | local monitor = nil |
| 13 | ||
| 14 | local function findPeripheralSide(type) | |
| 15 | for key, side in pairs(sides) do | |
| 16 | if peripheral.isPresent(side) and peripheral.getType(side) == type then | |
| 17 | return side; | |
| 18 | end | |
| 19 | end | |
| 20 | end | |
| 21 | ||
| 22 | local function findMonitor() | |
| 23 | local side = findPeripheralSide("monitor")
| |
| 24 | if side then | |
| 25 | return peripheral.wrap(side) | |
| 26 | end | |
| 27 | end | |
| 28 | ||
| 29 | local function findSensor() | |
| 30 | local side = findPeripheralSide("sensor")
| |
| 31 | if side then | |
| 32 | return sensor.wrap(side) | |
| 33 | end | |
| 34 | - | local mapData = inventory.sensorCardCall("getMapData", "0,-1,0", 1)
|
| 34 | + | |
| 35 | ||
| 36 | - | displayMapColors(mapData.Colors) |
| 36 | + | |
| 37 | local function getColorIndex(x, y) | |
| 38 | return ((x-1) + (y-1) * 128) + 1 | |
| 39 | end | |
| 40 | ||
| 41 | local function drawPixel(x, y, color) | |
| 42 | monitor.setCursorPos(x, y) | |
| 43 | monitor.setBackgroundColor(color) | |
| 44 | monitor.write(" ")
| |
| 45 | end | |
| 46 | ||
| 47 | local function displayMapColors(colors) | |
| 48 | for x=1, width do | |
| 49 | for y=1, height do | |
| 50 | local index = getColorIndex(x, y) | |
| 51 | local color = colors[index] | |
| 52 | drawPixel(x, y, color) | |
| 53 | end | |
| 54 | end | |
| 55 | end | |
| 56 | ||
| 57 | local function findPossibleTargets(sen) | |
| 58 | local maps = {};
| |
| 59 | for key, data in pairs(sen.getTargets()) do | |
| 60 | local details = sen.getTargetDetails(key) | |
| 61 | for slot, slotd in pairs(details.Slots) do | |
| 62 | if slotd.Name == "item.map" then | |
| 63 | table.insert(maps, { target = key, slot = slot })
| |
| 64 | end | |
| 65 | end | |
| 66 | end | |
| 67 | return maps; | |
| 68 | end | |
| 69 | ||
| 70 | while true do | |
| 71 | ||
| 72 | monitor = findMonitor(); | |
| 73 | if monitor == nil then | |
| 74 | error("no monitor attached")
| |
| 75 | end | |
| 76 | ||
| 77 | width, height = monitor.getSize() | |
| 78 | ||
| 79 | local inventory = findSensor() | |
| 80 | if inventory == nil then | |
| 81 | error("no sensor attached")
| |
| 82 | end | |
| 83 | ||
| 84 | local possibleMaps = findPossibleTargets(inventory) | |
| 85 | local firstMap = table.remove(possibleMaps, 1) | |
| 86 | ||
| 87 | if firstMap ~= nil then | |
| 88 | ||
| 89 | local width, height = monitor.getSize() | |
| 90 | ||
| 91 | local mapData = inventory.sensorCardCall("getMapData", firstMap.target, firstMap.slot)
| |
| 92 | ||
| 93 | displayMapColors(mapData.Colors) | |
| 94 | ||
| 95 | end | |
| 96 | ||
| 97 | sleep(0.1) | |
| 98 | ||
| 99 | end |