Steps to reproduce
Make the first test subject invulnerable to attacks
{ ... "minecraft:entity": { "description": { "identifier": "test:invulnerability", ... }, "components": { "minecraft:damage_sensor": { "triggers": { "cause": "all", "deals_damage": false } }, ... } } }Make an item to add a custom component to it
{ "format_version": "1.21.20", "minecraft:item": { "description": { "identifier": "test:item" }, "components": { ... "minecraft:custom_components": [ "test:before_damage" ] } } }Make a script to detect a hit by both using ItemComponentHitEntityEvent and EntityHurtBeforeEvent
import { world, system, EntityDamageCause } from '@minecraft/server'; world.beforeEvents.entityHurt.subscribe(data => { // beta const { hurtEntity: { typeId }, damageSource: { cause } } = data; if (cause !== EntityDamageCause.entityAttack || typeId.startsWith('test'')) return; data.cancel = true; }); system.beforeEvents.startup.subscribe(({ itemComponentRegistry }) => itemComponentRegistry.registerCustomComponent('test:before_damage', { onHitEntity: ({ hitEntity, hadEffect }) => console.log(`${hadEffect ? "Successfully" : "Failed to"} hit ${hitEntity.typeId}`); }); );Hit the entity and a vanilla mob for different results
Expected result
the hadEffect parameter returns false, as the script cancels the damage
Actual result
Returns true
Please edit your report to change the Affected Version to the version shown on the Minecraft title screen