diff --git a/src/main/java/ru/octol1ttle/knockdowns/client/gui/ReviveGui.java b/src/main/java/ru/octol1ttle/knockdowns/client/gui/ReviveGui.java index 02816fd..b8b5e0d 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/client/gui/ReviveGui.java +++ b/src/main/java/ru/octol1ttle/knockdowns/client/gui/ReviveGui.java @@ -30,7 +30,7 @@ public class ReviveGui extends KnockdownsBaseGui { String timerText = String.format("%.1f", data.getReviveTimeLeft() / 20.0f); float timerX = (resolution.getScaledWidth() - font.getStringWidth(timerText)) * 0.5f; - data.getRevivers().removeIf(reviver -> reviver.isDead || !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown()); + data.getRevivers().removeIf(reviver -> !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown()); int reviverCount = data.getRevivers().size(); TextFormatting color; if (reviverCount == 0) { diff --git a/src/main/java/ru/octol1ttle/knockdowns/client/mixin/PlayerControllerMPMixin.java b/src/main/java/ru/octol1ttle/knockdowns/client/mixin/PlayerControllerMPMixin.java new file mode 100644 index 0000000..c5bfb92 --- /dev/null +++ b/src/main/java/ru/octol1ttle/knockdowns/client/mixin/PlayerControllerMPMixin.java @@ -0,0 +1,16 @@ +package ru.octol1ttle.knockdowns.client.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerControllerMP; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData; + +@Mixin(PlayerControllerMP.class) +public abstract class PlayerControllerMPMixin { + @ModifyExpressionValue(method = "processRightClickBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemBlock;canPlaceBlockOnSide(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;)Z")) + private boolean cancelPlaceIfKnockedDown(boolean original) { + return original && !IKnockdownsPlayerData.get(Minecraft.getMinecraft().player).isKnockedDown(); + } +} diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java index d2ec8d0..a5348af 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsCommonEventListener.java @@ -62,6 +62,15 @@ public class KnockdownsCommonEventListener { } } + @SubscribeEvent + public static void onPlayerJoin(PlayerLoggedInEvent event) { + IKnockdownsPlayerData data = IKnockdownsPlayerData.get(event.player); + KnockdownsNetwork.sendToPlayer( + new SynchronizePlayerDataS2CPacket.Full(event.player.getEntityId(), data.isKnockedDown(), data.getReviveTimeLeft()), + (EntityPlayerMP) event.player + ); + } + @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { MinecraftServer server = event.player.getServer(); @@ -74,13 +83,15 @@ public class KnockdownsCommonEventListener { return; } + knocked.clearElytraFlying(); + if (allPlayersKnocked(server, knocked)) { knocked.attackEntityFrom(DamageSource.GENERIC, knocked.getMaxHealth()); return; } List revivers = data.getRevivers(); - revivers.removeIf(reviver -> reviver.isDead || !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown()); + revivers.removeIf(reviver -> !reviver.isEntityAlive() || IKnockdownsPlayerData.get(reviver).isKnockedDown()); if (!revivers.isEmpty()) { data.setReviveTimeLeft(data.getReviveTimeLeft() - revivers.size()); KnockdownsNetwork.sendToMultiple( @@ -111,7 +122,13 @@ public class KnockdownsCommonEventListener { data.setTicksKnocked(data.getTicksKnocked() + 1); int period = MathHelper.floor(KNOCKED_HURT_PERIOD * 20); - if (data.getTicksKnocked() >= KNOCKED_INVULNERABILITY_TICKS && data.getTicksKnocked() % period == 0) { + 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)); + } else if (data.getTicksKnocked() % period == 0) { knocked.setEntityInvulnerable(false); knocked.attackEntityFrom(DamageSource.GENERIC, knocked.getMaxHealth() / (KNOCKED_TENACITY / KNOCKED_HURT_PERIOD)); } @@ -133,15 +150,14 @@ public class KnockdownsCommonEventListener { return; } - player.clearActivePotions(); player.setEntityInvulnerable(true); player.setHealth(1.0f); player.setAbsorptionAmount(player.getMaxHealth() - 1.0f); player.extinguish(); player.setAir(300); player.clearElytraFlying(); - - player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 6000, 3)); + KnockdownsUtils.clearBadPotionEffects(player); + player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, Integer.MAX_VALUE, 3)); Entity trueSource = event.getSource().getTrueSource(); if (trueSource instanceof EntityLiving) { @@ -230,15 +246,6 @@ public class KnockdownsCommonEventListener { } } - @SubscribeEvent - public static void onPlayerJoin(PlayerLoggedInEvent event) { - IKnockdownsPlayerData data = IKnockdownsPlayerData.get(event.player); - KnockdownsNetwork.sendToPlayer( - new SynchronizePlayerDataS2CPacket.Full(event.player.getEntityId(), data.isKnockedDown(), data.getReviveTimeLeft()), - (EntityPlayerMP) event.player - ); - } - @SubscribeEvent public static void onPlayerLeave(PlayerLoggedOutEvent event) { for (EntityPlayer knocked : event.player.world.playerEntities) { diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsFMLLoadingPlugin.java b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsFMLLoadingPlugin.java index 77e881b..457d398 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsFMLLoadingPlugin.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsFMLLoadingPlugin.java @@ -38,6 +38,7 @@ public class KnockdownsFMLLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixi public List getMixinConfigs() { ArrayList list = new ArrayList<>(); list.add("mixins.knockdowns.json"); + list.add("mixins.knockdowns.client.json"); return list; } } diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java index 65c8d54..2c32768 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/KnockdownsUtils.java @@ -1,8 +1,12 @@ package ru.octol1ttle.knockdowns.common; +import java.util.ArrayList; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.MobEffects; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; import net.minecraft.server.MinecraftServer; import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData; import ru.octol1ttle.knockdowns.common.network.KnockdownsNetwork; @@ -14,6 +18,20 @@ public class KnockdownsUtils { public static final float KNOCKED_HURT_PERIOD = 1.2f; public static final float KNOCKED_TENACITY = 60.0f; + public static void clearBadPotionEffects(EntityPlayerMP player) { + List removeList = new ArrayList<>(); + + for (PotionEffect effect : player.getActivePotionEffects()) { + if (effect.getPotion().isBadEffect()) { + removeList.add(effect.getPotion()); + } + } + + for (Potion potion : removeList) { + player.removePotionEffect(potion); + } + } + public static boolean allPlayersKnocked(MinecraftServer server, EntityPlayer except) { for (EntityPlayer player : server.getPlayerList().getPlayers()) { if (player.equals(except)) { diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityLivingBaseMixin.java b/src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityLivingBaseMixin.java similarity index 90% rename from src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityLivingBaseMixin.java rename to src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityLivingBaseMixin.java index 8bcea94..598bbbc 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityLivingBaseMixin.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityLivingBaseMixin.java @@ -1,4 +1,4 @@ -package ru.octol1ttle.knockdowns.common.mixins; +package ru.octol1ttle.knockdowns.common.mixin; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -19,7 +19,7 @@ public abstract class EntityLivingBaseMixin extends Entity { } @Inject(method = "checkTotemDeathProtection", at = @At("RETURN")) - public void onTotemActivation(CallbackInfoReturnable cir) { + private void onTotemActivation(CallbackInfoReturnable cir) { if (cir.getReturnValue() && ((Object) this) instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) (Object) this; IKnockdownsPlayerData data = IKnockdownsPlayerData.get(player); diff --git a/src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityPlayerMixin.java b/src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityPlayerMixin.java similarity index 89% rename from src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityPlayerMixin.java rename to src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityPlayerMixin.java index e1684ac..0b6e54f 100644 --- a/src/main/java/ru/octol1ttle/knockdowns/common/mixins/EntityPlayerMixin.java +++ b/src/main/java/ru/octol1ttle/knockdowns/common/mixin/EntityPlayerMixin.java @@ -1,4 +1,4 @@ -package ru.octol1ttle.knockdowns.common.mixins; +package ru.octol1ttle.knockdowns.common.mixin; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.entity.player.EntityPlayer; @@ -8,7 +8,7 @@ import ru.octol1ttle.knockdowns.common.data.IKnockdownsPlayerData; @SuppressWarnings("ConstantValue") @Mixin(EntityPlayer.class) -public class EntityPlayerMixin { +public abstract class EntityPlayerMixin { @ModifyReturnValue(method = "shouldHeal", at = @At("RETURN")) private boolean dontHealIfKnockedDown(boolean original) { if (((Object) this) instanceof EntityPlayer) { diff --git a/src/main/resources/mixins.knockdowns.client.json b/src/main/resources/mixins.knockdowns.client.json new file mode 100644 index 0000000..619948d --- /dev/null +++ b/src/main/resources/mixins.knockdowns.client.json @@ -0,0 +1,13 @@ +{ + "package": "ru.octol1ttle.knockdowns.client.mixin", + "required": true, + "refmap": "${mixin_refmap}", + "target": "@env(DEFAULT)", + "minVersion": "0.8.5", + "compatibilityLevel": "JAVA_8", + "mixins": [], + "server": [], + "client": [ + "PlayerControllerMPMixin" + ] +} diff --git a/src/main/resources/mixins.knockdowns.json b/src/main/resources/mixins.knockdowns.json index 7e58f0a..55681b4 100644 --- a/src/main/resources/mixins.knockdowns.json +++ b/src/main/resources/mixins.knockdowns.json @@ -1,5 +1,5 @@ { - "package": "ru.octol1ttle.knockdowns.common.mixins", + "package": "ru.octol1ttle.knockdowns.common.mixin", "required": true, "refmap": "${mixin_refmap}", "target": "@env(DEFAULT)",