Guest User

Untitled

a guest
Aug 14th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1.     public GameMap(int game, int x, int y) {
  2.         this.x = x; // Tọa độ X trên world của x = 0 trên mặt ảnh
  3.         this.y = y; // Tọa độ Z trên world của y = 0 trên mặt ảnh
  4.         File mapfile = new File(Main.getInstance().getDataFolder() + "/maps", game + ".png");
  5.         if (mapfile.exists())
  6.             try {
  7.                 BufferedImage img = ImageIO.read(mapfile);
  8.                 mapbytes = loadFromImage(img); // Hàm này sẽ chuyển buffered image sang mảng byte (xem bên dưới)
  9.             } catch (Exception e) {
  10.                 Main.getInstance().getLogger().log(Level.WARNING, "Can't load map img for game #" + game, e);
  11.             }
  12.     }
  13.  
  14.     @SuppressWarnings("deprecation")
  15.     public byte[][] loadFromImage(BufferedImage base) {
  16.         int w = base.getWidth(), h = base.getHeight();
  17.         BufferedImage img2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  18.         Graphics2D g = img2.createGraphics();
  19.         g.drawImage(base, 0, 0, null);
  20.         g.dispose();
  21.         byte[][] kq = new byte[w][h];
  22.         for (int x = 0; x < w; ++x)
  23.             for (int y = 0; y < h; ++y)
  24.                 kq[x][y] = MapPalette.matchColor(new Color(img2.getRGB(x, y), true)); // Hàm chuyển đổi màu thực tế sang màu byte của Minecraft
  25.         return kq;
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment