Data Packs, Commands And Generated Data
Register data pack sources, command collectors and generated JSON output through the Minecraft adapter.
Data Packs, Commands And Generated Data
Datapack and resource-pack sources are exposed through the version adapter:
DataPacks packs = MinecraftApi.dataPacks(context);
Path modPackDir = packs.modPackDirectory("my_mod");
Path dataDir = packs.modDataDirectory("my_mod");
Path assetsDir = packs.modAssetsDirectory("my_mod");
List<Object> serverSources = packs.sources(PackTarget.SERVER_DATA);
Commands and generated JSON data are collected through the adapter as well:
MinecraftApi.commands(context).register(CommandSpec.literal("my_mod")
.executes(MyCommands::run)
.result(1)
.build());
DataGen dataGen = MinecraftApi.dataGen(context);
dataGen.writeJson(dataGen.recipePath("my_mod:widget"), Map.class, Map.of(
"type", "minecraft:crafting_shapeless",
"ingredients", List.of(Map.of("item", "minecraft:stone")),
"result", Map.of("id", "my_mod:widget", "count", 1)
));
Pack Sources
DataPacks.modPackDirectory(modId) gives a stable per-mod directory under the active game directory. modDataDirectory(modId) and modAssetsDirectory(modId) give the normal namespaced data/<modId> and assets/<modId> folders for generated or user-editable resources.
Use PackTarget.SERVER_DATA for data packs and PackTarget.CLIENT_RESOURCES for assets. registerSource(PackTarget, Object) still forwards to Minecraft’s real repository source internally, so complex pack behavior can keep using the target version’s native source object behind the stable target enum.
Commands
MinecraftApi.commands(context).register(CommandSpec) covers simple literal commands through a stable Nows-owned value. The lower-level dispatcher callback is still available when a command needs Brigadier arguments, permissions or version-specific source details.
Register commands during normal mod initialization. Avoid capturing temporary world/server objects in the registration lambda; use the command source passed at execution time.
Generated Data
DataGen writes JSON through the adapter, with helpers such as recipePath("my_mod:widget") for common output paths. The current API is intentionally small: it writes generated JSON, but it does not replace a full Gradle data-generation pipeline.
Good uses include simple generated recipes, tags, language fragments or small model/data files that are easier to derive from Java constants. Large asset pipelines should still live in normal build tooling.