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
    • Giving NBT Items
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On First World Load
    • 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
  • Techniques
    • Execute Logic Gates
    • Execute at Block Variant
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Item Drop Detection
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Compass Display
    • 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

Execute at Block Variant

Execute at Block Variant
  • Introduction
  • System
  • Purpose of Each Command
  • System - Modified

Introduction ​

Sourced by the Bedrock Commands Community (BCC) Discord

This technique allows you to execute commands at the location of any block variant without explicitly specifying each coordinate.

Demonstration GIF

WARNING

  • This system must be used with caution when a large number of blocks are involved, as it can cause a lag spike due to a temporary entity being generated for each block.
  • When used in areas containing fully-filled composter blocks, it could falsely replace it. If you have any such builds or blocks in your world that could be affected, please use the slightly tweaked version of it at the end of this page here, which involves 3 additonal commands.

System ​

BP/functions/wiki/execute_at_blocks/diamond_block.mcfunction
yaml
## Replace [Block] in [Area] with Fully-filled Composters
execute at @a run fill ~8~8~8 ~-8~-1~-8 composter ["composter_fill_level"=8] replace diamond_block

## Tag Existing Item Drops to Ignore
tag @e[type=item] add wiki:ignored.item

## Make the Fully-filled Composters Drop Their Bonemeal
### By replacing the fully-filled composter with original [block]
execute at @a run fill ~8~8~8 ~-8~-1~-8 diamond_block replace composter ["composter_fill_level"=8]

## Your Commands Here (Example):
### Play a shulker bullet particle above all diamond blocks near players
execute at @e[type=item,tag=!wiki:ignored.item] align xyz positioned ~0.5~0.5~0.5 run particle minecraft:shulker_bullet ~~1~

## Delete All System Generated Bonemeal Drops
kill @e[type=item,tag=!wiki:ignored.item]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Chain of Five Command Blocks

Here, we have used a /particle command as an example, but you can use any command you prefer and as many as you need.

Just make sure to follow the given order and properly instruct execute at @e[type=item,tag=!wiki:ignored.item] align xyz positioned ~0.5~0.5~0.5 run, as shown for your desired commands.

Also note that the block of choice (diamond_block) and desired area (at @a run fill ~8~8~8 ~-8~-1~-8) can be changed to your preference. For example, gold_block or iron_block and fill 8 8 8 -12 -12 -12 or at @a fill ~3~3~3 ~-3~-3~-3.

Purpose of Each Command ​

  • Command 1: All blocks of your choice (e.g., diamond blocks) in a specified area (e.g., a certain volume around all players) will be replaced with composters fully filled with bonemeal.
    • A fully filled composter has a useful behavior: when destroyed or replaced, it drops the bonemeal it contains.
  • Command 2: All existing item drops (e.g., armor dropped by a player) will be tagged with wiki:ignored.item. This ensures that in Command 5, only bonemeal dropped by the composters is deleted, while all other item drops not generated by the system are ignored.
  • Command 3: As explained in Command 1, we now replace the composters with the original block (e.g., diamond block). This causes the bonemeal inside the composter to drop, allowing us to target it using selectors and execute desired commands at its position.
  • Command 4: As clarified earlier, this is an example command that can be modified or expanded according to your intended use.
  • Command 5: This is the final command in the system. It deletes all bonemeal item drops generated by the composters, preventing lag caused by an increased number of item drops in the world.

If using functions, your pack folder structure will be as follows:

          • 📝diamond_block.mcfunction
    • 🖼️pack_icon.png
    • 📝manifest.json

System - Modified ​

This is a slightly modified version of the system that will not affect any existing fully-filled composters in your world.

Demonstration GIF

BP/functions/wiki/execute_at_blocks/diamond_block.mcfunction
yaml
## Tag Existing Item Drops to Ignore
tag @e[type=item] add wiki:ignored.item

## 🟩 Make Existing Fully-filled Composters in [Area] Drop Their Bonemeal
### By replacing them with air
execute at @a run fill ~8~8~8 ~-8~-1~-8 air replace composter ["composter_fill_level"=8]

## 🟩 Tag Existing Fully-filled Composter Drops to Ignore
tag @e[type=item,tag=!wiki:ignored.item] add wiki:ignored.composter

## Replace [Block] in [Area] with Fully-filled Composters
execute at @a run fill ~8~8~8 ~-8~-1~-8 composter ["composter_fill_level"=8] replace diamond_block

## Make System's Fully-filled Composters Drop Their Bonemeal
### By replacing them with original [block]
execute at @a run fill ~8~8~8 ~-8~-1~-8 diamond_block replace composter ["composter_fill_level"=8]

## 🟩 Return Previously Existing Fully-filled Composters
execute at @e[type=item,tag=wiki:ignored.composter] run setblock ~~~ composter ["composter_fill_level"=8]

## Your Commands Here (Example):
### Play a shulker bullet particle above all diamond blocks near players
execute at @e[type=item,tag=!wiki:ignored.item,tag=!wiki:ignored.composter] align xyz positioned ~0.5~0.5~0.5 run particle minecraft:shulker_bullet ~~1~

## Delete All System Generated Bonemeal Drops
kill @e[type=item,tag=!wiki:ignored.item]
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

Chain of Eight Command Blocks

Note: Commands under level 2 headers prefixed with 🟩 indicate newly added commands.

In the original system, you only needed to ignore the wiki:ignored.item tag in the commands you wanted to execute. However, in this modified system, you must also ignore the wiki:ignored.composter tag as shown above.

Contributors

Edit Execute at Block Variant 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