Topic category: Help with Minecraft modding (Java Edition)
This may contain slightly more technical information than normal MCreator posts:
1.21.1 NeoForge 21.1.176 / MCreator version 2025.2
I have a problem: I want to implement a shield mechanic. While the shield is active, the LivingEntity should be invulnerable—taking no damage and triggering no hit animations.
The issue is with handling the damage: LivingDamageEvent / actuallyHurt gives me the final, calculated damage, but by that point the entity has already taken the damage, so I can't cancel it but only reduce it to 0 damage with animations.
LivingIncomingDamageEvent (Entity is attacked) lets me cancel the event, but the damage it provides is raw—before armor, enchantments, or potion effects are applied.
I also tried using a Mixin on "actuallyHurt" to intercept damage and redirect it to the shield instead. Even if I cancel the event there, the game still plays the damage sound and screen shake. What I need is a way to get the fully calculated damage and still be able to cancel the event, so the player feels invulnerable. I thought about using a fake player to capture pre/post damage, but that would be very performance-heavy.
Here's the triggering order of trigger, events and vanilla code:
LivingIncomingDamageEvent (Entity is attacked) → actuallyHurt (that's from Player.class so mixin) → LivingDamageEvent.Pre → LivingDamageEvent.Post (Entity is hurt)
I can only cancel the event at "LivingIncomingDamageEvent" but i can't get calculated final damage from this. Others are letting me get calculatet damage, but i can't cancel the event properly. I can make incoming damage 0, but still triggering hurt animation, sound, screentilt, etc.
Any ideas or suggestions? And sorry for my english.