diff --git a/src/main/java/net/mcreator/target/mobeffect/ShockMobEffect.java b/src/main/java/net/mcreator/target/mobeffect/ShockMobEffect.java index 6ae5d69b0..c04519528 100644 --- a/src/main/java/net/mcreator/target/mobeffect/ShockMobEffect.java +++ b/src/main/java/net/mcreator/target/mobeffect/ShockMobEffect.java @@ -13,13 +13,11 @@ import net.minecraft.util.RandomSource; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeMap; import net.minecraft.world.entity.ai.attributes.AttributeModifier; 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.MobEffectEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -35,27 +33,33 @@ public class ShockMobEffect extends MobEffect { @Override public void addAttributeModifiers(LivingEntity entity, AttributeMap attributeMap, int amplifier) { - if (entity instanceof Player player) { - if (!entity.level().isClientSide()) { - entity.level().playSound(null, BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1); - } else { - entity.level().playLocalSound(entity.getX(), entity.getY(), entity.getZ(), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1, false); - } + if (!entity.level().isClientSide()) { + entity.level().playSound(null, BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1); + } else { + entity.level().playLocalSound(entity.getX(), entity.getY(), entity.getZ(), TargetModSounds.SHOCK.get(), SoundSource.HOSTILE, 1, 1, false); } } @Override public void applyEffectTick(LivingEntity entity, int amplifier) { - entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36)); - entity.xRotO = entity.getXRot(); - if (!entity.level().isClientSide()) { - entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10)); + Entity attacker; + if (!entity.getPersistentData().contains("TargetShockAttacker")) { + attacker = null; + } 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 public boolean isDurationEffectTick(int duration, int amplifier) { - return true; + return duration % 20 == 0; } @SubscribeEvent @@ -68,7 +72,7 @@ public class ShockMobEffect extends MobEffect { } living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(), - event.getEffectSource()), 2 * (instance.getAmplifier() + 1)); + event.getEffectSource()), 5.0f); if (event.getEffectSource() instanceof LivingEntity source) { living.getPersistentData().putInt("TargetShockAttacker", source.getId()); @@ -108,27 +112,8 @@ public class ShockMobEffect extends MobEffect { LivingEntity living = event.getEntity(); if (living.hasEffect(TargetModMobEffects.SHOCK.get())) { - MobEffectInstance instance = living.getEffect(TargetModMobEffects.SHOCK.get()); - - 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)); - } - } + living.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36)); + living.xRotO = living.getXRot(); } } }