Custom triggers
When no goal in the list does what you need, write your own. The code ships in your pack.
A Custom trigger goal (under Advanced) is done when its event is sent for a player. You give the event a name, and say when it happens in one of two ways:
- With a script: JavaScript in the goal's Script box. The creator puts it in your pack, and it calls
done(player)when the player has done it. - Without a script: a command, a function, or another add-on sends the event.
Name events after your pack's namespace, like my_pack:rang_the_bell, so they can't clash with another pack's.
With a script
The Script box takes JavaScript for Minecraft's Script API (@minecraft/server 2.11.0). world, system and mc (everything in @minecraft/server) are there already, so leave out import lines. Call done(player) when a player has done it.
Ring a bell with an empty hand:
world.afterEvents.playerInteractWithBlock.subscribe((ev) => {
if (ev.block.typeId === "minecraft:bell" && !ev.beforeItemStack) done(ev.player);
});
Stand on a gold block at night, checked every second:
system.runInterval(() => {
const night = world.getTimeOfDay() > 13000 && world.getTimeOfDay() < 23000;
if (!night) return;
for (const player of world.getAllPlayers()) {
const below = player.dimension.getBlock({ ...player.location, y: player.location.y - 1 });
if (below?.typeId === "minecraft:gold_block") done(player);
}
}, 20);
For longer code, Expand in the box's corner opens it over most of the page (Esc or Close brings it back). Tab indents.
With Times set, each done(player) counts once: done(player, 5) counts five at a time.
What the creator checks
Before export, the creator looks for brackets and quotes that don't close, import lines, and a script that never calls done. It doesn't run your code, so test the pack in game. A mistake that stops the script loading shows in Minecraft's content log, named after your pack.
How it ships
- Your behaviour pack gets a script module,
scripts/main.js, with every custom trigger's code. BedrockAdvancements never runs it: your pack does, and tells BedrockAdvancements with a script event. - A pack with a script needs Minecraft 1.26.60 or newer.
- The code is also kept in the pack's
ba_creator.json, so importing the pack into the creator brings it back. - Each trigger's code runs in a function of its own. If one throws an error while starting up, the content log says which, and the others still run.
Community packs with scripts
A script can do anything in the world that any add-on can, so a community pack with one says so: a Scripts badge on its card, a note by its download button, and a Scripts tab on its page that shows every line of its code. Scripts that harm players' worlds break the community guidelines and are removed.
Without a script
Leave the Script box empty and send the event yourself. From a command block, a function or an NPC's dialogue:
/execute as @p run scriptevent ba:event my_pack:rang_the_bell
From your own add-on's script:
system.sendScriptEvent("ba:event", JSON.stringify({ player: player.id, event: "my_pack:rang_the_bell" }));
Add "amount": 5 to count five at once. See Map making for the other script events.