A programming language for Minecraft datapacks

Poplar compiles to Minecraft Java datapacks. Write functions, variables, conditions, loops and events instead of raw commands. Every command is checked when you build.

src/main.poplar
namespace deaths;
var #deaths = 0;
mcfun load() {
onEvent("deathCount", playerDied);
}
mcfun playerDied() {
#deaths = #deaths + 1;
/tellraw @a {{["Deaths: ", text(#deaths)]}};
}

How it works

Functions are Minecraft functions

Every mcfun becomes a normal .mcfunction file, so other datapacks can call it with /function. load and tick run when the pack loads and every tick.

Variables are scores or NBT

#mana is a scoreboard score and $item is NBT data. @s.#mana is the score of the entity running the function.

Commands are written as commands

A line that starts with / is a Minecraft command. {{...}} puts a value into it. The compiler checks it against the command tree of the target version.

src/main.poplar
namespace mana;
var #mana = 0;
var #maxMana = 100;
mcfun tick() {
execute (as @a) {
regen();
}
}
// Runs as each player. @s.#mana is the player's own mana.
mcfun regen() {
if (@s.#mana < #maxMana) {
@s.#mana = @s.#mana + 1;
}
/title @s actionbar {{["Mana: ", text(@s.#mana), "/", text(#maxMana)]}};
}
$ poplar check
✗ src/main.poplar:4:21  Unknown mob_effect 'poision'. Did you mean 'poison'?
✗ 1 error

Features

Examples

Each one is a complete project in the repository. Try one in a world with poplar watch examples/<name> --world <world folder>.

hello

The smallest pack: mcfun load, constants, inserts and for.

View the project on GitHub
examples/hello/src/main.poplar
// The smallest pack: a greeting when the pack loads.
namespace hello;
var #loads = 0;
mcfun load() {
#loads = #loads + 1;
// A constant only exists while the pack is built. `{{...}}` writes it into the command.
var name = "Poplar";
/say Hello from {{name}}!;
// A score is read in the game, so this line becomes a macro line.
/say This pack has loaded {{#loads}} times;
// `for` repeats its body while the pack is built: three `say` commands.
for (1..4) |step| {
/say Step {{step}};
}
}

Read the documentation

The docs cover the whole language, the standard library, the CLI and what the compiled pack looks like.