From 6f437212ce5c050b6bdab57c24bd7823d5f808c9 Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Wed, 2 Jul 2025 13:09:50 +0200 Subject: [PATCH] Make C4 waterproof --- .../entity/projectile/C4Entity.java | 2 +- .../superbwarfare/tools/CustomExplosion.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) 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 bdd8142ee..6ba99fef5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/C4Entity.java @@ -425,7 +425,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, true).setDamageMultiplier(1); + pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true, true).setDamageMultiplier(1); explosion.explode(); EventHooks.onExplosionStart(level(), explosion); ParticleTool.spawnHugeExplosionParticles(level(), position()); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index 8c5c454b4..0cc9bd3c0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -21,6 +21,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.event.EventHooks; @@ -44,11 +45,12 @@ public class CustomExplosion extends Explosion { private final float damage; private int fireTime; private float damageMultiplier; + private boolean ignoreFluids; public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, @Nullable ExplosionDamageCalculator pDamageCalculator, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, - BlockInteraction pBlockInteraction, ParticleOptions smallParticle, ParticleOptions bigParticle, Holder sound) { + BlockInteraction pBlockInteraction, ParticleOptions smallParticle, ParticleOptions bigParticle, Holder sound, boolean ignoreFluids) { super(pLevel, pSource, source, null, pToBlowX, pToBlowY, pToBlowZ, pRadius, false, pBlockInteraction, smallParticle, bigParticle, sound); this.level = pLevel; @@ -60,21 +62,26 @@ public class CustomExplosion extends Explosion { this.y = pToBlowY; this.z = pToBlowZ; this.damage = damage; + this.ignoreFluids = ignoreFluids; } public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, @Nullable ExplosionDamageCalculator pDamageCalculator, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, - BlockInteraction pBlockInteraction) { - this(pLevel, pSource, source, pDamageCalculator, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE); + BlockInteraction pBlockInteraction, boolean ignoreFluids) { + this(pLevel, pSource, source, pDamageCalculator, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, ParticleTypes.EXPLOSION, ParticleTypes.EXPLOSION_EMITTER, SoundEvents.GENERIC_EXPLODE, ignoreFluids); } public CustomExplosion(Level pLevel, @Nullable Entity pSource, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, BlockInteraction pBlockInteraction) { - this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction); + this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, false); } 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, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, false, false); + } + + 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, boolean ignoreFluids) { + this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, ignoreFluids); if (pLevel instanceof ServerLevel && vanillaExplode) { pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, 0.4f * pRadius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE); @@ -84,13 +91,13 @@ public class CustomExplosion extends Explosion { } 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); + this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction, false); ShakeClientMessage.sendToNearbyPlayers(level, pToBlowX, pToBlowY, pToBlowZ, 4 * radius, 5 + 0.02 * damage, 0.75 * pRadius, 4 + 0.02 * damage); } public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius) { - this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, BlockInteraction.KEEP); + this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, BlockInteraction.KEEP, false); ShakeClientMessage.sendToNearbyPlayers(level, pToBlowX, pToBlowY, pToBlowZ, radius, 20 + 0.02 * damage, pRadius, 10 + 0.03 * damage); } @@ -138,7 +145,12 @@ public class CustomExplosion extends Explosion { break; } - Optional optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate); + Optional optional; + if (this.ignoreFluids) { + optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, Fluids.EMPTY.defaultFluidState()); + } else { + optional = this.damageCalculator.getBlockExplosionResistance(this, this.level, blockpos, blockstate, fluidstate); + } if (optional.isPresent()) { f -= (optional.get() + 1F) * 0.3F; }