修改电击效果逻辑
This commit is contained in:
parent
02d2d841a9
commit
84e3027794
2 changed files with 101 additions and 30 deletions
|
@ -5,13 +5,11 @@ import net.mcreator.target.headshot.BoundingBoxManager;
|
||||||
import net.mcreator.target.headshot.IHeadshotBox;
|
import net.mcreator.target.headshot.IHeadshotBox;
|
||||||
import net.mcreator.target.init.*;
|
import net.mcreator.target.init.*;
|
||||||
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
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.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
|
@ -108,32 +106,14 @@ public class TaserBulletProjectileEntity extends ThrowableItemProjectile {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!living.level().isClientSide()) {
|
if (!living.level().isClientSide()) {
|
||||||
living.addEffect(new MobEffectInstance(TargetModMobEffects.SHOCK.get(), 100, 0));
|
living.addEffect(new MobEffectInstance(TargetModMobEffects.SHOCK.get(), 100, 0), this.getOwner());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headshot) {
|
if (headshot) {
|
||||||
entity.hurt(TargetModDamageTypes.causeShockDamage(this.level().registryAccess(), this.getOwner()), this.damage * 1.5f);
|
entity.hurt(TargetModDamageTypes.causeShockDamage(this.level().registryAccess(), this.getOwner()), this.damage * 1.5f);
|
||||||
} else {
|
} else {
|
||||||
entity.hurt(TargetModDamageTypes.causeShockDamage(this.level().registryAccess(), this.getOwner()), this.damage);
|
entity.hurt(TargetModDamageTypes.causeShockDamage(this.level().registryAccess(), this.getOwner()), this.damage);
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=1;i<=5;i++) {
|
|
||||||
|
|
||||||
TargetMod.queueServerWork(i * 20, () -> {
|
|
||||||
|
|
||||||
if (entity == null || this.getOwner() == null || !entity.isAlive())
|
|
||||||
return;
|
|
||||||
if (!entity.level().isClientSide())
|
|
||||||
|
|
||||||
entity.hurt(TargetModDamageTypes.causeShockDamage(this.level().registryAccess(), this.getOwner()), 1);
|
|
||||||
entity.invulnerableTime = 0;
|
|
||||||
|
|
||||||
if (this.getOwner() instanceof ServerPlayer player) {
|
|
||||||
this.getOwner().level().playSound(null, this.getOwner().blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
|
||||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.discard();
|
this.discard();
|
||||||
|
@ -155,8 +135,8 @@ public class TaserBulletProjectileEntity extends ThrowableItemProjectile {
|
||||||
@Override
|
@Override
|
||||||
protected void onHitBlock(BlockHitResult result) {
|
protected void onHitBlock(BlockHitResult result) {
|
||||||
if (!level().isClientSide) {
|
if (!level().isClientSide) {
|
||||||
this.setDeltaMovement(this.getDeltaMovement().multiply(0, 0, 0));
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0, 0, 0));
|
||||||
this.setNoGravity(true);
|
this.setNoGravity(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,34 @@
|
||||||
package net.mcreator.target.mobeffect;
|
package net.mcreator.target.mobeffect;
|
||||||
|
|
||||||
|
import net.mcreator.target.TargetMod;
|
||||||
import net.mcreator.target.init.TargetModDamageTypes;
|
import net.mcreator.target.init.TargetModDamageTypes;
|
||||||
|
import net.mcreator.target.init.TargetModMobEffects;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
|
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.util.RandomSource;
|
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.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.phys.Vec3;
|
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||||
|
import net.minecraftforge.event.entity.living.MobEffectEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
public class ShockMobEffect extends MobEffect {
|
public class ShockMobEffect extends MobEffect {
|
||||||
public ShockMobEffect() {
|
public ShockMobEffect() {
|
||||||
super(MobEffectCategory.BENEFICIAL, -256);
|
super(MobEffectCategory.BENEFICIAL, -256);
|
||||||
|
addAttributeModifier(Attributes.MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", -2.0F, AttributeModifier.Operation.MULTIPLY_TOTAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,9 +42,6 @@ public class ShockMobEffect extends MobEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
||||||
if (!entity.level().isClientSide()) {
|
|
||||||
entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10));
|
|
||||||
}
|
|
||||||
entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36));
|
entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -23, -36));
|
||||||
entity.xRotO = entity.getXRot();
|
entity.xRotO = entity.getXRot();
|
||||||
}
|
}
|
||||||
|
@ -41,4 +50,86 @@ public class ShockMobEffect extends MobEffect {
|
||||||
public boolean isDurationEffectTick(int duration, int amplifier) {
|
public boolean isDurationEffectTick(int duration, int amplifier) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onEffectAdded(MobEffectEvent.Added event) {
|
||||||
|
LivingEntity living = event.getEntity();
|
||||||
|
if (event.getEffectSource() instanceof LivingEntity source) {
|
||||||
|
MobEffectInstance instance = event.getEffectInstance();
|
||||||
|
|
||||||
|
if (!instance.getEffect().equals(TargetModMobEffects.SHOCK.get())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
living.getPersistentData().putBoolean("TargetShock", true);
|
||||||
|
living.getPersistentData().putInt("TargetShockAttacker", source.getId());
|
||||||
|
|
||||||
|
if (living.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||||
|
System.out.println(instance.getDuration());
|
||||||
|
if (instance.getDuration() % 10 == 0) {
|
||||||
|
living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(),
|
||||||
|
source), 5.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onEffectExpired(MobEffectEvent.Expired event) {
|
||||||
|
LivingEntity living = event.getEntity();
|
||||||
|
|
||||||
|
MobEffectInstance instance = event.getEffectInstance();
|
||||||
|
if (instance == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instance.getEffect().equals(TargetModMobEffects.SHOCK.get())) {
|
||||||
|
living.getPersistentData().remove("TargetShock");
|
||||||
|
living.getPersistentData().remove("TargetShockAttacker");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onEffectRemoved(MobEffectEvent.Remove event) {
|
||||||
|
LivingEntity living = event.getEntity();
|
||||||
|
|
||||||
|
MobEffectInstance instance = event.getEffectInstance();
|
||||||
|
if (instance == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instance.getEffect().equals(TargetModMobEffects.SHOCK.get())) {
|
||||||
|
living.getPersistentData().remove("TargetShock");
|
||||||
|
living.getPersistentData().remove("TargetShockAttacker");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onLivingTick(LivingEvent.LivingTickEvent event) {
|
||||||
|
LivingEntity living = event.getEntity();
|
||||||
|
|
||||||
|
if (living.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||||
|
MobEffectInstance instance = living.getEffect(TargetModMobEffects.SHOCK.get());
|
||||||
|
|
||||||
|
if (instance == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!living.getPersistentData().contains("TargetShockAttacker") ||
|
||||||
|
!living.getPersistentData().getBoolean("TargetShock")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity entity = living.level().getEntity(living.getPersistentData().getInt("TargetShockAttacker"));
|
||||||
|
|
||||||
|
if (instance.getDuration() % 20 == 0) {
|
||||||
|
living.hurt(TargetModDamageTypes.causeShockDamage(living.level().registryAccess(), entity), 5.0f);
|
||||||
|
|
||||||
|
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