3
Minecraft command block
So i have this one map ive been making for a while but i was wondering if there was a way to make mobs give effects whenever they attack players like how husks apply hunger and wither skeletons apply wither using command blocks. but for other mobs
2
You can apply Effects when a player is Damaged using Command Blocks by setting up a simple scoreboard loop:
On an impulse block or in the console, activate once:
scoreboard objectives add dmgTaken minecraft.custom:minecraft.damage_taken
I would also add the scoreboard display when testing:
/scoreboard objectives setdisplay sidebar dmgTaken
Then on a repeating command block:
execute as @a[scores={dmgTaken=2..}] run effect give @s minecraft:glowing 5 0 false
Link a chain command block (Conditional, Always Active) to the repeating block:
scoreboard players set @a[scores={dmgTaken=1..}] dmgTaken 0
(This allows the score to reset so the effect can be applied again.)
However, yes, CyborgVillager is on point here that a datapack may give you more flexibility and precision. The command loop above is basic and will trigger whenever a player takes ANY damage.
On an impulse block or in the console, activate once:
scoreboard objectives add dmgTaken minecraft.custom:minecraft.damage_taken
I would also add the scoreboard display when testing:
/scoreboard objectives setdisplay sidebar dmgTaken
Then on a repeating command block:
execute as @a[scores={dmgTaken=2..}] run effect give @s minecraft:glowing 5 0 false
Link a chain command block (Conditional, Always Active) to the repeating block:
scoreboard players set @a[scores={dmgTaken=1..}] dmgTaken 0
(This allows the score to reset so the effect can be applied again.)
However, yes, CyborgVillager is on point here that a datapack may give you more flexibility and precision. The command loop above is basic and will trigger whenever a player takes ANY damage.
Quite frankly I think making a datapack would be easier than using a command block due to more controls you can have ( better readability) for stuff like this.
I did a bit of digging and found CorgiXP YT video called 👉 Minecraft Summon Command Tutorial | Custom Mobs with NBT (Java 1.21)
And for abilities the only one I could find for command blocks was for the Bedrock edition, made by Jervenshmine How to give mobs custom abilities | Minecraft Bedrock Command Tutorial
- Hope those helps👍 You might have to edit a bit from the Bedrock to Java, but it should give you an idea
I did a bit of digging and found CorgiXP YT video called 👉 Minecraft Summon Command Tutorial | Custom Mobs with NBT (Java 1.21)
And for abilities the only one I could find for command blocks was for the Bedrock edition, made by Jervenshmine How to give mobs custom abilities | Minecraft Bedrock Command Tutorial
- Hope those helps👍 You might have to edit a bit from the Bedrock to Java, but it should give you an idea
