From 2f2052e33114822aea4126ab5ce54ddc57156fe2 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Sun, 12 Jan 2025 04:13:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=A5=9E=E7=A7=98=E7=9A=84?= =?UTF-8?q?=E5=8A=9E=E6=B3=95=E8=AE=A9=E8=BD=BD=E5=85=B7=E6=8A=B5=E6=B6=88?= =?UTF-8?q?=E5=A4=A7=E9=83=A8=E5=88=86=E7=88=86=E7=82=B8=E5=87=BB=E9=80=80?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=BF=AB=E8=89=87=E5=90=83=E6=B0=B4?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Ah6Entity.java | 10 +++++++++ .../entity/vehicle/SpeedboatEntity.java | 12 +++++++++- .../entity/vehicle/VehicleEntity.java | 8 +++++++ .../entity/vehicle/WheelChairEntity.java | 10 +++++++++ .../superbwarfare/tools/CustomExplosion.java | 22 +++++++++++++++++++ .../superbwarfare/tools/ProjectileTool.java | 2 +- 6 files changed, 62 insertions(+), 2 deletions(-) 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 bf4c63a5b..b685dbecf 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -611,6 +611,16 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli return super.getDismountLocationForPassenger(passenger); } + @Override + public float ignoreExplosionHorizontalKnockBack() { + return -0.5f; + } + + @Override + public float ignoreExplosionVerticalKnockBack() { + return -0.9f; + } + @Override public boolean isDriver(Player player) { return player == this.getFirstPassenger(); 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 24a22641e..4b20757a8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -181,7 +181,7 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity, } double fluidFloat; - fluidFloat = -0.06 + 0.12 * getSubmergedHeight(this); + fluidFloat = 0.12 * getSubmergedHeight(this); this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); if (this.onGround()) { @@ -452,6 +452,16 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity, return this.cache; } + @Override + public float ignoreExplosionHorizontalKnockBack() { + return -0.5f; + } + + @Override + public float ignoreExplosionVerticalKnockBack() { + return -0.9f; + } + @Override public int getMaxPassengers() { return 5; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index fa85a35cf..8c8ff8350 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -310,6 +310,14 @@ public class VehicleEntity extends Entity { public void travel() { } + public float ignoreExplosionHorizontalKnockBack() { + return -1f; + } + + public float ignoreExplosionVerticalKnockBack() { + return -1f; + } + // From Immersive_Aircraft public Matrix4f getVehicleTransform() { Matrix4f transform = new Matrix4f(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java index bba57df92..58feb5294 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java @@ -277,6 +277,16 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity { } } + @Override + public float ignoreExplosionHorizontalKnockBack() { + return -0.2f; + } + + @Override + public float ignoreExplosionVerticalKnockBack() { + return -0.3f; + } + @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index e57efb9dc..d04bffc35 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.tools; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; +import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.google.common.collect.Sets; import net.minecraft.core.BlockPos; @@ -11,8 +12,10 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.PrimedTnt; import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.item.enchantment.ProtectionEnchantment; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.ExplosionDamageCalculator; import net.minecraft.world.level.Level; @@ -167,6 +170,9 @@ public class CustomExplosion extends Explosion { double zDistance = entity.getZ() - this.z; double distance = Math.sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance); if (distance != 0.0D) { + xDistance /= distance; + yDistance /= distance; + zDistance /= distance; double seenPercent = Mth.clamp(getSeenPercent(position, entity), 0.01 * ExplosionConfig.EXPLOSION_PENETRATION_RATIO.get(), Double.POSITIVE_INFINITY); double damagePercent = (1.0D - distanceRate) * seenPercent; @@ -180,6 +186,22 @@ public class CustomExplosion extends Explosion { if (fireTime > 0) { entity.setSecondsOnFire(fireTime); } + + double d11; + if (entity instanceof LivingEntity livingentity) { + d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener(livingentity, damagePercent); + } else { + d11 = damagePercent; + } + + xDistance *= d11; + yDistance *= d11; + zDistance *= d11; + + if (entity instanceof VehicleEntity vehicle) { + Vec3 knockbackVec = new Vec3(vehicle.ignoreExplosionHorizontalKnockBack() * xDistance, vehicle.ignoreExplosionVerticalKnockBack() * yDistance, vehicle.ignoreExplosionHorizontalKnockBack() * zDistance); + vehicle.setDeltaMovement(vehicle.getDeltaMovement().add(knockbackVec)); + } } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java index 87032bdef..92eb1a973 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/ProjectileTool.java @@ -17,7 +17,7 @@ public class ProjectileTool { explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion); explosion.finalizeExplosion(false); - ParticleTool.spawnMediumExplosionParticles(projectile.level(), target.position()); + ParticleTool.spawnMediumExplosionParticles(projectile.level(), projectile.position()); projectile.discard(); }