Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void changeCursor(ResourceLocation cursor) {
- try {
- BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(cursor).getInputStream());
- int w = image.getWidth();
- int h = image.getHeight();
- int[] pixels = new int[w*h];
- image.getRGB(0, 0, w, h, pixels, 0, w);
- ByteBuffer buffer = BufferUtils.createByteBuffer(w*h*4);
- for (int y = 0; y < h; y++)
- for (int x = 0; x < w; x++)
- {
- int pixel = pixels[(h-1-y)*w+x]; //load pixel & flip them
- buffer.put((byte) (pixel & 0xFF)); // red
- buffer.put((byte) ((pixel >> 8) & 0xFF)); // green
- buffer.put((byte) ((pixel >> 16) & 0xFF)); // blue
- buffer.put((byte) ((pixel >> 24) & 0xFF)); // alpha
- }
- buffer.flip();
- Mouse.setNativeCursor(new Cursor(w, h, 0, h-1, 1, buffer.asIntBuffer(), null)); //set cursor
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement