Applying Constant Effects
experimental
easy
FORMAT & MIN ENGINE VERSION 1.20.30
This tutorial assumes a basic understanding of blocks, including block states. Check out the blocks guide before starting.
EXPERIMENTAL
Requires Holiday Creator Features
to trigger events.
This tutorial aims to show how to apply status effects to entities as long as these entities stand on the block.
Setup
We will need to add a couple things to our code, first let's start with a state that will hold true
when stood on, and false
otherwise:
"states": {
"wiki:stood_on": [false, true]
}
2
3
Now we need the minecraft:queued_ticking
component that will check if our property is set to true
and if so, trigger the event causing the effect to apply:
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [1, 1],
"on_tick": {
"event": "wiki:add_effect",
"target": "self",
"condition": "q.block_state('wiki:stood_on')"
}
}
2
3
4
5
6
7
8
9
We will use the minecraft:on_step_on
event trigger component to fire the event that will set our wiki:stood_on
property to true
...
"minecraft:on_step_on": {
"event": "wiki:step_on"
}
2
3
...and the minecraft:on_step_off
component to fire the event that will set our wiki:stood_on
to false
:
"minecraft:on_step_off": {
"event": "wiki:step_off"
}
2
3
Time to setup our events
. First, let's define the wiki:step_on
and wiki:step_off
events:
"events": {
"wiki:step_on": {
"set_block_state": {
"wiki:stood_on": true
}
},
"wiki:step_off": {
"set_block_state": {
"wiki:stood_on": false
}
}
}
2
3
4
5
6
7
8
9
10
11
12
The last thing to add is an event that will trigger the effect:
"wiki:add_effect": {
"run_command": {
"command": "effect @e[r=1] wither 2 2"
}
}
2
3
4
5
And done! The code above will trigger the desired status effect as long as the entity is standing on a block.
Example JSON
Example Wither Block
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:wither_block",
"menu_category": {
"category": "nature"
},
"states": {
"wiki:stood_on": [false, true]
}
},
"components": {
"minecraft:geometry": "geometry.wither_block",
"minecraft:material_instances": {
"*": {
"texture": "wither_block"
}
},
"minecraft:loot": "loot_tables/empty.json",
"minecraft:on_step_on": {
"event": "wiki:step_on"
},
"minecraft:on_step_off": {
"event": "wiki:step_off"
},
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [1, 1],
"on_tick": {
"event": "wiki:add_effect",
"condition": "q.block_state('wiki:stood_on')"
}
},
"minecraft:map_color": "#181818"
},
"events": {
"wiki:step_on": {
"set_block_state": {
"wiki:stood_on": true
}
},
"wiki:step_off": {
"set_block_state": {
"wiki:stood_on": false
}
},
"wiki:add_effect": {
"run_command": {
"command": "effect @e[r=1] wither 2 2"
}
}
}
}
}
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Additional Notes
Some context for the last part of the code:
Q: Why is the effect triggered via the
run_command
event response if there's already anadd_mob_effect
event response that does that?A:
add_mob_effect
does not have a target when triggered fromminecraft:queued_ticking
, so/effect
's target selection must be used instead.
Depending on the desired outcome, there is a potential issue if effect duration is set to less than 2 seconds. If the effect is causing damage to an entity (for example via poison), that damage will be applied as soon as the effect is triggered. This results in the situation where entity receives damage faster than in vanilla Minecraft, since applying effect is quicker than damage that occurs from effects applied for more than 2 seconds (considering the entity is moving). To better understand this, simply set the effect duration in command
to 1 second and compare the results. Having a 2 second duration allows the game to apply the damage in correct pace.