实现爆炸后的粒子云

This commit is contained in:
17146 2025-02-23 00:11:19 +08:00
parent ad5a50e451
commit 55d29691c3

View file

@ -16,6 +16,7 @@ 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.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.AreaEffectCloud;
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;
@ -173,6 +174,7 @@ public class MortarShellEntity extends ThrowableItemProjectile implements GeoEnt
entity.hurt(ModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage); entity.hurt(ModDamageTypes.causeCannonFireDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
ProjectileTool.causeCustomExplode(this, this.damage, this.radius); ProjectileTool.causeCustomExplode(this, this.damage, this.radius);
this.createAreaCloud(this.level());
} }
this.discard(); this.discard();
} }
@ -189,6 +191,7 @@ public class MortarShellEntity extends ThrowableItemProjectile implements GeoEnt
if (!this.level().isClientSide() && this.level() instanceof ServerLevel) { if (!this.level().isClientSide() && this.level() instanceof ServerLevel) {
if (this.tickCount > 1) { if (this.tickCount > 1) {
ProjectileTool.causeCustomExplode(this, this.damage, this.radius); ProjectileTool.causeCustomExplode(this, this.damage, this.radius);
this.createAreaCloud(this.level());
} }
} }
this.discard(); this.discard();
@ -207,6 +210,7 @@ public class MortarShellEntity extends ThrowableItemProjectile implements GeoEnt
if (this.tickCount > this.life || this.isInWater()) { if (this.tickCount > this.life || this.isInWater()) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
ProjectileTool.causeCustomExplode(this, this.damage, this.radius); ProjectileTool.causeCustomExplode(this, this.damage, this.radius);
this.createAreaCloud(this.level());
} }
this.discard(); this.discard();
} }
@ -233,4 +237,17 @@ public class MortarShellEntity extends ThrowableItemProjectile implements GeoEnt
} }
super.onRemovedFromWorld(); super.onRemovedFromWorld();
} }
private void createAreaCloud(Level level) {
if (this.potion == Potions.EMPTY) return;
AreaEffectCloud cloud = new AreaEffectCloud(level, this.getX(), this.getY(), this.getZ());
cloud.setPotion(this.potion);
cloud.setDuration((int) this.damage);
cloud.setRadius(this.radius);
if (this.getOwner() instanceof LivingEntity living) {
cloud.setOwner(living);
}
level.addFreshEntity(cloud);
}
} }