From 7efc2d9af12e15cec3d90000d527a675dfd210e1 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Fri, 19 Jul 2024 14:52:42 +0500 Subject: [PATCH] fix: account for STUPID mods overriding invulnerability i love 1.12.2 Signed-off-by: Octol1ttle --- .../common/KnockdownsCommonEventListener.java | 27 ++++++++++--------- .../knockdowns/common/KnockdownsUtils.java | 7 +++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java index a5348af..734c891 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java @@ -5,8 +5,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.MobEffects; -import net.minecraft.potion.PotionEffect; import net.minecraft.server.MinecraftServer; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumActionResult; @@ -16,6 +14,7 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.PlayerEvent; @@ -123,17 +122,24 @@ public class KnockdownsCommonEventListener { int period = MathHelper.floor(KNOCKED_HURT_PERIOD * 20); if (data.getTicksKnocked() <= KNOCKED_INVULNERABILITY_TICKS) { - knocked.setEntityInvulnerable(true); - knocked.extinguish(); - knocked.setAir(300); - KnockdownsUtils.clearBadPotionEffects(knocked); - knocked.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3)); + KnockdownsUtils.setKnockedInitialState(knocked); } else if (data.getTicksKnocked() % period == 0) { - knocked.setEntityInvulnerable(false); knocked.attackEntityFrom(DamageSource.GENERIC, knocked.getMaxHealth() / (KNOCKED_TENACITY / KNOCKED_HURT_PERIOD)); } } + @SubscribeEvent + public static void onPlayerHurt(LivingHurtEvent event) { + if (event.getEntityLiving() instanceof EntityPlayerMP) { + EntityPlayerMP knocked = (EntityPlayerMP) event.getEntityLiving(); + IKnockdownsPlayerData data = IKnockdownsPlayerData.get(knocked); + if (data.isKnockedDown() && data.getTicksKnocked() <= KNOCKED_INVULNERABILITY_TICKS) { + KnockdownsUtils.setKnockedInitialState(knocked); + event.setCanceled(true); + } + } + } + @SubscribeEvent public static void onPlayerDeath(LivingDeathEvent event) { if (!(event.getEntityLiving() instanceof EntityPlayerMP)) { @@ -153,11 +159,8 @@ public class KnockdownsCommonEventListener { player.setEntityInvulnerable(true); player.setHealth(1.0f); player.setAbsorptionAmount(player.getMaxHealth() - 1.0f); - player.extinguish(); - player.setAir(300); player.clearElytraFlying(); - KnockdownsUtils.clearBadPotionEffects(player); - player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3)); + KnockdownsUtils.setKnockedInitialState(player); Entity trueSource = event.getSource().getTrueSource(); if (trueSource instanceof EntityLiving) { diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java index 2c32768..b605f9a 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java @@ -18,6 +18,13 @@ public class KnockdownsUtils { public static final float KNOCKED_HURT_PERIOD = 1.2f; public static final float KNOCKED_TENACITY = 60.0f; + public static void setKnockedInitialState(EntityPlayerMP player) { + player.extinguish(); + player.setAir(300); + KnockdownsUtils.clearBadPotionEffects(player); + player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3)); + } + public static void clearBadPotionEffects(EntityPlayerMP player) { List removeList = new ArrayList<>();