Speaking to somebody
The three ways a conversation opens: a right-click binding, the /dialogue command, and routing from code.
Three ways, and you will probably use all three.
1. A right-click
data/<yourpack>/dialogue_speakers/<name>.json
{
"entity": "#minecraft:raiders",
"dialogue": "mypack:raider_parley",
"priority": 10,
"requires": [ { "condition": "player_has_effect", "effect": "minecraft:hero_of_the_village" } ]
}| Field | Default | Meaning |
|---|---|---|
entity | required | An entity type, or a #tag of them. |
dialogue | required | The dialogue to open, namespaced. |
priority | 0 | Highest wins where several bindings name the same entity. |
requires | none | Conditions that must hold for this binding to be the one used. |
interrupts | false | Whether the conversation may start while the speaker is being hit, fighting or fleeing. |
Several bindings may name the same entity: the highest priority whose requires all hold is the one that opens. So write the ordinary greeting with no conditions, and stack the special cases above it.
An entity with nothing bound to it is an ordinary right-click, and vanilla handles it as it always did.
interrupts is off by default. A speaker who is asked at a bad moment can say so instead.
Leave vanilla's item interactions alone
Binding a conversation to a mob takes over its right-click, which can take away something vanilla did with an item. An ingot mends an iron golem, a bucket milks a cow. Bow out with holding:
"requires": [
{ "condition": "inverted", "of": { "condition": "holding", "item": "minecraft:iron_ingot" } }
]Already handled for you
A name tag and a spawn egg are refused before any binding is consulted, so naming a bound mob always works. A sleeping speaker, and a merchant already trading with somebody else, are refused too.
2. The /dialogue command
For everything that is not a click: entering a region, finishing an advancement, pressing a button.
dialogue open @s mypack:awakening
dialogue open @a[distance=..8] mypack:the_gate_speaks @e[type=villager,limit=1]
dialogue flag @s set mypack:told_about_ruins
dialogue flag @s clear mypack:told_about_ruins
dialogue flag @s list
dialogue list| Command | Does |
|---|---|
dialogue open <players> <dialogue> [speaker] | Opens it for each player. The trailing entity is who the conversation is with. |
dialogue flag <players> set <flag> | Writes a flag on each player. The same flags set_flag and has_flag use. |
dialogue flag <players> clear <flag> | Rubs it out. |
dialogue flag <player> list | Lists what one player carries. |
dialogue list | How many dialogues are loaded. A quick check that a pack was read. |
The trailing speaker matters: every condition and value that asks about a speaker asks about them, so a line about the weather is theirs and a reward reaches them. Leave it out for a conversation with nobody in particular, and those conditions fall back to the reader.
Permission level 2, the same as a command block. The dialogue argument suggests every id a pack has actually defined, so a typo is caught before the command runs.
Function output is suppressed
A command run from a minecraft:load function prints nothing, so dialogue list is invisible from one. Use say to prove a function ran.
3. From code
One line of Java, for a mod that opens conversations of its own:
DialogueManager.open(player, ResourceLocation.fromNamespaceAndPath("yourmod", "greeting"), speaker);See For mod developers.
Routing: when a file cannot name the dialogue
Reach for this only if you are writing a mod and the name of the file depends on the speaker. Everything else is a binding with requires and a priority, and better written as one, because then a pack can change it.
// dialogues/villager/<profession>.json, including a profession from a mod nobody has heard of yet
SpeakerBindings.route(new SpeakerRoute(new Kind.Any(MY_SPEAKERS), 0, false, (player, entity) -> ...));Return null to stand aside and let the next entry answer.
Routes sit in the same priority-ordered list as the bindings read from dialogue_speakers/, so a pack outranks your routing by writing a binding above it, you outrank another mod's by registering higher, and a tie between a route and a binding goes to the binding.
