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
    • 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 Education Edition
    • 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

Functions

Functions
  • Introduction
  • Function Pack Folder Structure
  • Notes For Beginners
  • Comments Style Guide
  • Creating a Function
  • Execution
  • Tick JSON
  • Sample Function Pack
  • Troubleshooting Functions

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_initialise.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_initialise.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

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