#[1.20.1] how do I make a specific entity detect if it's hit by a projectile and make it run code?

3 messages · Page 1 of 1 (latest)

blissful gazelle
#

Good morning, I want to make a specific entity(shown in the video) run some code if it only gets hit by any projectile(all abstract arrows, potions, projectiles in general). How do I make the entity detect if it gets hit by a projectile and make some code run as a consequence?

Edit for the message: if it gets hit

tranquil tapir
#

must be public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float f)
from livingentity class

try overridig that an put some system.out on it
if (damageSource.is(DamageTypeTags.IS_PROJECTILE)){
System.out.println( "DamageTypeTags.IS_PROJECTILE" );
}

blissful gazelle