Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- monitor.setTextScale(0.5)
- monitor.clear()
- local baseUrl = "http://localhost:8080/tiles/tile.png?dimension=minecraft:overworld&mapTypeString=day&y=0&zoom=0&t="
- local refreshInterval = 10 -- Refresh map every 10 seconds
- local outputPath = "/map.png"
- local centerX, centerZ = 0, 0 -- Base chunk coordinates at the center
- local radius = 4 -- 9x9 area (radius 4 around center)
- -- Function to download the map image
- local function fetchMap()
- print("Fetching map tiles from JourneyMap Web Map...")
- for ix = -radius, radius do
- for iz = -radius, radius do
- local tileUrl = baseUrl .. os.epoch("utc") .. "&x=" .. (centerX + ix) .. "&z=" .. (centerZ + iz)
- local response = http.get(tileUrl)
- if response then
- local file = fs.open(outputPath, "wb")
- file.write(response.readAll())
- file.close()
- print("Tile (" .. (centerX + ix) .. ", " .. (centerZ + iz) .. ") downloaded successfully.")
- else
- print("Failed to fetch tile at (" .. (centerX + ix) .. ", " .. (centerZ + iz) .. ").")
- end
- end
- end
- end
- -- Function to draw PNG directly on monitor using paintutils
- local function drawPNG(path)
- if not fs.exists(path) then
- print("PNG file not found.")
- return
- end
- local file = fs.open(path, "rb")
- local data = file.readAll()
- file.close()
- local width, height = 64, 64 -- Assume 64x64 monitor resolution
- local x, y = 1, 1
- for i = 1, #data do
- local byte = string.byte(data, i)
- local colorIndex = byte % 16
- -- Draw each pixel directly on the monitor
- paintutils.drawPixel(x, y, colorIndex)
- x = x + 1
- if x > width then
- x = 1
- y = y + 1
- if y > height then break end
- end
- end
- print("Map drawn to monitor.")
- end
- -- Main loop to continuously update the map
- while true do
- fetchMap()
- drawPNG(outputPath)
- sleep(refreshInterval)
- end
Advertisement
Add Comment
Please, Sign In to add comment