Meteor Addon Template

repository·master·Indexed 41 days ago

https://github.com/meteordevelopment/meteor-addon-template

A boilerplate template for creating Minecraft addons using the Meteor Client API. It provides a pre-configured Gradle environment with Fabric Loom, version catalogs, and a standard project structure for modules, commands, and HUDs.

Tokens
1.6K
Snippets
4
Records
6
Agent score
3%

What's inside Meteor Addon Template

  1. Initialize a new Meteor Addon project

    master

    You can start a new project using either the GitHub Template feature or by cloning the repository manually.

    Click the Use this template button on the repository page to create a new repository with a clean history.

    Manual Clone

    If cloning manually, use the following commands to ensure you start with a clean Git history:

    # Clone the template with a shallow depth
    git clone --depth 1 https://github.com/MeteorDevelopment/meteor-addon-template your-addon-name
    cd your-addon-name
    
    # Reset the git history to start fresh
    rm -rf .git
    git init
    git add .
    git commit -m "Initial commit from template"
    git clone --depth 1 https://github.com/MeteorDevelopment/meteor-addon-template your-addon-name
    cd your-addon-name
    rm -rf .git
    git init
    git add .
    git commit -m "Initial commit from template"
  2. Develop and build your Meteor Addon

    master

    Testing during development

    To test your addon, run the Minecraft Client configuration within your IDE. This launches a Minecraft instance with the Meteor Client mod and your addon pre-loaded.

    Building the JAR

    To create a distributable file, run the Gradle build task. The resulting JAR file will be located in the build/libs folder.

    To install the addon:

    1. Move the JAR from build/libs to your Minecraft mods folder.
    2. Ensure the Meteor Client mod is also present in the mods folder.
    3. Run the game.
    # Run the gradle build task
    ./gradlew build
  3. Update the addon to a newer Minecraft version

    master

    Follow these steps to migrate your addon to a newer Minecraft version:

    1. Verify Meteor Client: Ensure a Meteor Client snapshot exists for the target Minecraft version.
    2. Update Versions Catalog: Edit gradle/libs.versions.toml to update the following keys:
      • versions.minecraft: The new Minecraft version.
      • versions.fabric-loader: The new Fabric loader version.
      • versions.meteor: The new Meteor Client snapshot version.
      • versions.loom: The latest version compatible with the new Minecraft version.
      • Update any other library versions in the [libraries] section as required.
    3. Refresh Gradle: Refresh dependencies and rebuild in your IDE.
    4. Update Gradle Wrapper: Run the wrapper update command for your platform:
      • Unix / macOS / Windows (Powershell):
        ./gradlew wrapper --gradle-version <version> && ./gradlew wrapper
      • Windows (cmd.exe):
        gradlew.bat wrapper --gradle-version <version> && gradlew.bat wrapper
    5. Update Source Code: Adjust for Minecraft changes (method names, imports, mixins) and check for Meteor Client API changes by comparing against the Meteor Client master branch.
    6. Verify: Run the build task to confirm success.
    # Example for Unix/macOS to update Gradle wrapper
    ./gradlew wrapper --gradle-version 8.5 && ./gradlew wrapper
  4. Define command arguments and execution logic

    master

    Commands are built using the Brigadier system.

    • Literals: Use literal("name") to create a fixed part of the command path.
    • Arguments: Use argument("name", type) to accept dynamic input. Common types include StringArgumentType.word().
    • Execution: Use .executes(context -> { ... }) to define what happens when the command (or a specific branch of it) is run.
    • Return Value: Execution blocks should return SINGLE_SUCCESS (or other Brigadier success/failure constants) to indicate the result of the command.
    • Feedback: Use the info(String message) method inherited from Command to send messages to the client/user.
  5. Configure addon metadata and resources

    master

    Modify these files to customize your addon's identity and assets:

    • src/main/resources/fabric.mod.json: Edit this file to update the addon's metadata (name, description, etc.).
    • src/main/resources/assets/template: Replace icon.png with your own addon icon. It is recommended to rename the template folder to match your addon's name.
    • src/main/resources/addon-template.mixins.json: Add your own Mixins to the client array.
    • gradle.properties: Manage maven_group and archives_base_name.
    • src/main/java/com/example/addon/AddonTemplate.java: This is the main class. Use the getPackage method to set your addon's package name.
  6. Implement a custom command by extending Command

    master

    To create a new command in a Meteor Client addon, extend the Command class. You must provide a command name in kebab-case and a description via the super constructor.

    Override the build method to define the command's structure using the Brigadier LiteralArgumentBuilder. This allows you to define literals (static words), arguments (dynamic values), and execution logic using .executes().

    public class CommandExample extends Command {
        /**
         * The {@code name} parameter should be in kebab-case.
         */
        public CommandExample() {
            super("example", "Sends a message.");
        }
    
        @Override
        public void build(LiteralArgumentBuilder<ClientSuggestionProvider> builder) {
            // Basic command: /example
            builder.executes(_ -> {
                info("hi");
                return SINGLE_SUCCESS;
            });
    
            // Command with argument: /example name <nameArgument>
            builder.then(literal("name").then(argument("nameArgument", StringArgumentType.word()).executes(context -> {
                String argument = StringArgumentType.getString(context, "nameArgument");
                info("hi, " + argument);
                return SINGLE_SUCCESS;
            })));
        }
    }