From 1742e1b70671cba239e4c99768f45914a0baef08 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Thu, 10 Jul 2025 13:25:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=91=E9=98=B2=E7=82=AE?= =?UTF-8?q?=E7=82=AE=E5=BC=B9=E6=8B=A6=E6=88=AAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/SmallCannonShellEntity.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java index e7273f00e..e3a0e72e7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java @@ -36,6 +36,9 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; +import java.util.Comparator; +import java.util.Optional; + public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { private float damage = 40.0f; private float explosionDamage = 80f; @@ -194,15 +197,15 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G public void crushProjectile(Vec3 velocity) { if (this.level() instanceof ServerLevel) { - var frontBox = getBoundingBox().inflate(3).expandTowards(velocity); + var frontBox = getBoundingBox().inflate(0.5).expandTowards(velocity); - var entities = level().getEntities( + Optional target = level().getEntities( EntityTypeTest.forClass(Projectile.class), frontBox, entity -> entity != this).stream() .filter(entity -> !(entity instanceof SmallCannonShellEntity) && (entity.getBbWidth() >= 0.3 || entity.getBbHeight() >= 0.3)) - .toList(); - for (var entity : entities) { - causeExplode(entity.position(), false); - entity.discard(); + .min(Comparator.comparingDouble(e -> e.position().distanceTo(position()))); + if (target.isPresent()) { + causeExplode(target.get().position(), false); + target.get().discard(); this.discard(); } }