Advertisement
Guest User

mapper.py

a guest
Dec 8th, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.07 KB | None | 0 0
  1. #2019-12-08
  2. #By: Alexis DeSilva
  3.  
  4. import pygame
  5. import nbt
  6.  
  7. colorTable = [
  8. (0,0,0),
  9. (0,0,0),
  10. (0,0,0),
  11. (0,0,0)]
  12.  
  13. rawColorTable = [
  14. (127,178,56),
  15. (247,233,163),
  16. (199,199,199),
  17. (255,0,0),
  18. (160,160,255),
  19. (167,167,167),
  20. (0,124,0),
  21. (255,255,255),
  22. (164,168,184),
  23. (151,109,77),
  24. (112,112,112),
  25. (64,64,255),
  26. (143,119,72),
  27. (255,252,245),
  28. (216,127,51),
  29. (178,76,216),
  30. (102,153,216),
  31. (229,229,51),
  32. (127,204,25),
  33. (242,127,165),
  34. (76,76,76),
  35. (153,153,153),
  36. (76,127,153),
  37. (127,63,178),
  38. (51,76,178),
  39. (102,76,51),
  40. (102,127,51),
  41. (153,51,51),
  42. (25,25,25),
  43. (250,238,77),
  44. (92,219,213),
  45. (74,128,255),
  46. (0,217,58),
  47. (129,86,49),
  48. (112,2,0),
  49. (209,177,161),
  50. (159,82,36),
  51. (149,87,108),
  52. (112,108,138),
  53. (186,133,36),
  54. (103,117,53),
  55. (160,77,78),
  56. (57,41,35),
  57. (135,107,98),
  58. (87,92,92),
  59. (122,73,88),
  60. (76,62,92),
  61. (76,50,35),
  62. (76,82,42),
  63. (142,60,46),
  64. (37,22,16)
  65. ]
  66.  
  67. bannerColours = {
  68.     "white":(255,255,255),
  69.     "orange":(216,127,51),
  70.     "magenta":(178,76,216),
  71.     "light_blue":(102,153,216),
  72.     "yellow":(229,229,51),
  73.     "lime":(127,204,25),
  74.     "pink":(242,127,165),
  75.     "gray":(76,76,76),
  76.     "light_gray":(153,153,153),
  77.     "cyan":(76,127,153),
  78.     "purple":(127,63,178),
  79.     "blue":(51,76,178),
  80.     "brown":(102,76,51),
  81.     "green":(102,127,51),
  82.     "red":(153,51,51),
  83.     "black":(25,25,25)
  84. }
  85.  
  86. markerSize = 16
  87. fontSize = 24
  88.  
  89. pygame.font.init()
  90. font = pygame.font.Font(pygame.font.get_default_font(),fontSize)
  91.  
  92. for i in rawColorTable:
  93.     values = [135,180,220,255]
  94.     for v in values:
  95.         colorTable.append((int(i[0]*v/255),int(i[1]*v/255),int(i[2]*v/255)))
  96.  
  97. mapArray = [["map_22","map_18",None],["map_12","map_3","map_51"],["map_28",None,None]]
  98.  
  99.  
  100. screen = pygame.display.set_mode((1536,1536))
  101.  
  102. xP = 0
  103. for x in mapArray:
  104.     yP = 0
  105.     for y in x:
  106.         if y != None:
  107.             nbtFile = nbt.nbt.NBTFile(y+".dat",'rb')
  108.  
  109.             mapScale = 2**nbtFile["data"]["scale"].value
  110.  
  111.             xPos = 0
  112.             yPos = 0
  113.             for value in nbtFile["data"]["colors"]:
  114.                 if xPos >= 128:
  115.                     yPos += 1
  116.                     xPos = 0
  117.                 pygame.draw.rect(screen,colorTable[value],(xPos*4+xP,yPos*4+yP,4,4))
  118.                 xPos += 1
  119.  
  120.         yP += 512
  121.     xP += 512
  122.  
  123. xP = 0
  124. for x in mapArray:
  125.     yP = 0
  126.     for y in x:
  127.         if y != None:
  128.             nbtFile = nbt.nbt.NBTFile(y+".dat",'rb')
  129.  
  130.             mapScale = 2**nbtFile["data"]["scale"].value
  131.  
  132.             xPos = 0
  133.             yPos = 0
  134.             for banner in nbtFile["data"]["banners"]:
  135.                 trueX = int((banner["Pos"]["X"].value - nbtFile["data"]["xCenter"].value) / mapScale)
  136.                 trueZ = int((banner["Pos"]["Z"].value - nbtFile["data"]["zCenter"].value) / mapScale)
  137.                
  138.                 drawX = 256+trueX*4+xP-(markerSize//2)
  139.                 drawZ = 256+trueZ*4+yP-(markerSize//2)
  140.                
  141.                 pygame.draw.rect(screen,(0,0,0),(drawX-4,drawZ-4,markerSize+8,markerSize+8))
  142.                 pygame.draw.rect(screen,bannerColours[banner["Color"].value],(drawX,drawZ,markerSize,markerSize))
  143.  
  144.                 if len(banner["Name"].value) > 10:
  145.                     text = font.render(banner["Name"].value[9:-2],True,(0,0,0),(255,255,255))
  146.                     textRect = text.get_rect()
  147.                     textRect.center = (drawX,drawZ+markerSize+fontSize)
  148.                    
  149.                     screen.blit(text,textRect)
  150.  
  151.         yP += 512
  152.     xP += 512
  153.  
  154. pygame.image.save(screen,"outputMap.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement