fix: account for STUPID mods overriding invulnerability
i love 1.12.2 Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
c5d7692742
commit
7efc2d9af1
2 changed files with 22 additions and 12 deletions
|
@ -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) {
|
||||
|
|
|
@ -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<Potion> removeList = new ArrayList<>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue