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 Effects
      Scripts
    • Avoiding State Limit
    • Block Orientation
    • Fake Blocks
      Scripts
    • Intercardinal Orientation
      Scripts
    • Ore Loot Tables
      Scripts
    • Tool-Based Destruction
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Heads
      Scripts
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Redstone Components
    • Vanilla Block Models
    • Vanilla Block Sounds
    • Vanilla Block Tags
    • Vanilla Voxel Shapes
Commands
  • General
    • Intro to Command Blocks
    • Understanding Selectors
    • Functions
      guide
    • Block States
    • Coordinate System
    • Giving NBT Items
    • Scoreboard Operations
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On First World Load
      function
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Detection Systems
    • Look Detection
    • Item Drop Detection
    • Movement Detections
    • Rain Detection
  • Techniques
    • Execute Logic Gates
      concept
    • Execute at Block Variant
    • Execution Forking
      concept
    • Binary in Commands
      concept
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Dynamic Displays
    • Orbital Camera
  • Useful Creations
    • Sphere Command
    • Compass Display
    • Custom Crafting
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Molang
  • Namespaces
  • Overwriting Assets
  • Shaders
  • Sounds
  • Subpacks
  • Texture Atlases
  • textures_list.json
Documentation
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Molang Queries
  • Pack Folder Structure
  • Shared Constructs
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogue
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Area Effect Clouds
    • Coordinate Space Conversion
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Movement
    • Entity Timers
    • Holding Items
    • Invulnerable Entities
    • Look at Entity
    • Riding Flying Entities
    • 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
    • Item Catalog
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Groups
    • Vanilla Item Tags
    • 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
    • Enabling Experiments by Editing NBT
    • 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
    • Custom Commands
    • GameTests
    • Script Core Features
    • Script Privileges
    • Script Requests API
    • Server Forms
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Text & Localization
  • General
    • Intro to Text & Localization
    • Raw Text
    • Splashes
  • Emojis & Symbols
    • Fonts
    • Intro to Emojis
    • Custom Emojis
    • Input Keys
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

Functions

guide
Functions
  • Introduction
  • Function Pack Folder Structure
  • Notes For Beginners
  • Comments Style Guide
  • Creating a Function
  • Execution
  • Tick JSON
  • Sample Function Pack
  • Troubleshooting Functions
  • Professional Workspace Setup (Optional)
    • 1. Visual Studio Code (VS Code)
    • 2. Version Control with GitHub
    • 3. GitHub Desktop
    • 4. Linking Your Folders

Introduction ​

Sourced by the Bedrock Commands Community (BCC) Discord

Functions are .mcfunction files which contain multiple lines of commands. They are run with the /function command in-game.

Functions are created in a Behavior Pack, nested within the functions folder. A function pack creates a system using solely function files.

Functions are useful in many ways to reduce the time spent going from command block to command block debugging a system. They also help with packaging systems for use in multiple worlds and provide many functions that can change how everything works.

Function Pack Folder Structure ​

      • this_code.mcfunction
      • more_of_this_code.mcfunction
      • tick.json
        • this_code_is_nested.mcfunction

To help create a consistent format, make it easier for everyone to follow, and to maintain uniformity across your functions, it is advised to follow these best-practices for your folder structure:

  1. All your .mcfunction files must be go in a namespaced root-folder within the functions folder. On Bedrock Wiki, we use the wiki namespace. However, you may choose a namespace based on your name or project. For more info, refer to the namespaces page.
    • βœ…οΈ BP/functions/wiki/random_number.mcfunction
    • ❌️ BP/functions/random_number.mcfunction
  2. Folders and files in a pack must be named using snake_case
    • This means only lowercase alpha-numeric characters and underscores (_) are allowed.
    • βœ…οΈ BP/functions/wiki/scoreboard/objectives/add_all.mcfunction
    • ❌️ BP/functions/wiki/scoreboard/objectives/Add-All.mcfunction
  3. They must be properly nested:
    • βœ…οΈ BP/functions/wiki/teleport/zone/hell
    • ❌ BP/functions/wiki/teleport_hellzone
  4. The names must follow an action_object structure. Meaning verbs should come before subjects.
    • βœ…οΈ add_all
    • ❌️ all_add
    • βœ…οΈ shuffle_position
    • ❌️ position_shuffle
  5. The total character length of any path must not exceed 80 characters (console limitation).
  6. Content folders should use consistent pluralization: Stick with names that are either all plural or all singular, don't mix and match. Example:

βœ…οΈ Consistent:

BP/functions/wiki/ability/ice_blast.mcfunction
BP/functions/wiki/ability/fire_trail.mcfunction
BP/functions/wiki/event/players/on_death.mcfunction
BP/functions/wiki/event/worlds/on_initialize.mcfunction
1
2
3
4
  • All content folders ability and event are consistently singular.
  • The content folders in event are also consistent, as both players and worlds are plural.

❌️ Inconsistent:

BP/functions/wiki/abilities/ice_blast.mcfunction
BP/functions/wiki/abilities/fire_trail.mcfunction
BP/functions/wiki/event/players/on_death.mcfunction
BP/functions/wiki/event/world/on_initialize.mcfunction
1
2
3
4
  • Only abilities content folder is pluralized while event is singular.
  • Also, in the event folder, the players folder is plural while world is singular.

Notes For Beginners ​

Below is an example function file for beginners reference:

BP/functions/wiki/effects.mcfunction
yaml
# These effects are for the spawn
effect @a[tag=wiki:at_spawn] regeneration 12 255 true
effect @a[tag=wiki:at_spawn] saturation 12 255 true
effect @a[tag=wiki:at_spawn] weakness 12 255 true

# These effects are for the nether
effect @a[tag=wiki:in_nether] fire_resistance 12 255 true
1
2
3
4
5
6
7
  • Commands in a function may not begin with a slash (/). Each new line in a function file represents a new command (ignored if left blank). You may start a line with a hashtag ( #) to add comments β€” the space after # is only a format preference. For comments style guide for functions, see the section below.

  • All commands in a function are run in the same tick. Because of this, a function which causes large changes may cause a sudden lag spike and it is helpful to delegate some commands across multiple ticks, if possible. Commands in a function are still run in the same sequence, however.

  • In Minecraft Bedrock, functions cannot run more than 10,000 commands in a function file. This includes any other function files that are executed inside of the original file.

  • It is not possible to run conditional commands. Those will still need to utilize command blocks in some way, or could utilize the 1.19.50 execute syntax.

  • Running commands with a specified delay in a function involves using scoreboard timers to incrementally count up each tick until a certain point, and executing commands at specific scores within the file. See Scoreboard Timers page to learn it's setup.

Comments Style Guide ​

  • When working with functions that contain many commands, it's helpful to keep them organized by using multiple hashtags in comments to indicate different header levels.
  • Optionally, to further distinguish these levels, you can apply different styles:
  • level 1 headers - # UPPERCASE
  • level 2 headers - ## Title Case
  • level 3 headers - ### Sentence case
  • Try to avoid the use of more than three header levels or too many headers overall, as this can make the code look cluttered. For your reference, see the example file below:
Example Function File
BP/functions/wiki/ability/fire_trail.mcfunction
yaml
# ON PLAYER ITEM DROP

## Give Effects
### Fire resistance
execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] fire_resistance 10 255
### Speed
execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] speed 10 1 true

## Add Particle Time (10s)
execute at @e[type=item,name="Fire Trail Ability"] run scoreboard players set @p[r=3] abilities.fire_trail 200

## Delete Item
kill @e[type=item,name="Fire Trail Ability"]


# ENTITY TIMER

## Emit Particle Trail
execute at @a[scores={wiki:ability.fire_trail=1..}] run particle minecraft:basic_flame_particle ~~~

## Countdown Timer
scoreboard players remove @a [scores={wiki:ability.fire_trail=1..}] wiki:ability.fire_trail 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Note the use of two lines of spacing before level 1 headers and one line of spacing before level 2 headers for improved readability.

This practice helps create a consistent format, making it easier for everyone to follow, and maintain uniformity across your functions. For Scoreboard and Tags convention, see the Style Guide page.

Creating a Function ​

  1. Locate the πŸ“ com.mojang folder and navigate to πŸ“ development_behavior_packs

    • The development folders are used for quick reloading of packs, as the packs aren't cached to the world files.
  2. Create a folder (of any name) for the function pack. This will be referred to as Behavior Pack or BP.

  3. Create a πŸ“„ manifest.json file and a πŸ–Ό pack_icon.png file (optional) within the BP folder.

    • A manifest file contains all the information needed to register a pack, while a pack icon displays visually in the pack menu. A pack icon is typically a 128x128 or a 256x256 image, though any power-of-2 resolution will do, they will be upscaled and downscaled accordingly.
Sample πŸ“„ manifest.json
BP/manifest.json
json
{
    "format_version": 2,
    "header": {
        "description": "Write Your Pack Description Here",
        "name": "Write Your Pack Name Here",
        "uuid": "00000000-0000-0000-0000-000000000000",
        "version": [1, 0, 0],
        "min_engine_version": [1, 19, 73]
    },
    "modules": [
        {
            "description": "Β§r",
            "type": "data",
            "uuid": "00000000-0000-0000-0000-000000000000",
            "version": [1, 0, 0]
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Note that the uuid field needs to be replaced with an actual uuid, and the two generated must be different from one another. You can generate a uuid at uuidgenerator.net

Sample πŸ–Ό pack_icon.png

Sample A:

pack_icon.png

Sample B:

pack_icon.png

  1. Create a πŸ“ functions folder. Any file within this folder that ends with .mcfunction will be registered as a function in-game, which can be run with /function <function_name>.

    • Nested functions are allowed, simply list the file path in relation to the functions folder as shown in the function pack folder structure.
  2. Apply the behavior pack in-game and try out the functions. Function file changes can be reflected in the world by running /reload or by simply relogging.

NOTE:

Functions are versioned; therefore, they will run in the version listed in the πŸ“„ manifest.json, such as:

  • min_engine_version 1.19.50 or above will adopt the new execute syntax.
  • min_engine_version 1.19.70 or above will require aux values be replaced with block states.

Execution ​

Functions can be executed in-game by typing /function name_of_function. This will execute all the commands in the function file, all in a single tick.

Nested functions, for example BP/functions/wiki/teleport/zone/hell can be run using the nested folder path, in this case /function wiki/teleport/zone/hell

Tick JSON ​

The final file within a functions folder is the tick.json file. This specifies functions to run server-side on every game tick, (similar to a repeating command block). It is located in the BP/functions folder. By default, functions running in this file execute at origin (0, 0, 0) in the overworld. Example tick.json` file:

BP/functions/tick.json
json
{
  "values": [
    "wiki/function_1",
    "wiki/function_2"
  ]
}
1
2
3
4
5
6

Note: Functions in this file are run as soon as the world is initialized, regardless of whether or not the player has been loaded. This may cause unintended behavior if used incorrectly.

Sample Function Pack ​

Download

Troubleshooting Functions ​

Your functions may not appear within the command suggestions when using /function. This is normally due to an error with one or more commands in the function.

Enabling the Content Log in the creator settings allows you to see if there are any errors in your function pack, which function the error is in, on which line, and exactly what the syntax error is for that command.

The list of errors will be generated every time you load a world or run /reload to reflect changes after editing files. The list can be viewed on-screen for a few seconds, as well as in the content log history in settings.

contentLogToggles

contentLogHistory

Professional Workspace Setup (Optional) ​

Setting up a dedicated workspace is the final step in developing function packs or add-ons like a pro. While you can write functions in a basic text editor, the following tools will help you catch errors instantly, collaborate with others, and sync your changes directly into Minecraft.

1. Visual Studio Code (VS Code) ​

Think of VS Code as your command center. It is a powerful, free code editor that makes writing .mcfunction files much easier than using Notepad.

  • Download: Get it from the Official VS Code Site.
  • The Essential Plugin: Once installed, click the Extensions icon (the four squares) on the left sidebar and search for MCBE Command Checker.
  • Why use it?
    • Syntax Highlighting: Commands change color based on their type, making them easier to read.
    • Auto-Complete: As you type, the editor will suggest valid arguments, targets, and block names.
    • Error Detection: It will highlight typos or invalid syntax with a red underline before you even open the game.

Example screenshot:

Editing a .mcfunction file in VSCode

2. Version Control with GitHub ​

GitHub is a cloud-based service that acts as a "save point" for your projects.

  • Create an Account: Sign up at GitHub.com.
  • The Benefits:
    • Cloud Backup: You’ll never lose your work if your computer crashes.
    • Collaboration: You can share a link to your code so others can review it or help you fix bugs without sending files back and forth.
    • History: You can see exactly what changes you made today versus a week ago.
    • Releases: Once your pack is ready for the public, you can create a "Release." This allows you to host specific versions (like v1.0 or v2.1) as downloadable .mcpack files, making it easy for players to find the most stable version of your work.

3. GitHub Desktop ​

While GitHub lives in the cloud, GitHub Desktop is the app on your computer that talks to it. It’s the easiest way for beginners to manage their files without learning complex "Git" commands.

  • Download: Get it at desktop.github.com.
  • The Workflow: After you finish writing code in VS Code, you use GitHub Desktop to "Commit" (save) and "Push" (upload) your changes to the cloud.

4. Linking Your Folders ​

The biggest hurdle in Bedrock development is moving files from your "Work" folder to the Minecraft "Behavior Pack" folder. You can skip this manual step by creating a Directory Junction (a shortcut that acts like a real folder).

By linking your \GitHub\ProjectName folder to Minecraft's \development_behavior_packs\ProjectName folder, any change you save in VS Code is instantly updated in your Minecraft files.

How to Link Folders (Windows):

  1. Locate your project in your GitHub folder.

Example:

C:\Github\YOUR_PROJECT_NAME
1
  1. Locate your Minecraft development folder.

Example:

C:\Users\YOUR_NAME\AppData\Roaming\Minecraft Bedrock\Users\Shared\games\com.mojang\development_behavior_packs\YOUR_PROJECT_NAME
1
  1. Open Command Prompt as Administrator.
  2. Use the mklink /J command to link them.

Example:

mklink /J "Path\To\Minecraft\Folder" "Path\To\GitHub\Folder"`
1

TIP

Once these folders are linked, you don’t need to restart Minecraft or even re-enter the world to test your work. Simply save your file in VS Code and run the /reload command in-game to apply your changes immediately.

Bonus Tip: Enable Auto Save in VS Code (File > Auto Save) to make this process even fasterβ€”just tab back into Minecraft and run /reload!

Contributors

Edit Functions 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