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 Loot Tables, Spawn Rules & Crafting Recipes
  • 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
    • Block Ticking
      Scripts
    • Blocks as Items
    • Multi-Blocks
    • Troubleshooting Blocks
      help
  • Sound & Visuals
    • Intro to Block Visuals
      guide
    • Block Culling
    • Block Models
      guide
    • Block Sounds
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
    • N-Way Rotation
      guide
  • Tutorials
    • Applying Effects
      Scripts
    • Avoiding State Limit
    • Block Orientation
    • Fake Blocks
      Scripts
    • Ore Loot Tables
      Scripts
    • Tool-Based Destruction
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Fences
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Heads
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Co-Location
    • Block Format History
    • Block Shapes
    • 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
  • Sounds (Server)
  • Subpacks
  • Texture Atlases
  • textures_list.json
Documentation
  • Advanced Molang
  • Aim Assist
  • 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
    • Equipment-Based Commands
    • Spawning Items
    • Throwable Items
  • Vanilla Re-Creations
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
  • 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
    • Dynamic Content Generation
    • Modifying Server Forms
    • Preserve Title Texts
    • Type Conversion
  • 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
    • Script Core Features
    • Block Placement Prevention
    • Custom Commands
    • GameTests
    • 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
    • Client Biomes
    • Dimensions
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Jigsaw Structures
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Block Ticking

scripting
intermediate
Block Ticking
  • Random Ticks
  • Scheduled Ticks
    • Block Ticks
    • Named Block Ticks

A block tick is a type of event that triggers for a block after a period of time. There are two main types of block tick:

  • Random ticks are events which occur for all blocks at a random interval in ticking chunks.
    • These are used for vanilla functionality such as crop growth.
    • They are better for performance than scheduled ticks as no data has to be saved for the block.
  • Scheduled ticks are events which occur after a specific duration of time.
    • These are used for vanilla functionality such as geyser eruptions.
    • They are worse for performance than random ticks as the delay until the next tick has to be saved.

Where possible, random ticks should be used instead of scheduled ticks to avoid performance issues.

Now that you have a basic understanding of what each type of block tick is, let's explore how you can hook into these ticks!

CUSTOM COMPONENTS REQUIRED

There are no global world events for block ticking, only custom components are able to hook into tick events. Therefore, there is no way to hook into ticks that occur for vanilla blocks.

Random Ticks ​

Each game tick, a number of blocks in each chunk is randomly selected to receive a random tick.

The randomTickSpeed game rule multiplies this number of blocks. By default, random tick speed is set to 1. Increasing it to 2 results in twice as many blocks per chunk receiving a random tick each game tick.

Any block can receive a random tick, but most don't do anything in response. If you would like your block to hook into random ticks, you'll need to make a custom component with the onRandomTick() hook. As an example, let's make a custom TNT block that explodes whenever it randomly ticks.

📝 BP/scripts/main.js
js
import { system } from "minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockExplodeOnRandomTickComponent = {
    onRandomTick({ block, dimension }, { params }) {
        dimension.createExplosion(block, params.power);
    },
};

system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "wiki:explode_on_random_tick",
        BlockExplodeOnRandomTickComponent
    );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
📝 BP/blocks/spontaneous_tnt.js
minecraft:blockcomponents
json
"wiki:explode_on_random_tick": {
    "power": 4
}
1
2
3

Scheduled Ticks ​

Scheduled ticks (also known as pending ticks or queued ticks) are ticks that occur after a specified duration of time.

Custom blocks can only have 1 unnamed tick scheduled at once, whereas up to 4 named ticks can be scheduled for the same game tick.

Unlike methods such as system.runTimeout(), scheduled ticks are saved into the world and persist even after the block has been moved by a piston.

Block Ticks ​

Regular (unnamed) scheduled ticks are triggered by the minecraft:tick component which schedules a tick with the specified duration when the block is placed.

The period of time until the tick occurs is determined by the interval_range parameter which accepts an array of two integer values: a minimum and maximum duration in game ticks. The game will then choose a random duration between the minimum and maximum each time the tick is scheduled.

Given that there are 20 game ticks in a second, the following code would schedule the tick for 1-2 seconds after the block is placed. To have a non-random delay, simply set the minimum and maximum to the same value.

minecraft:blockcomponents
json
"minecraft:tick": {
    "interval_range": [20, 40]
}
1
2
3

Optionally, the looping parameter can be specified to cause a new tick to be scheduled after the previous one has executed.

minecraft:blockcomponents
json
"minecraft:tick": {
    "interval_range": [20, 40],
    "looping": true
}
1
2
3
4

Now, let's do something when the block ticks. How about some more explosions?

We can amend the wiki:explode_on_random_tick component to instead make use of the onTick() hook which triggers on (unnamed) block ticks. Here's our new wiki:explode_on_tick

📝 BP/scripts/main.js
js
import { system } from "minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockExplodeOnTickComponent = {
    onTick({ block, dimension }, { params }) {
        dimension.createExplosion(block, params.power);
    },
};

system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "wiki:explode_on_tick",
        BlockExplodeOnTickComponent
    );
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
📝 BP/blocks/spontaneous_tnt.js
minecraft:blockcomponents
json
"minecraft:tick": {
    "interval_range": [20, 40]
},
"wiki:explode_on_tick": {
    "power": 4
}
1
2
3
4
5
6

Named Block Ticks ​

EXPERIMENTAL 1.26.60

Named scheduled ticks are experimental and require the Beta APIs experiment to be enabled.

Named scheduled ticks are similar to unnamed ticks with two main differences:

  • Named ticks are manually scheduled using scripts, there is no vanilla component that schedules them.
  • Named ticks (as the name implies) have a name attached which makes it easier to differentiate between ticks when multiple are scheduled.

To schedule a named tick on a block, you'll need to use the Block.scheduleNamedTick() method.

  • The first parameter of this method is the name of the tick (max 31 characters). This name should not have a namespace given that the pack UUID is internally used to namespace the tick.
  • The second parameter of this method is the duration of time (in game ticks) until the tick should occur.
js
block.scheduleNamedTick("my_tick", 20);
1

In order to hook into named ticks, you'll need to use the onNamedTick() custom component event hook. The event object passed to this hook includes an isName() method which can be used to check the name of the tick. This method only returns true if both the name provided and pack UUID of the script match those of the scheduled tick.

Let's create a custom component that causes the block to explode after certain events occur, giving the reason for the explosion in chat.

📝 BP/scripts/main.js
js
import { system, world } from "minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockExplodeAfterEventsComponent = {
    onPlayerInteract({ block }) {
        // Schedule an explosion for 0.5 seconds after a player interaction
        block.scheduleNamedTick("player_interact", 10);
    },
    onStepOn({ block }) {
        // Schedule an explosion for 2 seconds after an entity steps onto the block
        block.scheduleNamedTick("step_on", 40);
    },
    onNamedTick(event, { params }) {
        const { block, dimension } = event;

        // Explode the block when the named tick occurs
        dimension.createExplosion(block, params.power);

        // State the reason for the explosion in chat
        if (event.isName("player_interact")) {
            world.sendMessage("Block exploded because a player interacted with it.");
        } else if (event.isName("step_on")) {
            world.sendMessage("Block exploded because an entity stepped onto it.");
        }
    },
};

system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "wiki:explode_after_events",
        BlockExplodeAfterEventsComponent
    );
});
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
📝 BP/blocks/spontaneous_tnt.js
minecraft:blockcomponents
json
"wiki:explode_after_events": {
    "power": 4
}
1
2
3

Contributors

Edit Block Ticking on GitHub

Text and image content on this page is licensed under the Creative Commons Attribution 4.0 International License

Code samples on this page are licensed under the MIT License

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