BlissSilence

Untitled

Jan 2nd, 2025 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. monitor.setTextScale(0.5)
  3. monitor.clear()
  4.  
  5. local baseUrl = "http://localhost:8080/tiles/tile.png?dimension=minecraft:overworld&mapTypeString=day&y=0&zoom=0&t="
  6. local refreshInterval = 10 -- Refresh map every 10 seconds
  7. local outputPath = "/map.png"
  8. local centerX, centerZ = 0, 0 -- Base chunk coordinates at the center
  9. local radius = 4 -- 9x9 area (radius 4 around center)
  10.  
  11. -- Function to download the map image
  12. local function fetchMap()
  13. print("Fetching map tiles from JourneyMap Web Map...")
  14. for ix = -radius, radius do
  15. for iz = -radius, radius do
  16. local tileUrl = baseUrl .. os.epoch("utc") .. "&x=" .. (centerX + ix) .. "&z=" .. (centerZ + iz)
  17. local response = http.get(tileUrl)
  18.  
  19. if response then
  20. local file = fs.open(outputPath, "wb")
  21. file.write(response.readAll())
  22. file.close()
  23. print("Tile (" .. (centerX + ix) .. ", " .. (centerZ + iz) .. ") downloaded successfully.")
  24. else
  25. print("Failed to fetch tile at (" .. (centerX + ix) .. ", " .. (centerZ + iz) .. ").")
  26. end
  27. end
  28. end
  29. end
  30.  
  31. -- Function to draw PNG directly on monitor using paintutils
  32. local function drawPNG(path)
  33. if not fs.exists(path) then
  34. print("PNG file not found.")
  35. return
  36. end
  37.  
  38. local file = fs.open(path, "rb")
  39. local data = file.readAll()
  40. file.close()
  41.  
  42. local width, height = 64, 64 -- Assume 64x64 monitor resolution
  43. local x, y = 1, 1
  44.  
  45. for i = 1, #data do
  46. local byte = string.byte(data, i)
  47. local colorIndex = byte % 16
  48.  
  49. -- Draw each pixel directly on the monitor
  50. paintutils.drawPixel(x, y, colorIndex)
  51.  
  52. x = x + 1
  53. if x > width then
  54. x = 1
  55. y = y + 1
  56. if y > height then break end
  57. end
  58. end
  59. print("Map drawn to monitor.")
  60. end
  61.  
  62. -- Main loop to continuously update the map
  63. while true do
  64. fetchMap()
  65. drawPNG(outputPath)
  66. sleep(refreshInterval)
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment