Execute at Block Variant
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.
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
## 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]
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.
## 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]
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.