取消伤害动画

Cancel hurting animation

我正在制作一个 mod 可以增加护甲,让你立于不败之地。到目前为止我有这个代码:

@SubscribeEvent
public void onPlayerHurt(LivingHurtEvent event) {
    if(event.getEntity() != null && event.getEntity() instanceof  EntityPlayer){
        EntityPlayer player = (EntityPlayer) event.getEntity();
        for(ItemStack stack : player.getArmorInventoryList()) {
            if(stack != null && stack.getItem() instanceof ItemUltimusArmor){
                event.setCanceled(true);
            }
        }
    }
}

当我使用我的盔甲时,这确实取消了伤害,但我仍然得到噪音和动画。穿着这件盔甲时,我希望能够没有那些东西。有什么办法可以做到吗?

我明白了。我使用 LivingAttackEvent 来监听一个事件,实际上使用了与 LivingHurtEvent 相同的代码,并且它起作用了。感谢 Pokechu22 的推荐!