Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameMap(int game, int x, int y) {
- this.x = x; // Tọa độ X trên world của x = 0 trên mặt ảnh
- this.y = y; // Tọa độ Z trên world của y = 0 trên mặt ảnh
- File mapfile = new File(Main.getInstance().getDataFolder() + "/maps", game + ".png");
- if (mapfile.exists())
- try {
- BufferedImage img = ImageIO.read(mapfile);
- mapbytes = loadFromImage(img); // Hàm này sẽ chuyển buffered image sang mảng byte (xem bên dưới)
- } catch (Exception e) {
- Main.getInstance().getLogger().log(Level.WARNING, "Can't load map img for game #" + game, e);
- }
- }
- @SuppressWarnings("deprecation")
- public byte[][] loadFromImage(BufferedImage base) {
- int w = base.getWidth(), h = base.getHeight();
- BufferedImage img2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = img2.createGraphics();
- g.drawImage(base, 0, 0, null);
- g.dispose();
- byte[][] kq = new byte[w][h];
- for (int x = 0; x < w; ++x)
- for (int y = 0; y < h; ++y)
- 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
- return kq;
- }
Advertisement
Add Comment
Please, Sign In to add comment