Starting with Minecraft: Java Edition 1.21.2, Adventure is implemented using mostly shared code between NeoForge and Fabric.
Each major version of Minecraft will usually require a new release of the platform.
The platform supports all features, including localization and custom renderers.
When building multi-loader mods, we often want to move as much code as possible into a loader-agnostic part of our projects.
Adventure facilities this through the net.kyori:adventure-platform-mod-shared artifact.
A second variant, net.kyori:adventure-platform-mod-shared-fabric-repack, is also published. This variant should be used
when your common code is managed by fabric-loom.
If you are building a Fabric-only or NeoForge-only mod, or do not care to use the platform API in shared code,
then you don’t need to use this artifact explicitly. This is because both platforms depend on it transitively.
As with the rest of the Adventure projects, releases are distributed on Maven Central, and snapshots on Sonatype OSS.
Add the artifact to your build file:
First, add the repository:
repositories{// for development buildsmaven{name="sonatype-oss-snapshots1"url="https://s01.oss.sonatype.org/content/repositories/snapshots/"mavenContent{snapshotsOnly()}}// for releasesmavenCentral()}
repositories{// for development buildsmaven(url="https://s01.oss.sonatype.org/content/repositories/snapshots/"){name="sonatype-oss-snapshots1"mavenContent{snapshotsOnly()}}// for releasesmavenCentral()}
dependencies{// Loom projectmodCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:6.1.0")// for Minecraft 1.21.2-1.21.3// NeoGradle/ModDevGradle/VanillaGradle projectcompileOnly("net.kyori:adventure-platform-mod-shared:6.1.0")// for Minecraft 1.21.2-1.21.3}
dependencies{// Loom projectmodCompileOnly("net.kyori:adventure-platform-mod-shared-fabric-repack:6.1.0")// for Minecraft 1.21.2-1.21.3// NeoGradle/ModDevGradle/VanillaGradle projectcompileOnly("net.kyori:adventure-platform-mod-shared:6.1.0")// for Minecraft 1.21.2-1.21.3}
Attention
Each major Minecraft release will require different platform versions. For older Minecraft versions, consult the table below.
Historic Versions
Minecraft Version
Adventure version
adventure-platform-(mod-shared|fabric|neoforge) version
The platform provides custom argument types to specify Key and Component parameters in Brigadier commands.
Warning
See the platform-specific documentation for details on registration and syncing of these argument types.
As an example, here’s a simple command that will echo whatever is provided as input:
// A potential method to be in the mod initializer class aboveprivatestaticfinalStringARG_MESSAGE="message";voidregisterCommands(finalCommandDispatcherdispatcher,finalbooleanisDedicated){dispatcher.register(literal("echo").then(argument(ARG_MESSAGE,component()).executes(ctx->{finalComponentmessage=component(ctx,ARG_MESSAGE);((Audience)ctx.getSource()).sendMessage(Component.text("You said: ").append(message));}));}
Sadly, Adventure can’t provide API for every place chat components are used in the game. However, for areas not covered by the API in Audience, it’s possible to convert components between native and Adventure types. See certain native types which implement
Adventure interfaces, and the methods on MinecraftAudiences for other available conversions.