Skip to content
Jacob0225 edited this page Mar 25, 2026 · 2 revisions

Datapack-Commands — Wiki

A Fabric mod for Minecraft 1.21.11 that lets server operators create custom slash commands that execute datapack functions. Commands are registered at runtime, persist across server restarts and /reload, and appear in tab completion for all players immediately — no restart required.


How It Works

Datapack-Commands acts as a bridge between players and datapack functions. Normally, players cannot run datapack functions directly — only operators can use /function. This mod lets operators pre-register shortcuts so players can trigger functions with simple, friendly commands.

When a command is created:

  1. It is registered into Minecraft's command tree (Brigadier) immediately
  2. It is saved to datapackcommands.json in the world folder
  3. All online players receive an updated command tree so tab completion works right away
  4. On every server start and /reload, saved commands are automatically re-registered

Installation

  1. Install [Fabric Loader](https://fabricmc.net/) for Minecraft 1.21.11
  2. Install [Fabric API](https://modrinth.com/mod/fabric-api)
  3. Drop the mod .jar into your mods/ folder
  4. Start your server

No configuration is needed. The mod creates datapackcommands.json automatically in your world folder the first time a command is registered.


Command Reference

All /cgen subcommands require operator level 4. Custom commands created with the mod are available to all players.


/cgen create

Registers a new custom command that executes a datapack function.

Syntax:

/cgen create <commandname> <namespace:function>
/cgen create "<command> <subcommand>" <namespace:function>
  • <commandname> — the name of the new command (single word, no spaces)
  • "<command> <subcommand>" — a quoted multi-word command path
  • <namespace:function> — the datapack function to run, in namespace:path format

Rules:

  • Command names are case-sensitive
  • You cannot register a command that already exists — use /cgen remove first
  • The datapack function does not need to exist at registration time, but the command will silently do nothing if it doesn't exist when run

Examples:

/cgen create spawn utils:teleport_spawn
/cgen create heal utils:heal_player
/cgen create day utils:set_daytime
/cgen create night utils:set_nighttime
/cgen create weather_clear utils:clear_weather

/cgen remove

Unregisters a custom command immediately.

Syntax:

/cgen remove <commandname>
  • Tab complete will suggest all currently registered commands after typing /cgen remove
  • For multi-word commands, type the full path (e.g. tp creative)
  • Removing a root command (e.g. tp) also removes all its subcommands from the tree

Examples:

/cgen remove spawn
/cgen remove heal
/cgen remove tp creative

Note: If you registered /tp creative and /tp survival as separate commands, removing tp creative only removes that specific entry from the save file. However, because Brigadier manages the tree as a whole, the root /tp node is what gets unregistered — meaning /tp survival will also stop working until the next /reload or restart, at which point it re-registers from the save file.


/cgen list

Lists all currently registered commands and the functions they map to.

Syntax:

/cgen list

Example output:

Registered commands:
  /spawn -> utils:teleport_spawn
  /heal -> utils:heal_player
  /tp creative -> gamemode:set_creative
  /tp survival -> gamemode:set_survival

/cgen feedback

Controls whether a confirmation message appears in chat when a player runs a custom command. Defaults to off.

Syntax:

/cgen feedback
/cgen feedback on
/cgen feedback off
  • feedback with no argument — shows the current state
  • feedback on — players see "Executed function: namespace:path" after running a command
  • feedback off — commands run silently (default)

This setting is saved to datapackcommands.json and persists across restarts.

Example with feedback on:

> /spawn
Executed function: utils:teleport_spawn

Example with feedback off:

> /spawn
(nothing shown)

Note: Messages sent by the datapack function itself (via tellraw, say, title, etc.) are always shown regardless of this setting. Feedback only controls the "Executed function: ..." line added by the mod and the vanilla "Running function ..." system message.


/cgen check

Sanity check to verify the mod is running.

Syntax:

/cgen check

Returns 1 in chat if the mod is loaded and functioning correctly. Useful for datapacks that need to check whether the mod is active.


Multi-Word Commands

Datapack-Commands supports registering commands with subcommands by wrapping the full command path in quotes.

Syntax:

/cgen create "<root> <sub>" <namespace:function>
/cgen create "<root> <sub> <subsub>" <namespace:function>

Each space-separated token becomes a fixed literal subcommand in the Brigadier tree. Minecraft will tab-complete each level automatically.

Example — gamemode shortcuts:

/cgen create "gm creative" gamemode:set_creative
/cgen create "gm survival" gamemode:set_survival
/cgen create "gm adventure" gamemode:set_adventure
/cgen create "gm spectator" gamemode:set_spectator

Players can now type /gm and Tab to see creative, survival, adventure, spectator as suggestions.

Example — time shortcuts:

/cgen create "time day" world:set_day
/cgen create "time noon" world:set_noon
/cgen create "time night" world:set_night
/cgen create "time midnight" world:set_midnight

Example — three levels deep:

/cgen create "buff speed fast" buffs:speed_fast
/cgen create "buff speed slow" buffs:speed_slow
/cgen create "buff jump high" buffs:jump_high

Players run /buff speed fast or /buff jump high.

Removing multi-word commands:

/cgen remove gm creative
/cgen remove time day

Examples

Basic server utility commands

/cgen create spawn world:teleport_spawn
/cgen create heal player:restore_health
/cgen create feed player:restore_hunger
/cgen create day world:set_day
/cgen create night world:set_night
/cgen create clear world:clear_weather
/cgen create rain world:set_rain

Gamemode shortcuts

/cgen create "gm c" gamemode:creative
/cgen create "gm s" gamemode:survival
/cgen create "gm a" gamemode:adventure
/cgen create "gm sp" gamemode:spectator

Event commands for a minigame server

/cgen create startgame minigame:start
/cgen create endgame minigame:end
/cgen create resetarena minigame:reset_arena
/cgen create givekits minigame:distribute_kits

Tiered shop or reward system

/cgen create "shop tier1" shop:buy_tier1
/cgen create "shop tier2" shop:buy_tier2
/cgen create "shop tier3" shop:buy_tier3

Season or world event toggles

/cgen create "event halloween" events:start_halloween
/cgen create "event christmas" events:start_christmas
/cgen create "event off" events:disable_all

Storage

Commands are saved to a JSON file inside your world folder:

world/datapackcommands.json

Example file contents:

{
  "commands": {
    "spawn": "utils:teleport_spawn",
    "heal": "utils:heal_player",
    "tp creative": "gamemode:set_creative",
    "tp survival": "gamemode:set_survival"
  },
  "feedbackEnabled": false
}
  • Each world has its own independent set of commands
  • Switching to a different world folder will load that world's commands instead
  • You can manually edit this file while the server is stopped, but do not edit it while the server is running
  • Deleting the file removes all registered commands on next restart

Known Limitations

  • No dynamic arguments — subcommands are fixed literals only. You cannot create a command like /tp <player> where <player> is a variable. Each variation must be registered as its own command path.
  • No permission levels per command — all custom commands are available to every player. Permission management must be handled inside the datapack function itself (e.g. checking scores or tags).
  • Datapack function is not validated — if the function does not exist when the command is run, Minecraft will silently do nothing. Make sure your datapack is loaded before registering commands that depend on it.
  • Removing a root unregisters the whole tree — if you registered /tp creative and /tp survival and remove one of them, both subcommands disappear from Brigadier until the next /reload or restart, at which point remaining entries re-register from the save file.
  • The datapack's own messages cannot be silenced/cgen feedback off suppresses the mod's own messages and the vanilla Running function ... line, but any tellraw, say, or title inside the function will always show.