修复近防炮炮弹拦截bug
This commit is contained in:
parent
c86dc2341a
commit
1742e1b706
1 changed files with 9 additions and 6 deletions
|
@ -36,6 +36,9 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||||
import software.bernie.geckolib.animation.AnimatableManager;
|
import software.bernie.geckolib.animation.AnimatableManager;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
|
public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
|
||||||
private float damage = 40.0f;
|
private float damage = 40.0f;
|
||||||
private float explosionDamage = 80f;
|
private float explosionDamage = 80f;
|
||||||
|
@ -194,15 +197,15 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
|
||||||
|
|
||||||
public void crushProjectile(Vec3 velocity) {
|
public void crushProjectile(Vec3 velocity) {
|
||||||
if (this.level() instanceof ServerLevel) {
|
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<Projectile> target = level().getEntities(
|
||||||
EntityTypeTest.forClass(Projectile.class), frontBox, entity -> entity != this).stream()
|
EntityTypeTest.forClass(Projectile.class), frontBox, entity -> entity != this).stream()
|
||||||
.filter(entity -> !(entity instanceof SmallCannonShellEntity) && (entity.getBbWidth() >= 0.3 || entity.getBbHeight() >= 0.3))
|
.filter(entity -> !(entity instanceof SmallCannonShellEntity) && (entity.getBbWidth() >= 0.3 || entity.getBbHeight() >= 0.3))
|
||||||
.toList();
|
.min(Comparator.comparingDouble(e -> e.position().distanceTo(position())));
|
||||||
for (var entity : entities) {
|
if (target.isPresent()) {
|
||||||
causeExplode(entity.position(), false);
|
causeExplode(target.get().position(), false);
|
||||||
entity.discard();
|
target.get().discard();
|
||||||
this.discard();
|
this.discard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue