SHARE
TWEET

Change Cursor in Minecraft

a guest Aug 12th, 2017 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void changeCursor(ResourceLocation cursor) {
  2.         try {
  3.             BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(cursor).getInputStream());
  4.             int w = image.getWidth();
  5.             int h = image.getHeight();
  6.             int[] pixels = new int[w*h];
  7.             image.getRGB(0, 0, w, h, pixels, 0, w);
  8.             ByteBuffer buffer = BufferUtils.createByteBuffer(w*h*4);
  9.             for (int y = 0; y < h; y++)
  10.                 for (int x = 0; x < w; x++)
  11.                 {
  12.                     int pixel = pixels[(h-1-y)*w+x]; //load pixel & flip them
  13.                     buffer.put((byte) (pixel & 0xFF));          // red
  14.                     buffer.put((byte) ((pixel >> 8) & 0xFF));   // green
  15.                     buffer.put((byte) ((pixel >> 16) & 0xFF));  // blue
  16.                     buffer.put((byte) ((pixel >> 24) & 0xFF));  // alpha
  17.                 }
  18.             buffer.flip();
  19.             Mouse.setNativeCursor(new Cursor(w, h, 0, h-1, 1, buffer.asIntBuffer(), null)); //set cursor
  20.         } catch (Exception e) {
  21.             e.printStackTrace();
  22.         }
  23.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top