mojira.dev
MCPE-234391

ItemComponentHitEntityEvent not working well with EntityHurtBeforeEvent

Steps to reproduce

  1. Make the first test subject invulnerable to attacks

    {
    	...
    	"minecraft:entity": {
    		"description": {
    			"identifier": "test:invulnerability",
    			...
    		},
    		"components": {
    			"minecraft:damage_sensor": {
    				"triggers": {
    					"cause": "all",
    					"deals_damage": false
    				}
    			},
    			...
    		}
    	}
    }
  2. 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"
                ]
            }
        }
    }
  3. 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}`);
        });
    );
  4. 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

Attachments

Comments 3

Please edit your report to change the Affected Version to the version shown on the Minecraft title screen

Please attach an example add-on that can be used to reproduce the issue.

Random Persom

(Unassigned)

Unconfirmed

Multiple

26.0.25 Preview, 26.0.26 Preview

Retrieved