diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java index fdde71be0..c08779732 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java @@ -36,6 +36,7 @@ import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.Comparator; import java.util.Optional; import java.util.UUID; @@ -153,7 +154,8 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity { } @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.level().isClientSide()) { 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)); 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, - 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); @@ -248,7 +250,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity { private void triggerExplode() { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java index 440f81052..151b7165e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java @@ -413,7 +413,7 @@ public class C4Entity extends Entity implements GeoEntity, OwnableEntity { CustomExplosion explosion = new CustomExplosion(level(), this, 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(); EventHooks.onExplosionStart(level(), explosion); ParticleTool.spawnHugeExplosionParticles(level(), position()); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java index 4b861137d..98b5b4bea 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java @@ -264,7 +264,7 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt vec.y(), vec.z(), 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); explosion.explode(); 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().z + 5 * getDeltaMovement().normalize().z, 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); explosion.explode(); EventHooks.onExplosionStart(this.level(), explosion); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java index 549588672..7720ebb1d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HeliRocketEntity.java @@ -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) { 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(); EventHooks.onExplosionStart(projectile.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java index 993ea83be..b5d1efa1d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/JavelinMissileEntity.java @@ -340,7 +340,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo this.getEyeY(), this.getZ(), 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); explosion.explode(); EventHooks.onExplosionStart(this.level(), explosion); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java index 663108fae..03f4da3c3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java @@ -235,7 +235,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt vec3.y, vec3.z, 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); explosion.explode(); EventHooks.onExplosionStart(this.level(), explosion); 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 63339e5de..042239fb8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SmallCannonShellEntity.java @@ -7,26 +7,27 @@ import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; 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.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BellBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.event.EventHooks; 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.util.GeckoLibUtil; -import java.util.Comparator; -import java.util.List; -import java.util.stream.StreamSupport; - public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity { private float damage = 40.0f; private float explosionDamage = 80f; private float explosionRadius = 5f; - private boolean antiAir = false; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public SmallCannonShellEntity(EntityType type, Level world) { @@ -53,12 +49,47 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G 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); this.damage = damage; this.explosionDamage = explosionDamage; 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 @@ -127,24 +158,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G 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 public void tick() { super.tick(); @@ -158,10 +171,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G this.setDeltaMovement(0, 0, 0); } - if (antiAir) { - findEntityOnPath(); - } - if (this.tickCount > 200 || this.isInWater()) { if (this.level() instanceof ServerLevel && !onGround()) { causeExplode(position()); @@ -170,36 +179,6 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G } } - public void findEntityOnPath() { - List 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 public void registerControllers(AnimatableManager.ControllerRegistrar data) { } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java index 52662b9b2..69b8e31d9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java @@ -256,7 +256,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) { 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(); EventHooks.onExplosionStart(level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java index 0bce267a7..dfb2ec359 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/WgMissileEntity.java @@ -203,7 +203,7 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) { 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(); EventHooks.onExplosionStart(level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index 863af21e1..9ca270a01 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -482,7 +482,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index a9511a906..d5a7c8c21 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -414,7 +414,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, if (passenger != null) { CustomExplosion explosion = new CustomExplosion(this.level(), passenger, 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(); EventHooks.onExplosionStart(this.level(), explosion); 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)); CustomExplosion explosion = new CustomExplosion(this.level(), shooter, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); @@ -436,7 +436,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 42162d55e..772d6983e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -607,7 +607,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java index 1023e9623..8bcb9dcdc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -578,15 +578,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { CustomExplosion explosion = switch (mode) { case 1 -> new CustomExplosion(this.level(), this, 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, 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, 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; }; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java index fcd7c8b83..634ad2bdf 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java @@ -5,8 +5,6 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.TargetEntity; 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.CannonEntity; 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 java.util.Comparator; -import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.stream.StreamSupport; 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()) .explosionDamage(VehicleConfig.HPJ11_EXPLOSION_DAMAGE.get().floatValue()) .explosionRadius(VehicleConfig.HPJ11_EXPLOSION_RADIUS.get().floatValue()) - .antiAir(true) .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()); } - 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(); 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 (checkNoClip(this, target, barrelRootPos) && entityData.get(AMMO) > 0) { vehicleShoot(player, 0); - findEntityOnPath(barrelRootPos, targetVec); + findEntityOnPath(barrelRootPos, targetVec, 0.3); } else { 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")); } - public void findEntityOnPath(Vec3 pos, Vec3 toVec) { - List entities = this.level() - .getEntities(this, - new AABB(pos, pos) - .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(); + public void findEntityOnPath(Vec3 pos, Vec3 toVec, double size) { + 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()) { + var condition = target instanceof Projectile && isThreateningEntity(this, target, size, pos) && smokeFilter(target); + if (condition) { 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); 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); if (!player.level().isClientSide) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index ffb2c278f..32644b1ab 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -476,7 +476,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 6973e263f..1addc3fa0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -256,7 +256,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index f2fe3d7c2..df4afcd4b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -283,7 +283,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java index 1e705d55a..92b478b68 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java @@ -654,7 +654,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index c9a17b9c2..b7c885a4e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -381,7 +381,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index a2a81b2d3..f59d01ef9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -930,7 +930,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti if (level() instanceof ServerLevel) { CustomExplosion explosion = new CustomExplosion(this.level(), this, 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(); EventHooks.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/AutoAimable.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/AutoAimable.java index 3f4b24d0c..b53ac947b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/AutoAimable.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/AutoAimable.java @@ -1,6 +1,6 @@ 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 net.minecraft.world.entity.Entity; 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.projectile.Projectile; import net.minecraft.world.level.ClipContext; +import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import java.util.Comparator; -import java.util.stream.StreamSupport; 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) { - return StreamSupport.stream(EntityFindUtil.getEntities(attacker.level()).getAll().spliterator(), false) - .filter(e -> { - // TODO 自定义目标列表 - if (e.distanceTo(attacker) > minRange - && e.distanceTo(attacker) <= seekRange - && canAim(pos, e, minAngle, maxAngle) - && !(e instanceof Player player && (player.isSpectator() || player.isCreative())) - && ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || e == seekThreateningEntity(attacker, size, pos) || basicEnemyFilter(e)) - && smokeFilter(e)) { - return checkNoClip(attacker, e, pos); - } - return false; - }).min(Comparator.comparingDouble(e -> e.distanceTo(attacker))).orElse(null); + 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()) { + var condition = target.distanceToSqr(attacker) > minRange * minRange + && target.distanceToSqr(attacker) <= seekRange * seekRange + && canAim(pos, target, minAngle, maxAngle) + && !(target instanceof Player player && (player.isSpectator() || player.isCreative())) + && ((target instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || isThreateningEntity(attacker, target, size, pos) || basicEnemyFilter(target)) + && smokeFilter(target); + if (condition) { + return target; + } + } + return null; } // 判断具有威胁的弹射物 - default Entity seekThreateningEntity(Entity attacker, double size, Vec3 pos) { - return StreamSupport.stream(EntityFindUtil.getEntities(attacker.level()).getAll().spliterator(), false) - .filter(e -> { - if (!e.onGround() && e instanceof Projectile projectile && (e.getBbWidth() >= size || e.getBbHeight() >= size) && - VectorTool.calculateAngle(e.getDeltaMovement().normalize(), e.position().vectorTo(attacker.position()).normalize()) < 30) { - return checkNoClip(attacker, e, pos) && basicEnemyProjectileFilter(projectile); - } - return false; - }).min(Comparator.comparingDouble(e -> e.distanceTo(attacker))).orElse(null); + default boolean isThreateningEntity(Entity attacker, Entity target, double size, Vec3 pos) { + if (target instanceof SmallCannonShellEntity) return false; + if (!target.onGround() && target instanceof Projectile projectile && (target.getBbWidth() >= size || target.getBbHeight() >= size) && + VectorTool.calculateAngle(target.getDeltaMovement().normalize(), target.position().vectorTo(attacker.position()).normalize()) < 30) { + return checkNoClip(attacker, target, pos) && basicEnemyProjectileFilter(projectile); + } + return false; } // 判断载具和目标之间有无障碍物 diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/SmallCannonShellWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/SmallCannonShellWeapon.java index e1c2fc326..fa90f3ae0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/SmallCannonShellWeapon.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/SmallCannonShellWeapon.java @@ -6,7 +6,6 @@ import net.minecraft.world.entity.LivingEntity; public class SmallCannonShellWeapon extends VehicleWeapon { public float damage = 40, explosionDamage = 80, explosionRadius = 5; - public boolean antiAir = false; public SmallCannonShellWeapon damage(float damage) { this.damage = damage; @@ -23,12 +22,7 @@ public class SmallCannonShellWeapon extends VehicleWeapon { return this; } - public SmallCannonShellWeapon antiAir(boolean antiAir) { - this.antiAir = antiAir; - return this; - } - public SmallCannonShellEntity create(LivingEntity entity) { - return new SmallCannonShellEntity(entity, entity.level(), damage, explosionDamage, explosionRadius, antiAir); + return new SmallCannonShellEntity(entity, entity.level(), damage, explosionDamage, explosionRadius); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModEntities.java b/src/main/java/com/atsuishio/superbwarfare/init/ModEntities.java index 94eeff356..de8ccff4d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModEntities.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModEntities.java @@ -53,7 +53,7 @@ public class ModEntities { // Fast Projectiles public static final DeferredHolder, EntityType> SMALL_CANNON_SHELL = register("small_cannon_shell", - EntityType.Builder.of(SmallCannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.25f, 0.25f)); + EntityType.Builder.of(SmallCannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.75f, 0.75f)); public static final DeferredHolder, EntityType> RPG_ROCKET = register("rpg_rocket", EntityType.Builder.of(RpgRocketEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(false).noSave().setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f)); public static final DeferredHolder, EntityType> MORTAR_SHELL = register("mortar_shell", diff --git a/src/main/java/com/atsuishio/superbwarfare/item/HandGrenade.java b/src/main/java/com/atsuishio/superbwarfare/item/HandGrenade.java index 8f765a38d..9a8e7aa87 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/HandGrenade.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/HandGrenade.java @@ -80,7 +80,7 @@ public class HandGrenade extends Item implements ProjectileItem { CustomExplosion explosion = new CustomExplosion(pLevel, null, 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(); EventHooks.onExplosionStart(pLevel, explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/RgoGrenade.java b/src/main/java/com/atsuishio/superbwarfare/item/RgoGrenade.java index 40fbc63f8..8e1cf810d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/RgoGrenade.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/RgoGrenade.java @@ -79,7 +79,7 @@ public class RgoGrenade extends Item implements ProjectileItem { RgoGrenadeEntity rgoGrenade = new RgoGrenadeEntity(pLivingEntity, pLevel, 100); CustomExplosion explosion = new CustomExplosion(pLevel, null, 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(); EventHooks.onExplosionStart(pLevel, explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/LungeMineAttackMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/LungeMineAttackMessage.java index 8a1c761db..12a8f7f01 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/LungeMineAttackMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/LungeMineAttackMessage.java @@ -64,12 +64,11 @@ public record LungeMineAttackMessage(int msgType, UUID uuid, Vec3 hitPos) implem } CustomExplosion explosion = new CustomExplosion(player.level(), null, 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(); EventHooks.onExplosionStart(player.level(), explosion); explosion.finalizeExplosion(false); ParticleTool.spawnMediumExplosionParticles(player.level(), message.hitPos); - } 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) { CustomExplosion explosion = new CustomExplosion(pLevel, pLivingEntity, 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(); EventHooks.onExplosionStart(pLevel, explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index 64d39668c..bfcb1095a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -76,14 +76,24 @@ public class CustomExplosion extends Explosion { 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); 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); } + 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()) { if (target instanceof ServerPlayer serverPlayer) { PacketDistributor.sendToPlayer(serverPlayer, new ShakeClientMessage(5 + 0.02 * damage, 0.75 * pRadius, 4 + 0.02 * damage, pToBlowX, pToBlowY, pToBlowZ)); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java index 4f48659d4..6e663c7ef 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java @@ -2,10 +2,13 @@ package com.atsuishio.superbwarfare.tools; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.init.ModDamageTypes; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; 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 javax.annotation.Nullable; @@ -30,6 +33,12 @@ public class ProjectileTool { 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(); }