添加电击效果无限时长适配
This commit is contained in:
parent
7122367df3
commit
8f8caa22ce
1 changed files with 20 additions and 35 deletions
|
@ -13,13 +13,11 @@ import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.effect.MobEffectCategory;
|
import net.minecraft.world.effect.MobEffectCategory;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
||||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||||
import net.minecraftforge.event.entity.living.MobEffectEvent;
|
import net.minecraftforge.event.entity.living.MobEffectEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
@ -35,27 +33,33 @@ public class ShockMobEffect extends MobEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAttributeModifiers(LivingEntity entity, AttributeMap attributeMap, int amplifier) {
|
public void addAttributeModifiers(LivingEntity entity, AttributeMap attributeMap, int amplifier) {
|
||||||
if (entity instanceof Player player) {
|
|
||||||
if (!entity.level().isClientSide()) {
|
if (!entity.level().isClientSide()) {
|
||||||
entity.level().playSound(null, BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1);
|
entity.level().playSound(null, BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
entity.level().playLocalSound(entity.getX(), entity.getY(), entity.getZ(), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1, false);
|
entity.level().playLocalSound(entity.getX(), entity.getY(), entity.getZ(), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
||||||
entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36));
|
Entity attacker;
|
||||||
entity.xRotO = entity.getXRot();
|
if (!entity.getPersistentData().contains("TargetShockAttacker")) {
|
||||||
if (!entity.level().isClientSide()) {
|
attacker = null;
|
||||||
entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10));
|
} else {
|
||||||
|
attacker = entity.level().getEntity(entity.getPersistentData().getInt("TargetShockAttacker"));
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.hurt(TargetModDamageTypes.causeShockDamage(entity.level().registryAccess(), attacker), 5.0f);
|
||||||
|
|
||||||
|
if (attacker instanceof ServerPlayer player) {
|
||||||
|
player.level().playSound(null, player.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||||
|
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDurationEffectTick(int duration, int amplifier) {
|
public boolean isDurationEffectTick(int duration, int amplifier) {
|
||||||
return true;
|
return duration % 20 == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -68,7 +72,7 @@ public class ShockMobEffect extends MobEffect {
|
||||||
}
|
}
|
||||||
|
|
||||||
living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(),
|
living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(),
|
||||||
event.getEffectSource()), 2 * (instance.getAmplifier() + 1));
|
event.getEffectSource()), 5.0f);
|
||||||
|
|
||||||
if (event.getEffectSource() instanceof LivingEntity source) {
|
if (event.getEffectSource() instanceof LivingEntity source) {
|
||||||
living.getPersistentData().putInt("TargetShockAttacker", source.getId());
|
living.getPersistentData().putInt("TargetShockAttacker", source.getId());
|
||||||
|
@ -108,27 +112,8 @@ public class ShockMobEffect extends MobEffect {
|
||||||
LivingEntity living = event.getEntity();
|
LivingEntity living = event.getEntity();
|
||||||
|
|
||||||
if (living.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
if (living.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||||
MobEffectInstance instance = living.getEffect(TargetModMobEffects.SHOCK.get());
|
living.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36));
|
||||||
|
living.xRotO = living.getXRot();
|
||||||
if (instance == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity entity;
|
|
||||||
if (!living.getPersistentData().contains("TargetShockAttacker")) {
|
|
||||||
entity = null;
|
|
||||||
} else {
|
|
||||||
entity = living.level().getEntity(living.getPersistentData().getInt("TargetShockAttacker"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instance.getDuration() % 20 == 0) {
|
|
||||||
living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(), entity), 2 * (instance.getAmplifier() + 1));
|
|
||||||
living.level().playSound(null, living.getOnPos(), TargetModSounds.ELECTRIC.get(), SoundSource.PLAYERS, 1, 1);
|
|
||||||
if (entity instanceof ServerPlayer player) {
|
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
|
||||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue