优化防御塔索敌,调整爆炸

This commit is contained in:
Atsuishio 2025-05-02 16:30:09 +08:00 committed by Light_Quanta
parent 2b3c01b658
commit 1161f8426f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
28 changed files with 124 additions and 152 deletions

View file

@ -36,6 +36,7 @@ import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -153,7 +154,8 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity {
} }
@Override @Override
public InteractionResult interact(Player player, InteractionHand hand) { @ParametersAreNonnullByDefault
public @NotNull InteractionResult interact(Player player, InteractionHand hand) {
if (this.isOwnedBy(player) && player.isShiftKeyDown()) { if (this.isOwnedBy(player) && player.isShiftKeyDown()) {
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
this.discard(); this.discard();
@ -236,7 +238,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity {
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker, CustomExplosion explosion = new CustomExplosion(this.level(), attacker == null ? this : attacker,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 25.0f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker == null ? this : attacker, attacker == null ? this : attacker), 25.0f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
@ -248,7 +250,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity {
private void triggerExplode() { private void triggerExplode() {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeMineDamage(this.level().registryAccess(), this.getOwner()), 140f, ModDamageTypes.causeMineDamage(this.level().registryAccess(), this.getOwner()), 140f,
this.getX(), this.getEyeY(), this.getZ(), 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getEyeY(), this.getZ(), 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -413,7 +413,7 @@ public class C4Entity extends Entity implements GeoEntity, OwnableEntity {
CustomExplosion explosion = new CustomExplosion(level(), this, CustomExplosion explosion = new CustomExplosion(level(), this,
ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(level(), explosion); EventHooks.onExplosionStart(level(), explosion);
ParticleTool.spawnHugeExplosionParticles(level(), position()); ParticleTool.spawnHugeExplosionParticles(level(), position());

View file

@ -264,7 +264,7 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
vec.y(), vec.y(),
vec.z(), vec.z(),
radius, radius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1).setFireTime(fireTime); setDamageMultiplier(1).setFireTime(fireTime);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
@ -292,7 +292,7 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
result.getLocation().y + 5 * getDeltaMovement().normalize().y, result.getLocation().y + 5 * getDeltaMovement().normalize().y,
result.getLocation().z + 5 * getDeltaMovement().normalize().z, result.getLocation().z + 5 * getDeltaMovement().normalize().z,
radius, radius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1).setFireTime(fireTime); setDamageMultiplier(1).setFireTime(fireTime);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);

View file

@ -133,7 +133,7 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
public static void causeRocketExplode(ThrowableItemProjectile projectile, @Nullable DamageSource source, Entity target, float damage, float radius, float damageMultiplier) { public static void causeRocketExplode(ThrowableItemProjectile projectile, @Nullable DamageSource source, Entity target, float damage, float radius, float damageMultiplier) {
CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile, source, damage, CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile, source, damage,
projectile.getX(), projectile.getY(), projectile.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(damageMultiplier); projectile.getX(), projectile.getY(), projectile.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(damageMultiplier);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(projectile.level(), explosion); EventHooks.onExplosionStart(projectile.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -340,7 +340,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
this.getEyeY(), this.getEyeY(),
this.getZ(), this.getZ(),
explosion_radius, explosion_radius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier); setDamageMultiplier(this.monsterMultiplier);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);

View file

@ -235,7 +235,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
vec3.y, vec3.y,
vec3.z, vec3.z,
radius, radius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1.25f); setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);

View file

@ -7,26 +7,27 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
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.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
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;
import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BellBlock; import net.minecraft.world.level.block.BellBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -36,16 +37,11 @@ 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.List;
import java.util.stream.StreamSupport;
public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity { public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity {
private float damage = 40.0f; private float damage = 40.0f;
private float explosionDamage = 80f; private float explosionDamage = 80f;
private float explosionRadius = 5f; private float explosionRadius = 5f;
private boolean antiAir = false;
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public SmallCannonShellEntity(EntityType<? extends SmallCannonShellEntity> type, Level world) { public SmallCannonShellEntity(EntityType<? extends SmallCannonShellEntity> type, Level world) {
@ -53,12 +49,47 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
this.noCulling = true; this.noCulling = true;
} }
public SmallCannonShellEntity(LivingEntity entity, Level level, float damage, float explosionDamage, float explosionRadius, boolean antiAir) { public SmallCannonShellEntity(LivingEntity entity, Level level, float damage, float explosionDamage, float explosionRadius) {
super(ModEntities.SMALL_CANNON_SHELL.get(), entity, level); super(ModEntities.SMALL_CANNON_SHELL.get(), entity, level);
this.damage = damage; this.damage = damage;
this.explosionDamage = explosionDamage; this.explosionDamage = explosionDamage;
this.explosionRadius = explosionRadius; this.explosionRadius = explosionRadius;
this.antiAir = antiAir; }
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.getDirectEntity() instanceof Projectile) {
source.getDirectEntity().discard();
}
if (source.getEntity() instanceof Projectile) {
source.getEntity().discard();
}
this.discard();
causeExplode(position());
return super.hurt(source, amount);
}
@Override
public boolean isPickable() {
return !this.isRemoved();
} }
@Override @Override
@ -127,24 +158,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
ParticleTool.spawnSmallExplosionParticles(this.level(), vec3); ParticleTool.spawnSmallExplosionParticles(this.level(), vec3);
} }
private void causeAirExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).
setDamageMultiplier(1.25f);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
}
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
@ -158,10 +171,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
this.setDeltaMovement(0, 0, 0); this.setDeltaMovement(0, 0, 0);
} }
if (antiAir) {
findEntityOnPath();
}
if (this.tickCount > 200 || this.isInWater()) { if (this.tickCount > 200 || this.isInWater()) {
if (this.level() instanceof ServerLevel && !onGround()) { if (this.level() instanceof ServerLevel && !onGround()) {
causeExplode(position()); causeExplode(position());
@ -170,36 +179,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
} }
} }
public void findEntityOnPath() {
List<Entity> entities = this.level()
.getEntities(this,
this.getBoundingBox()
.expandTowards(this.getDeltaMovement())
.inflate(0.75)
);
for (Entity entity : entities) {
Entity target = StreamSupport.stream(EntityFindUtil.getEntities(level()).getAll().spliterator(), false)
.filter(e -> {
if (e == entity && e instanceof Projectile && !(e instanceof ProjectileEntity || e instanceof SmallCannonShellEntity)) {
return checkNoClip(e);
}
return false;
}).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null);
if (target != null) {
target.discard();
causeAirExplode(target.position());
}
}
}
public boolean checkNoClip(Entity target) {
return level().clip(new ClipContext(this.getEyePosition(), target.getEyePosition(),
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK;
}
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) { public void registerControllers(AnimatableManager.ControllerRegistrar data) {
} }

View file

@ -256,7 +256,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) { public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) {
CustomExplosion explosion = new CustomExplosion(level(), this, source, damage, CustomExplosion explosion = new CustomExplosion(level(), this, source, damage,
this.getX(), this.getY(), this.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); this.getX(), this.getY(), this.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(level(), explosion); EventHooks.onExplosionStart(level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -203,7 +203,7 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) { public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) {
CustomExplosion explosion = new CustomExplosion(level(), this, source, damage, CustomExplosion explosion = new CustomExplosion(level(), this, source, damage,
this.getX(), this.getY(), this.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); this.getX(), this.getY(), this.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(level(), explosion); EventHooks.onExplosionStart(level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -482,7 +482,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), 300.0f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, getAttacker()), 300.0f,
this.getX(), this.getY(), this.getZ(), 8f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 8f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -414,7 +414,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
if (passenger != null) { if (passenger != null) {
CustomExplosion explosion = new CustomExplosion(this.level(), passenger, CustomExplosion explosion = new CustomExplosion(this.level(), passenger,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, passenger), 300f, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, passenger), 300f,
pos.x, pos.y, pos.z, 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); pos.x, pos.y, pos.z, 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
@ -423,7 +423,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
Entity shooter = EntityFindUtil.findEntity(this.level(), this.entityData.get(SHOOTER_UUID)); Entity shooter = EntityFindUtil.findEntity(this.level(), this.entityData.get(SHOOTER_UUID));
CustomExplosion explosion = new CustomExplosion(this.level(), shooter, CustomExplosion explosion = new CustomExplosion(this.level(), shooter,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, shooter), 300f, ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, shooter), 300f,
pos.x, pos.y, pos.z, 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); pos.x, pos.y, pos.z, 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
@ -436,7 +436,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 600f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 600f,
this.getX(), this.getY(), this.getZ(), 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 15f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -607,7 +607,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -578,15 +578,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
CustomExplosion explosion = switch (mode) { CustomExplosion explosion = switch (mode) {
case 1 -> new CustomExplosion(this.level(), this, case 1 -> new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), mortarShell, attacker), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), mortarShell, attacker), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(),
this.getX(), this.getY(), this.getZ(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
case 2 -> new CustomExplosion(this.level(), this, case 2 -> new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), c4, attacker), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), c4, attacker), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
this.getX(), this.getY(), this.getZ(), ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
case 3 -> new CustomExplosion(this.level(), this, case 3 -> new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), rpg, attacker), ExplosionConfig.RPG_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), rpg, attacker), ExplosionConfig.RPG_EXPLOSION_DAMAGE.get(),
this.getX(), this.getY(), this.getZ(), ExplosionConfig.RPG_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), ExplosionConfig.RPG_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
default -> null; default -> null;
}; };

View file

@ -5,8 +5,6 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.TargetEntity; import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.AutoAimable; import com.atsuishio.superbwarfare.entity.vehicle.base.AutoAimable;
import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
@ -55,10 +53,8 @@ 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.Comparator;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.StreamSupport;
import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter;
@ -98,7 +94,6 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
.damage(VehicleConfig.HPJ11_DAMAGE.get().floatValue()) .damage(VehicleConfig.HPJ11_DAMAGE.get().floatValue())
.explosionDamage(VehicleConfig.HPJ11_EXPLOSION_DAMAGE.get().floatValue()) .explosionDamage(VehicleConfig.HPJ11_EXPLOSION_DAMAGE.get().floatValue())
.explosionRadius(VehicleConfig.HPJ11_EXPLOSION_RADIUS.get().floatValue()) .explosionRadius(VehicleConfig.HPJ11_EXPLOSION_RADIUS.get().floatValue())
.antiAir(true)
.icon(Mod.loc("textures/screens/vehicle_weapon/cannon_30mm.png")) .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_30mm.png"))
} }
}; };
@ -300,7 +295,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.entityData.set(TARGET_UUID, target.getVehicle().getStringUUID()); this.entityData.set(TARGET_UUID, target.getVehicle().getStringUUID());
} }
Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 4, target.getZ()).add(target.getDeltaMovement().scale((1 * (random.nextFloat() * 0.1f + 1) + 0.05 * target.distanceTo(this)))); Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 4, target.getZ()).add(target.getDeltaMovement().scale(1.0 + 0.04 * target.distanceTo(this)));
Vec3 targetVec = barrelRootPos.vectorTo(targetPos).normalize(); Vec3 targetVec = barrelRootPos.vectorTo(targetPos).normalize();
double d0 = targetVec.x; double d0 = targetVec.x;
@ -318,7 +313,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
if (target.distanceTo(this) <= 144 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 10) { if (target.distanceTo(this) <= 144 && VectorTool.calculateAngle(getViewVector(1), targetVec) < 10) {
if (checkNoClip(this, target, barrelRootPos) && entityData.get(AMMO) > 0) { if (checkNoClip(this, target, barrelRootPos) && entityData.get(AMMO) > 0) {
vehicleShoot(player, 0); vehicleShoot(player, 0);
findEntityOnPath(barrelRootPos, targetVec); findEntityOnPath(barrelRootPos, targetVec, 0.3);
} else { } else {
changeTargetTimer++; changeTargetTimer++;
} }
@ -355,25 +350,12 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
return !projectile.getOwner().isAlliedTo(this.getOwner()) || (projectile.getOwner().getTeam() != null && projectile.getOwner().getTeam().getName().equals("TDM")); return !projectile.getOwner().isAlliedTo(this.getOwner()) || (projectile.getOwner().getTeam() != null && projectile.getOwner().getTeam().getName().equals("TDM"));
} }
public void findEntityOnPath(Vec3 pos, Vec3 toVec) { public void findEntityOnPath(Vec3 pos, Vec3 toVec, double size) {
List<Entity> entities = this.level() for (Entity target : level().getEntitiesOfClass(Entity.class, new AABB(pos, pos).inflate(0.125).expandTowards(toVec.scale(30)), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(pos))).toList()) {
.getEntities(this, var condition = target instanceof Projectile && isThreateningEntity(this, target, size, pos) && smokeFilter(target);
new AABB(pos, pos) if (condition) {
.expandTowards(toVec.scale(30))
.inflate(0.125)
);
for (Entity entity : entities) {
Entity target = StreamSupport.stream(EntityFindUtil.getEntities(level()).getAll().spliterator(), false)
.filter(e -> {
if (e == entity && e instanceof Projectile && !(e instanceof ProjectileEntity || e instanceof SmallCannonShellEntity)) {
return checkNoClip(this, e, pos);
}
return false;
}).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null);
if (target != null) {
target.discard();
causeAirExplode(target.position()); causeAirExplode(target.position());
target.discard();
} }
} }
} }
@ -489,7 +471,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
Vector4f worldPosition = transformPosition(transform, 0f, 0.4f, 2.6875f); Vector4f worldPosition = transformPosition(transform, 0f, 0.4f, 2.6875f);
entityToSpawn.setPos(worldPosition.x, worldPosition.y, worldPosition.z); entityToSpawn.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
entityToSpawn.shoot(getLookAngle().x, getLookAngle().y, getLookAngle().z, 30, 1f); entityToSpawn.shoot(getLookAngle().x, getLookAngle().y + 0.001, getLookAngle().z, 30, 0.75f);
level().addFreshEntity(entityToSpawn); level().addFreshEntity(entityToSpawn);
if (!player.level().isClientSide) { if (!player.level().isClientSide) {

View file

@ -476,7 +476,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -256,7 +256,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 100f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 100f,
this.getX(), this.getY(), this.getZ(), 7f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 7f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -283,7 +283,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 120f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 120f,
this.getX(), this.getY(), this.getZ(), 6f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 6f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -654,7 +654,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -381,7 +381,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -930,7 +930,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f, ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), getAttacker(), getAttacker()), 80f,
this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); this.getX(), this.getY(), this.getZ(), 5f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -1,6 +1,6 @@
package com.atsuishio.superbwarfare.entity.vehicle.base; package com.atsuishio.superbwarfare.entity.vehicle.base;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
import com.atsuishio.superbwarfare.tools.VectorTool; import com.atsuishio.superbwarfare.tools.VectorTool;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
@ -8,11 +8,11 @@ import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import java.util.Comparator; import java.util.Comparator;
import java.util.stream.StreamSupport;
import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter;
@ -20,31 +20,28 @@ public interface AutoAimable {
// 防御类载具实体搜寻周围实体 // 防御类载具实体搜寻周围实体
default Entity seekNearLivingEntity(Entity attacker, Vec3 pos, double minAngle, double maxAngle, double minRange, double seekRange, double size) { default Entity seekNearLivingEntity(Entity attacker, Vec3 pos, double minAngle, double maxAngle, double minRange, double seekRange, double size) {
return StreamSupport.stream(EntityFindUtil.getEntities(attacker.level()).getAll().spliterator(), false) for (Entity target : attacker.level().getEntitiesOfClass(Entity.class, new AABB(pos, pos).inflate(seekRange), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(pos))).toList()) {
.filter(e -> { var condition = target.distanceToSqr(attacker) > minRange * minRange
// TODO 自定义目标列表 && target.distanceToSqr(attacker) <= seekRange * seekRange
if (e.distanceTo(attacker) > minRange && canAim(pos, target, minAngle, maxAngle)
&& e.distanceTo(attacker) <= seekRange && !(target instanceof Player player && (player.isSpectator() || player.isCreative()))
&& canAim(pos, e, minAngle, maxAngle) && ((target instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || isThreateningEntity(attacker, target, size, pos) || basicEnemyFilter(target))
&& !(e instanceof Player player && (player.isSpectator() || player.isCreative())) && smokeFilter(target);
&& ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || e == seekThreateningEntity(attacker, size, pos) || basicEnemyFilter(e)) if (condition) {
&& smokeFilter(e)) { return target;
return checkNoClip(attacker, e, pos);
} }
return false; }
}).min(Comparator.comparingDouble(e -> e.distanceTo(attacker))).orElse(null); return null;
} }
// 判断具有威胁的弹射物 // 判断具有威胁的弹射物
default Entity seekThreateningEntity(Entity attacker, double size, Vec3 pos) { default boolean isThreateningEntity(Entity attacker, Entity target, double size, Vec3 pos) {
return StreamSupport.stream(EntityFindUtil.getEntities(attacker.level()).getAll().spliterator(), false) if (target instanceof SmallCannonShellEntity) return false;
.filter(e -> { if (!target.onGround() && target instanceof Projectile projectile && (target.getBbWidth() >= size || target.getBbHeight() >= size) &&
if (!e.onGround() && e instanceof Projectile projectile && (e.getBbWidth() >= size || e.getBbHeight() >= size) && VectorTool.calculateAngle(target.getDeltaMovement().normalize(), target.position().vectorTo(attacker.position()).normalize()) < 30) {
VectorTool.calculateAngle(e.getDeltaMovement().normalize(), e.position().vectorTo(attacker.position()).normalize()) < 30) { return checkNoClip(attacker, target, pos) && basicEnemyProjectileFilter(projectile);
return checkNoClip(attacker, e, pos) && basicEnemyProjectileFilter(projectile);
} }
return false; return false;
}).min(Comparator.comparingDouble(e -> e.distanceTo(attacker))).orElse(null);
} }
// 判断载具和目标之间有无障碍物 // 判断载具和目标之间有无障碍物

View file

@ -6,7 +6,6 @@ import net.minecraft.world.entity.LivingEntity;
public class SmallCannonShellWeapon extends VehicleWeapon { public class SmallCannonShellWeapon extends VehicleWeapon {
public float damage = 40, explosionDamage = 80, explosionRadius = 5; public float damage = 40, explosionDamage = 80, explosionRadius = 5;
public boolean antiAir = false;
public SmallCannonShellWeapon damage(float damage) { public SmallCannonShellWeapon damage(float damage) {
this.damage = damage; this.damage = damage;
@ -23,12 +22,7 @@ public class SmallCannonShellWeapon extends VehicleWeapon {
return this; return this;
} }
public SmallCannonShellWeapon antiAir(boolean antiAir) {
this.antiAir = antiAir;
return this;
}
public SmallCannonShellEntity create(LivingEntity entity) { public SmallCannonShellEntity create(LivingEntity entity) {
return new SmallCannonShellEntity(entity, entity.level(), damage, explosionDamage, explosionRadius, antiAir); return new SmallCannonShellEntity(entity, entity.level(), damage, explosionDamage, explosionRadius);
} }
} }

View file

@ -53,7 +53,7 @@ public class ModEntities {
// Fast Projectiles // Fast Projectiles
public static final DeferredHolder<EntityType<?>, EntityType<SmallCannonShellEntity>> SMALL_CANNON_SHELL = register("small_cannon_shell", public static final DeferredHolder<EntityType<?>, EntityType<SmallCannonShellEntity>> SMALL_CANNON_SHELL = register("small_cannon_shell",
EntityType.Builder.<SmallCannonShellEntity>of(SmallCannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.25f, 0.25f)); EntityType.Builder.<SmallCannonShellEntity>of(SmallCannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.75f, 0.75f));
public static final DeferredHolder<EntityType<?>, EntityType<RpgRocketEntity>> RPG_ROCKET = register("rpg_rocket", public static final DeferredHolder<EntityType<?>, EntityType<RpgRocketEntity>> RPG_ROCKET = register("rpg_rocket",
EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f)); EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
public static final DeferredHolder<EntityType<?>, EntityType<MortarShellEntity>> MORTAR_SHELL = register("mortar_shell", public static final DeferredHolder<EntityType<?>, EntityType<MortarShellEntity>> MORTAR_SHELL = register("mortar_shell",

View file

@ -80,7 +80,7 @@ public class HandGrenade extends Item implements ProjectileItem {
CustomExplosion explosion = new CustomExplosion(pLevel, null, CustomExplosion explosion = new CustomExplosion(pLevel, null,
ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), handGrenade, pLivingEntity), ExplosionConfig.M67_GRENADE_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), handGrenade, pLivingEntity), ExplosionConfig.M67_GRENADE_EXPLOSION_DAMAGE.get(),
pLivingEntity.getX(), pLivingEntity.getY(), pLivingEntity.getZ(), ExplosionConfig.M67_GRENADE_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); pLivingEntity.getX(), pLivingEntity.getY(), pLivingEntity.getZ(), ExplosionConfig.M67_GRENADE_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(pLevel, explosion); EventHooks.onExplosionStart(pLevel, explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -79,7 +79,7 @@ public class RgoGrenade extends Item implements ProjectileItem {
RgoGrenadeEntity rgoGrenade = new RgoGrenadeEntity(pLivingEntity, pLevel, 100); RgoGrenadeEntity rgoGrenade = new RgoGrenadeEntity(pLivingEntity, pLevel, 100);
CustomExplosion explosion = new CustomExplosion(pLevel, null, CustomExplosion explosion = new CustomExplosion(pLevel, null,
ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), rgoGrenade, pLivingEntity), ExplosionConfig.RGO_GRENADE_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), rgoGrenade, pLivingEntity), ExplosionConfig.RGO_GRENADE_EXPLOSION_DAMAGE.get(),
pLivingEntity.getX(), pLivingEntity.getY(), pLivingEntity.getZ(), ExplosionConfig.RPG_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); pLivingEntity.getX(), pLivingEntity.getY(), pLivingEntity.getZ(), ExplosionConfig.RPG_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(pLevel, explosion); EventHooks.onExplosionStart(pLevel, explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -64,12 +64,11 @@ public record LungeMineAttackMessage(int msgType, UUID uuid, Vec3 hitPos) implem
} }
CustomExplosion explosion = new CustomExplosion(player.level(), null, CustomExplosion explosion = new CustomExplosion(player.level(), null,
ModDamageTypes.causeProjectileBoomDamage(player.level().registryAccess(), player, player), 60, ModDamageTypes.causeProjectileBoomDamage(player.level().registryAccess(), player, player), 60,
message.hitPos.x, message.hitPos.y, message.hitPos.z, 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); message.hitPos.x, message.hitPos.y, message.hitPos.z, 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(player.level(), explosion); EventHooks.onExplosionStart(player.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(player.level(), message.hitPos); ParticleTool.spawnMediumExplosionParticles(player.level(), message.hitPos);
} }
player.swing(InteractionHand.MAIN_HAND); player.swing(InteractionHand.MAIN_HAND);
} }
@ -78,7 +77,7 @@ public record LungeMineAttackMessage(int msgType, UUID uuid, Vec3 hitPos) implem
public static void causeLungeMineExplode(Level pLevel, Entity entity, Entity pLivingEntity) { public static void causeLungeMineExplode(Level pLevel, Entity entity, Entity pLivingEntity) {
CustomExplosion explosion = new CustomExplosion(pLevel, pLivingEntity, CustomExplosion explosion = new CustomExplosion(pLevel, pLivingEntity,
ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), pLivingEntity, entity), 60, ModDamageTypes.causeProjectileBoomDamage(pLevel.registryAccess(), pLivingEntity, entity), 60,
pLivingEntity.getX(), pLivingEntity.getEyeY(), pLivingEntity.getZ(), 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1.25f); pLivingEntity.getX(), pLivingEntity.getEyeY(), pLivingEntity.getZ(), 4f, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(pLevel, explosion); EventHooks.onExplosionStart(pLevel, explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);

View file

@ -76,14 +76,24 @@ public class CustomExplosion extends Explosion {
this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction); this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction);
} }
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, BlockInteraction pBlockInteraction) { public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, Explosion.BlockInteraction pBlockInteraction, boolean vanillaExplode) {
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction); this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction);
final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ); final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ);
if (pLevel instanceof ServerLevel) { if (pLevel instanceof ServerLevel && vanillaExplode) {
pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, 0.5f * pRadius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE); pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, 0.5f * pRadius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE);
} }
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4 * radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
if (target instanceof ServerPlayer serverPlayer) {
PacketDistributor.sendToPlayer(serverPlayer, new ShakeClientMessage(20 + 0.02 * damage, 3 * pRadius, 50 + 0.05 * damage, pToBlowX, pToBlowY, pToBlowZ));
}
}
}
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, Explosion.BlockInteraction pBlockInteraction) {
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction);
final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ);
for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4 * radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4 * radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) {
if (target instanceof ServerPlayer serverPlayer) { if (target instanceof ServerPlayer serverPlayer) {
PacketDistributor.sendToPlayer(serverPlayer, new ShakeClientMessage(5 + 0.02 * damage, 0.75 * pRadius, 4 + 0.02 * damage, pToBlowX, pToBlowY, pToBlowZ)); PacketDistributor.sendToPlayer(serverPlayer, new ShakeClientMessage(5 + 0.02 * damage, 0.75 * pRadius, 4 + 0.02 * damage, pToBlowX, pToBlowY, pToBlowZ));

View file

@ -2,10 +2,13 @@ package com.atsuishio.superbwarfare.tools;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile; import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -30,6 +33,12 @@ public class ProjectileTool {
ParticleTool.spawnHugeExplosionParticles(projectile.level(), projectile.position().add(projectile.getDeltaMovement().scale(0.5))); ParticleTool.spawnHugeExplosionParticles(projectile.level(), projectile.position().add(projectile.getDeltaMovement().scale(0.5)));
} }
Vec3 pos = projectile.position().add(projectile.getDeltaMovement().scale(0.5));
if (projectile.level() instanceof ServerLevel) {
projectile.level().explode(source == null ? null : source.getEntity(), pos.x, pos.y, pos.z, 0.5f * radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE);
}
projectile.discard(); projectile.discard();
} }