Skip to content

Creating Cursors

Every cursor must have a unique key as its identifier. Choose a unique key for your custom cursor and follow the resource pack guide when creating the assets.

Once you have prepared the cursor's assets, you can create a CursorType object using the static method: CursorType.of(String key). The CursorType instance itself is inconsequential—only its key is used for lookup (similar to Minecraft's Identifier).

The CursorType must then be registered from the MinecraftCursorInitializer

TIP

All built-in cursors are available as static fields of CursorType.

The Cursor Type key

Used to identify the cursor type. Following the resource pack structure, this is the:

  • file name of the cursor type:
  • assets
    • minecraft-cursor
      • textures
        • cursors
          • <​key​>.png
  • key for custom settings:
    cursors.json
    json
    {
      "settings": {
        "<key>": {
          "xhot": 3,
          "yhot": 3
        }
      }
    }
  • suffix of the translation entry for your cursor type:
    en_us.json
    json
    {
      "minecraft-cursor.options.cursor-type.<key>": "Custom"
    }

Creating a CursorType object

Using CursorType.of(String key):

java
CursorType customCursor = CursorType.of("custom-cursor");

Creating static CursorType objects

You should create final static variables or an enum for cursor types so they are easily reusable and maintainable.

CustomCursor.java
java
// Create static cursor types
public class CustomCursor {
    public static final CursorType CELL = CursorType.of("cell");
    public static final CursorType PROGRESS = CursorType.of("progress");
    public static final CursorType ZOOM = CursorType.of("zoom");
}
CustomCursorEnum.java
java
// Create static cursor types using enum
public enum CustomCursorEnum implements CursorType {
    MOVE,
    RESIZE,
    CROSSHAIR;

    @Override
    public String getKey() {
        return this.name().toLowerCase();
    }
}

After creating your cursor types, they must be registered from the MinecraftCursorInitializer where the CursorRegistrar instance will be injected.


Released under the CC0-1.0 License.