Your first conversation
Two datapack files and a /reload. The whole loop, in five minutes, with no Java at all.
Two files in a datapack, and a villager will talk to you. Put them in a datapack in world/datapacks/, or in your mod's own data/ folder if you are writing one.
Two files
What she says
data/mypack/dialogues/innkeeper.json
{
"speaker": { "text": "Marda" },
"pages": [
{ "text": "You look like you have walked a long way." },
{ "text": "There is a bed upstairs, and stew if you want it." }
],
"choices": [
{
"label": { "text": "I will take the stew." },
"requires": [ { "condition": "has_items", "item": "minecraft:emerald" } ],
"actions": [
{ "type": "take_item", "item": "minecraft:emerald" },
{ "type": "give_item", "item": "minecraft:rabbit_stew" }
]
},
{ "label": { "text": "Another time." } }
]
}Who says it
data/mypack/dialogue_speakers/innkeeper.json
{
"entity": "minecraft:villager",
"dialogue": "mypack:innkeeper"
}Try it
Run /reload, then right-click a villager. That is the whole loop.
What that file is already doing
The stew choice is not offered at all unless the player is carrying an emerald. Conditions are weighed on the server, and a choice that fails one is never sent.
The panel is headed "Marda" rather than "Villager", because you said so. Leave speaker out and whoever was clicked supplies their own name.
Use translation keys for anything you ship
Write { "translate": "mypack.innkeeper.1" } instead of { "text": ... }. Every field that takes text is a full text component, so a language file is free.
The shape of it
A conversation is pages, then choices. Nothing else is required: a dialogue with pages and no choices is an announcement, and the last page simply closes.
A choice with no actions is a way out of the conversation and nothing more, which is what most farewells are.
Namespaces
An unnamespaced kind means one of this mod's. "type": "give_item" and "type": "rpg_dialogue:give_item" are the same thing.
Kinds from another mod are namespaced as normal: "type": "yourmod:ring_the_bell".
References to a dialogue always need the namespace, since nothing can guess which pack you meant. "dialogue": "mypack:innkeeper", never "dialogue": "innkeeper".
