change: don't allow knocked players to place blocks
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
e2021309cc
commit
5af7393908
9 changed files with 75 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<EntityPlayer> 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) {
|
||||
|
|
|
@ -38,6 +38,7 @@ public class KnockdownsFMLLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixi
|
|||
public List<String> getMixinConfigs() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("mixins.knockdowns.json");
|
||||
list.add("mixins.knockdowns.client.json");
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Potion> 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)) {
|
||||
|
|
|
@ -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<Boolean> cir) {
|
||||
private void onTotemActivation(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (cir.getReturnValue() && ((Object) this) instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) (Object) this;
|
||||
IKnockdownsPlayerData data = IKnockdownsPlayerData.get(player);
|
|
@ -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) {
|
13
src/main/resources/mixins.knockdowns.client.json
Normal file
13
src/main/resources/mixins.knockdowns.client.json
Normal file
|
@ -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"
|
||||
]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"package": "ru.octol1ttle.knockdowns.common.mixins",
|
||||
"package": "ru.octol1ttle.knockdowns.common.mixin",
|
||||
"required": true,
|
||||
"refmap": "${mixin_refmap}",
|
||||
"target": "@env(DEFAULT)",
|
||||
|
|
Loading…
Reference in a new issue