Parchment Mappings

repository·versions/1.21.x·Indexed 43 days ago

https://github.com/parchmentmc/parchment

An open, community-sourced set of mappings for Minecraft parameter names and Javadocs. Designed to be modloader-neutral, Parchment augments official Mojang mappings to improve the developer experience.

Tokens
105.8K
Snippets
295
Records
353
Agent score
55%

What's inside Parchment

  1. Migrate Parchment mapping data between Minecraft versions

    versions/1.21.x

    The data migration system allows you to migrate Parchment mapping data between different Minecraft versions. It uses the ParchmentJAM integration (which utilizes the JAMMER/JarAwareMapping tool) to match changed methods between versions and retain data integrity.

    Migration is performed using the migrateData task within the parchment task group.

    Workflow:

    1. Configure the target version (see Configuration).
    2. Run the migrateData task.
    3. Use the promoteStagingToProduction task to move the migrated data from the staging directory to the production directory (data/).
    4. Run sanitizeData and validateData to remove unwanted data fragments and ensure integrity.
    # Example command line execution
    ./gradlew -Pmigration-targetVersion="1.19.4" migrateData
  2. Set up the Parchment repository for contributing

    versions/1.21.x

    To contribute to Parchment mappings (such as writing Javadocs, naming parameters, or correcting typos), follow these steps:

    1. Fork the repository on GitHub to create your own copy.
    2. Clone your fork to your local machine.
    3. Launch the mapping interface by running the enigma Gradle task.
    4. Perform mapping tasks within the Enigma interface (see 'Using the Enigma interface' for details).
    5. Validate your changes using the validateData Gradle task.
    6. Submit a Pull Request for review.
    # Example of running the Enigma interface via Gradle
    ./gradlew enigma
  3. Use the Enigma interface to map parameters and Javadocs

    versions/1.21.x

    Enigma is the mapping interface used to edit Parchment data. Once launched via ./gradlew enigma, use the following interactions:

    • Navigate Classes: Classes are listed in the top-left section. Double-click a class to open it.
    • Rename Parameters:
      • Move the cursor to the parameter name, type the new name, and press <kbd>Enter</kbd>.
      • OR right-click the parameter name and select Rename from the context menu.
    • Add Javadocs: Right-click a class, field, method, or parameter and select Edit Javadocs from the context menu.
    • Save Changes: Press <kbd>Ctrl</kbd> + <kbd>S</kbd> or use File > Save.
  4. Configure the migration target version

    versions/1.21.x

    You must specify a targetVersion for the migration to occur. The system will migrate data in steps from the current version (defined by the version property in the compass extension) to the target version. The target version can be earlier or later than the current version, but cannot be the same.

    You can configure the target version in two ways:

    Set the targetVersion within the migration block of the compass extension in your Gradle configuration.

    Set the migration-targetVersion property. This is ideal for CI/CD or one-off migrations via the command line.

    Note: Configuring the version via the compass extension overrides any value provided via the project property.

    // Option 1: Extension configuration
    compass {
        migration {
            targetVersion = '1.19.4'
        }
    }
    # Option 2: Command-line property
    ./gradlew -Pmigration-targetVersion="1.19.4" migrateData
  5. Exclude intermediate versions during migration

    versions/1.21.x

    To prevent data loss during migration, certain versions (like April Fools versions) should be skipped. The migration system steps through all intermediate versions between the current and target versions unless they are explicitly excluded.

    How to exclude versions

    You can exclude versions using either the excludedVersions set property in the migrationExtension or the migration-excludedVersions project property (as a comma-separated list).

    Warning: Setting your own excluded versions will fully override the default list. If you want to keep the default April Fools exclusions, you must re-specify them in your configuration.

    Default Excluded Versions

    By default, the following April Fools versions are excluded:

    • 15w14a
    • 1.RV-Pre1
    • 3D Shareware v1.34
    • 20w14infinite
    • 22w13oneblockatatime
    • 23w13a_or_b
  6. Identify FunctionCommand inner classes

    versions/1.21.x

    The FunctionCommand class contains several inner classes used for managing command execution and results:

    • Callbacks: Used to signal results during function execution via signalResult(Object, Identifier, int).
    • 1Accumulator: An internal class used to accumulate results via add(int).
    • FunctionCustomExecutor: Provides access to arguments from a CommandContext via arguments(CommandContext).
  7. Validate and sanitize mapping data with Gradle tasks

    versions/1.21.x

    Before submitting a Pull Request, you should ensure your data adheres to the required standards using the following Gradle tasks:

    • validateData: Checks for errors in the mapped data, such as mapped or documented synthetic methods. This task is also run by the CI on every Pull Request.
    • sanitizeData: If validateData reports errors, run this task to automatically sanitize the data and remove potential causes of errors (e.g., removing synthetic methods).
    # Validate your mapping data
    ./gradlew validateData
    
    # Automatically fix validation errors
    ./gradlew sanitizeData
  8. Parse and retrieve results from ResourceOrTagArgument

    versions/1.21.x

    Once an argument is parsed, you can retrieve the result using getResourceOrTag. This method returns a Result object which encapsulates whether the input was a resource or a tag.

    • parse(StringReader reader): Parses the input string into a Result.
    • getResourceOrTag(CommandContext context, String argument, ResourceKey registryKey): Retrieves the result from the command context.
    • Result.cast(ResourceKey registryKey): Attempts to cast the result to a specific resource type, returning an Optional.
    // Parsing a reader
    ResourceOrTagArgument.Result result = argument.parse(stringReader);
    
    // Casting a result to a specific registry key
    Optional<ResourceKey> resource = result.cast(registryKey);
  9. Use ResourceOrIdArgument for command arguments

    versions/1.21.x

    The ResourceOrIdArgument class is used to handle command arguments that represent either a resource or an ID. It provides methods to parse input from a StringReader and retrieve specific types of resources from a CommandContext.

    Parsing

    • parse(StringReader reader): Parses the input into a Holder.
    • parse(StringReader reader, Grammar grammar, DynamicOps ops): Parses the input using a specific grammar and dynamic operations.

    Retrieving Resources from Context

    Once a command is being executed, you can retrieve the parsed resource from the CommandContext using the following methods (where name is the string identifier of the argument in the command definition):

    • getResource(CommandContext context, String name): Returns the resource as a Holder.
    • getLootTable(CommandContext context, String name): Returns a loot table as a Holder.
    • getLootModifier(CommandContext context, String name): Returns a loot modifier as a Holder.
    • getLootPredicate(CommandContext context, String name): Returns a loot predicate as a Holder.
    • getDialog(CommandContext context, String name): Returns a dialog as a Holder.
  10. Use ItemArgument for Minecraft command arguments

    versions/1.21.x

    The net/minecraft/commands/arguments/item/ItemArgument class is used to handle item-based arguments within Minecraft commands. It provides methods to initialize the argument with a CommandBuildContext, parse input from a StringReader into an ItemInput, and retrieve specific items from a command context using a name. It also supports generating suggestions for command completion via listSuggestions.

    // Example conceptual usage based on mapping signatures
    // Initialize the argument
    ItemArgument itemArg = ItemArgument.item(context);
    
    // Parse a string reader into an ItemInput
    ItemInput input = itemArg.parse(stringReader);
    
    // Retrieve an item from a command context
    ItemInput result = itemArg.getItem(commandContext, "item_name");