Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding a Loot Table, Spawn Rule & Crafting Recipe
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Constant Effects
      Scripts
    • Avoiding State Limit
    • Fake Blocks
      Scripts
    • Ore Loot Tables
      Scripts
    • Precise Interaction
      Scripts
    • Precise Rotation
      Scripts
    • Rotatable Blocks
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Vanilla Block Models
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • NBT Commands
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
    • On First World Load
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Techniques
    • Execute Logic Gates
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Custom Crafter
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Emojis & Symbols
  • Molang
  • Namespaces
  • Overwriting Assets
  • Raw Text
  • Shaders
  • Sounds
  • Subpacks
  • Text and Localization
  • Texture Atlases
  • textures_list.json
Documentation
  • Shared Constructs
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Menu Categories
  • Molang Queries
  • Pack Folder Structure
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogues
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Flying Entities
    • Introduction to AOE Clouds
    • Invulnerable Entities
    • Look at Entity
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • High Resolution Items
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Identifiers
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Experiments in Minecraft Education
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Block Placement Prevention
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Requests API
    • Simple Chat Commands
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

NPC Dialogues

intermediate
NPC Dialogues
  • Dialogue Files
    • scene_tag
    • npc_name
    • text
    • on_open_commands
    • on_close_commands
    • buttons
  • Selecting the Player
  • Translation
  • Opening Dialogues
  • Changing Dialogues
  • Full Example
    • Creating the NPC
    • The Dialogue File
    • Creating the Item
    • Testing
  • Credits

Non-Player Characters, or NPCs are villager-like entities that can be given a dialogue with a message and multiple buttons. They were originally designed for use in adventure maps, but with the introduction of the /dialogue command, they can now be used in the context of a normal add-on.

Dialogue Files ​

NPC dialogue data is stored in dialogue files, which are stored in the dialogue folder in the root of the behavior pack. Here is a basic NPC dialogue file:

dialogue/example.diag.json
json
{
    "format_version": "1.17",
    "minecraft:npc_dialogue": {
        "scenes": [
            {
                "scene_tag": "example",
                "npc_name": "Steve",
                "text": "Hello"
            }
        ]
    }
}
1
2
3
4
5
6
7
8
9
10
11
12

In this file, there is an array of scenes. Each scene is a separate dialogue. You can put every dialogue in one file, or you can put each one in a separate file. Within each scene object are a number of properties that can be set to control the dialogue:

scene_tag ​

The identifier of the scene, used to target the scene.

npc_name ​

The display name of the NPC. Optional, if it is not specified, the name of the NPC entity will be used, which is §eNPC by default.

text ​

The text to display in the speech bubble. Optional.

on_open_commands ​

Array of command strings to be run when the dialogue is opened. Optional.

json
"on_open_commands": [
  "/say Hello"
]
1
2
3

on_close_commands ​

Array of command strings to be run when the dialogue is closed. Optional.

json
"on_close_commands": [
  "/say Goodbye"
]
1
2
3

buttons ​

An array of objects specifying the buttons to show in the dialogue. Optional.

json
"buttons": [
    {
        "name": "Button One",
        "commands": [
            "/say Button One Pressed!"
        ]
    },
    {
        "name": "Button Two",
        "commands": [
            "/say Button Two Pressed!",
            "/say Secondary Command for Button Two"
        ]
    }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Selecting the Player ​

In on_open_commands, on_close_commands, and the commands property of each button object, you can use normal selectors, such as @p to select the nearest player. However, these selectors are run relative to the NPC entity, so this may be confusing in multiplayer. To solve this, there is a special selector, @initiator which always selects the player with the dialogue open.

json
"buttons": [
    {
        "name": "Levitation Please",
        "commands": [
            "/effect @initiator levitation"
        ]
    }
]
1
2
3
4
5
6
7
8

This selector only works within NPC dialogues, it cannot be used anywhere else.

Translation ​

All of the dialogue properties that will be displayed to the user can also be translated:

json
"npc_name": {
    "rawtext": [
        {
            "translate": "entity.endermite.name"
        }
    ]
}
1
2
3
4
5
6
7

The translation key used should then be specified in the resource pack's language files. In this case, entity.endermite.name would translate to "Endermite."

Opening Dialogues ​

The /dialogue command is used to open and control dialogues. The command looks like this: /dialogue open <npc: target> <player: target> [sceneName:string]

  • <npc: target>: A selector pointing to any entity with the minecraft:npc component, such as the vanilla NPC. This determines where dialogue commands are executed from, as well as the appearance of the NPC in the dialogue.
  • <player: target>: A selector pointing to the player who will see the dialogue.
  • [sceneName:string]: A string matching the scene_tag of the dialogue to be shown. Optional, if not present, the last dialogue shown by the NPC will be shown.

For example, the following command would open the dialogue example for the nearest player, using the nearest NPC:

/dialogue open @e[type=npc,c=1] @p example
1

Changing Dialogues ​

The /dialogue command is also used to change the dialogue of an NPC. Unlike the /dialogue open command, this command has no effect until a player opens the NPC dialogue manually. This syntax looks like this: /dialogue change <npc: target> <sceneName:string> [player: target]

  • <npc: target>: A selector pointing to the NPC to change the dialogue of.
  • <sceneName:string>: A string matching the scene_tag of the dialogue to be shown.
  • [player: target]: A selector pointing to the player who will see the updated dialogue. Optional, if not present, all player will be affected.

For example, the following command would change the nearest NPC's dialogue to example for a random player.

/dialogue change @e[type=npc,c=1] example @r
1

Full Example ​

This full example will create a custom item that will allow the player to teleport when they right-click/interact while holding the item. Full source code for this example can be found on Github. For this demo, use the manifest file at the top of this page.

Creating the NPC ​

Even if the NPC will never be visible, an NPC entity is always needed for the /dialogue command. To do this, you will need to summon the NPC and put it in a ticking area so that it is accessible from anywhere:

functions/setup.mcfunction
tickingarea add 0 1 0 0 2 0
summon npc "§r" 0 1 0
1
2

This function will create a ticking area at 0, 0, and spawn an NPC with no name in the bedrock layer in that ticking area. You will need to run this function once, either manually, or making use of player.json or tick.json.

TIP

You can trigger an NPC dialogue from within the player using the /dialogue command, without having to summon an NPC beforehand.

  1. Within the player's behavior, add the minecraft:npc component.
  2. Specify a scene from the BP/dialogue folder.
  3. Run the /dialogue command from the player, provided with the scene_tag:
/dialogue open @s @s <scene_tag>
1

Pros and Cons: ​

  • + You don't need to worry about hiding away an NPC, if you're just going to run NPC dialogues provided using scene_tags.
  • + No NPC means you also don't need to make sure it is in a 'ticking area'.
  • - Since the dialogue is being triggered from the player, in which it is not intended to, it may become unstable in some cases.
  • - Other players can click on player and they will see this dialogue.

To avoid this add the minecraft:interaction to the entity which will replace the npc interaction. The npc stuff will still work, but if a player clicks on another player, then the npc won't come up

json
"minecraft:interact": {
    "interactions": [
        {
            "on_interact": {
                "filters": {
                    "all_of": [
                        {
                            "test": "is_family",
                            "subject": "other",
                            "value": "player"
                        }
                    ]
                }
            }
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

The Dialogue File ​

This dialogue file features two dialogues, each with two teleport buttons, and a button to switch between the two.

dialogue/example.diag.json
json
{
    "format_version": "1.17",
    "minecraft:npc_dialogue": {
        "scenes": [
            {
                "scene_tag": "main_teleport_menu",
                "npc_name": "Teleport",
                "text": "Where would you like to teleport?",
                "buttons": [
                    {
                        "name": "Districts",
                        "commands": [
                            "/dialogue open @e[type=npc,c=1] @initiator districts_teleport_menu"
                        ]
                    },
                    {
                        "name": "My Base",
                        "commands": ["/tp @initiator -20 4 -20"]
                    },
                    {
                        "name": "World Spawn",
                        "commands": ["/tp @initiator 0 4 0"]
                    }
                ]
            },
            {
                "scene_tag": "districts_teleport_menu",
                "npc_name": "District Teleport",
                "text": "What district would you like to teleport to?",
                "buttons": [
                    {
                        "name": "< Back",
                        "commands": [
                            "/dialogue open @e[type=npc,c=1] @initiator main_teleport_menu"
                        ]
                    },
                    {
                        "name": "Shop District",
                        "commands": ["/tp @initiator 20 4 20"]
                    },
                    {
                        "name": "Gaming District",
                        "commands": ["/tp @initiator 20 4 -20"]
                    }
                ]
            }
        ]
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

Creating the Item ​

Lastly, create an item that will open the dialogue when right-clicked/interacted with. This item uses the Ender Pearl texture, but you could give it custom texture.

Item JSON ​

BP/items/teleport_menu.json
json
{
    "format_version": "1.21.70",
    "minecraft:item": {
        "description": {
            "identifier": "wiki:teleport_menu",
            "menu_category": {
                "category": "items"
            }
        },
        "components": {
            "minecraft:icon": "ender_pearl",
            "minecraft:glint": true,
            "minecraft:display_name": {
                "value": "Teleport Menu"
            },
            "minecraft:custom_components": ["wiki:teleport_menu"]
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Custom Component Script ​

BP/scripts/teleportMenu.js
js
import { world } from "@minecraft/server";

const ItemTeleportMenuComponent = {
    onUse({ source }) {
        source.runCommand("dialogue open @e[type=npc, c=1] @s main_teleport_menu");
    },
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent("wiki:teleport_menu", ItemTeleportMenuComponent);
});
1
2
3
4
5
6
7
8
9
10
11

Testing ​

When you are done, package these files along with the manifest, and import it into Minecraft. Start a new flat world, and make sure to enable cheats and experiments.

Once you are in the world, use /function setup to create the ticking area and NPC entity. Then use /give @s wiki:teleport_menu to give yourself the teleportation item. Switch to survival mode (NPC dialogues do not work in Creative), hold the item, and right-click. You should see your dialogue appear.

Credits ​

This tutorial is based off of this page in the Minecraft Creator documentation.

Contributors

Edit NPC Dialogues on GitHub

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository