From 206eff0e50d3b87940fb1a6065b4ac7dacea8fec Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sat, 24 May 2025 17:16:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=BD=BD=E5=85=B7=E5=BC=80=E7=81=AB=E9=9F=B3=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/atsuishio/superbwarfare/Mod.java | 6 ++++ .../client/sound/ClientSoundHandler.java | 14 ---------- .../sound/VehicleFireSoundInstance.java | 7 ++++- .../entity/vehicle/A10Entity.java | 17 ++++++++++- .../entity/vehicle/Hpj11Entity.java | 28 +++++++++++++------ 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/Mod.java b/src/main/java/com/atsuishio/superbwarfare/Mod.java index a9b9af560..25856d560 100644 --- a/src/main/java/com/atsuishio/superbwarfare/Mod.java +++ b/src/main/java/com/atsuishio/superbwarfare/Mod.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare; import com.atsuishio.superbwarfare.api.event.RegisterContainersEvent; import com.atsuishio.superbwarfare.client.MouseMovementHandler; import com.atsuishio.superbwarfare.client.renderer.molang.MolangVariable; +import com.atsuishio.superbwarfare.client.sound.VehicleFireSoundInstance; import com.atsuishio.superbwarfare.client.sound.VehicleSoundInstance; import com.atsuishio.superbwarfare.compat.CompatHolder; import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper; @@ -10,6 +11,8 @@ import com.atsuishio.superbwarfare.component.ModDataComponents; import com.atsuishio.superbwarfare.config.ClientConfig; import com.atsuishio.superbwarfare.config.CommonConfig; import com.atsuishio.superbwarfare.config.ServerConfig; +import com.atsuishio.superbwarfare.entity.vehicle.A10Entity; +import com.atsuishio.superbwarfare.entity.vehicle.Hpj11Entity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.NetworkRegistry; @@ -129,6 +132,9 @@ public class Mod { MobileVehicleEntity.trackSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(vehicle)); MobileVehicleEntity.engineSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.EngineSound(vehicle)); MobileVehicleEntity.swimSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.SwimSound(vehicle)); + + A10Entity.fireSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.A10FireSound(vehicle)); + Hpj11Entity.fireSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.HPJ11CloseFireSound(vehicle)); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/sound/ClientSoundHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/sound/ClientSoundHandler.java index a69ddcb48..01aaab9cd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/sound/ClientSoundHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/sound/ClientSoundHandler.java @@ -13,20 +13,6 @@ public class ClientSoundHandler { if (entity instanceof LoudlyEntity) { Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(entity)); Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(entity)); - } else { -// Mod.queueClientWork(60, () -> { -// if (entity instanceof MobileVehicleEntity mobileVehicle) { -// if (mobileVehicle instanceof TrackEntity) { -// Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle)); -// } -// if (mobileVehicle instanceof A10Entity) { -// Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.A10FireSound(mobileVehicle)); -// } -// if (mobileVehicle instanceof Hpj11Entity) { -// Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.HPJ11CloseFireSound(mobileVehicle)); -// } -// } -// }); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/sound/VehicleFireSoundInstance.java b/src/main/java/com/atsuishio/superbwarfare/client/sound/VehicleFireSoundInstance.java index f5d8fb4d5..e3e80013d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/sound/VehicleFireSoundInstance.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/sound/VehicleFireSoundInstance.java @@ -62,13 +62,17 @@ public abstract class VehicleFireSoundInstance extends AbstractTickableSoundInst } public static class A10FireSound extends VehicleSoundInstance { + public A10FireSound(MobileVehicleEntity mobileVehicle) { super(ModSounds.A_10_FIRE.get(), Minecraft.getInstance(), mobileVehicle); } @Override protected boolean canPlay(MobileVehicleEntity mobileVehicle) { - return true; + if (mobileVehicle instanceof A10Entity a10Entity) { + return a10Entity.isFiring(); + } + return false; } @Override @@ -89,6 +93,7 @@ public abstract class VehicleFireSoundInstance extends AbstractTickableSoundInst } public static class HPJ11CloseFireSound extends VehicleSoundInstance { + public HPJ11CloseFireSound(MobileVehicleEntity mobileVehicle) { super(ModSounds.HPJ_11_FIRE_3P.get(), Minecraft.getInstance(), mobileVehicle); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java index 7d3e4b763..ac60aebc4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java @@ -59,11 +59,15 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; import java.util.List; +import java.util.function.Consumer; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity, WeaponVehicleEntity, AircraftEntity { + public static Consumer fireSound = vehicle -> { + }; + public static final EntityDataAccessor LOADED_ROCKET = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor LOADED_BOMB = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor LOADED_MISSILE = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); @@ -80,6 +84,8 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity public int lockTime; public boolean locked; + private boolean wasFiring = false; + public A10Entity(EntityType type, Level world) { super(type, world); } @@ -189,7 +195,12 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity @Override public void baseTick() { - lockingTargetO = getTargetUuid(); + if (!this.wasFiring && this.isFiring() && this.level().isClientSide()) { + fireSound.accept(this); + } + this.wasFiring = this.isFiring(); + + this.lockingTargetO = getTargetUuid(); super.baseTick(); float f = (float) Mth.clamp(Math.max((onGround() ? 0.819f : 0.82f) - 0.0035 * getDeltaMovement().length(), 0.5) + 0.001f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90, 0.01, 0.99); @@ -956,6 +967,10 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity return 0; } + public boolean isFiring() { + return this.entityData.get(FIRE_TIME) > 0; + } + @Override public boolean canShoot(Player player) { if (getWeaponIndex(0) == 2 || getWeaponIndex(0) == 3) { 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 72a1d650b..585ab2d30 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java @@ -4,10 +4,7 @@ import com.atsuishio.superbwarfare.Mod; 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.vehicle.base.AutoAimable; -import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; +import com.atsuishio.superbwarfare.entity.vehicle.base.*; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; @@ -54,11 +51,15 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; import java.util.Optional; import java.util.UUID; +import java.util.function.Consumer; import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEntity, CannonEntity, OwnableEntity, AutoAimable { + public static Consumer fireSound = vehicle -> { + }; + public static final EntityDataAccessor ANIM_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor GUN_ROTATE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ACTIVE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.BOOLEAN); @@ -67,15 +68,17 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - public Hpj11Entity(EntityType type, Level world) { - super(type, world); - } + private boolean wasFiring = false; public int changeTargetTimer = 60; public float gunRot; public float gunRotO; + public Hpj11Entity(EntityType type, Level world) { + super(type, world); + } + @Override protected void defineSynchedData(SynchedEntityData.Builder builder) { super.defineSynchedData(builder); @@ -187,7 +190,12 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public void baseTick() { - gunRotO = this.getGunRot(); + if (!this.wasFiring && this.isFiring() && this.level().isClientSide()) { + fireSound.accept(this); + } + this.wasFiring = this.isFiring(); + + this.gunRotO = this.getGunRot(); super.baseTick(); if (this.entityData.get(ANIM_TIME) > 0) { @@ -231,6 +239,10 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti } } + public boolean isFiring() { + return this.entityData.get(FIRE_TIME) > 0; + } + public void autoAim() { if (this.getFirstPassenger() != null || !entityData.get(ACTIVE)) { return;