Applying Effects
FORMAT & MIN ENGINE VERSION 1.21.90
This tutorial assumes a basic understanding of blocks, including block events. Check out the blocks guide before starting.
This tutorial aims to show how to apply status effects to entities that are within a certain radius of your block.
Block JSON
To match the vanilla Beacon block, our custom block should apply effects every 4 seconds. This can be achieved by causing the block to "tick" every 80 ticks.
"minecraft:tick": {
"interval_range": [80, 80], // The interval shouldn't be random, so we use the same value for the min and max.
"looping": true
}
Next, we need to register our custom component to hook onto the tick event. This component should apply effects to entities within a specified area, so we're going to call it wiki:radial_effects
.
"wiki:radial_effects": {
"radius": 64, // Apply all of the following "effects" to entities within this radius of blocks.
"effects": [
{
"name": "wither",
"duration": 600, // 30 seconds in ticks.
"amplifier": 1
},
{
"name": "slowness",
"duration": 600,
"amplifier": 2
}
]
}
Custom Component Script
import { system } from "@minecraft/server";
/** @type {import("@minecraft/server").BlockCustomComponent} */
const BlockRadialEffectsComponent = {
onTick({ block, dimension }, { params }) {
const { radius, effects } = params; // The value we have assigned to the component in the block JSON.
// Gets all entities in the specified "radius" around the block.
const entities = dimension.getEntities({
location: block.center(),
maxDistance: radius,
});
for (const entity of entities) {
// Iterates over each object in the "effects" array.
for (const { name, duration, amplifier } of effects) {
entity.addEffect(name, duration, { amplifier });
}
}
},
};
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:radial_effects",
BlockRadialEffectsComponent
);
});
Example JSON
Example Wither Block
{
"format_version": "1.21.90",
"minecraft:block": {
"description": {
"identifier": "wiki:wither_block",
"menu_category": {
"category": "items"
}
},
"components": {
"minecraft:geometry": "geometry.wither_block",
"minecraft:material_instances": {
"*": {
"texture": "wiki:wither_block"
}
},
"minecraft:tick": {
"interval_range": [80, 80],
"looping": true
},
"wiki:radial_effects": {
"radius": 64,
"effects": [
{
"name": "wither",
"duration": 600,
"amplifier": 1
},
{
"name": "slowness",
"duration": 600,
"amplifier": 2
}
]
}
}
}
}
Contributors
Edit Applying Effects on GitHubText 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