尝试添加部分载具开火音效,优化代码

This commit is contained in:
17146 2025-05-24 17:16:49 +08:00 committed by Light_Quanta
parent e4bd8e5b00
commit 206eff0e50
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 48 additions and 24 deletions

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare;
import com.atsuishio.superbwarfare.api.event.RegisterContainersEvent; import com.atsuishio.superbwarfare.api.event.RegisterContainersEvent;
import com.atsuishio.superbwarfare.client.MouseMovementHandler; import com.atsuishio.superbwarfare.client.MouseMovementHandler;
import com.atsuishio.superbwarfare.client.renderer.molang.MolangVariable; 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.client.sound.VehicleSoundInstance;
import com.atsuishio.superbwarfare.compat.CompatHolder; import com.atsuishio.superbwarfare.compat.CompatHolder;
import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper; 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.ClientConfig;
import com.atsuishio.superbwarfare.config.CommonConfig; import com.atsuishio.superbwarfare.config.CommonConfig;
import com.atsuishio.superbwarfare.config.ServerConfig; 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.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.NetworkRegistry; 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.trackSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(vehicle));
MobileVehicleEntity.engineSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.EngineSound(vehicle)); MobileVehicleEntity.engineSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.EngineSound(vehicle));
MobileVehicleEntity.swimSound = vehicle -> Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.SwimSound(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));
} }
} }

View file

@ -13,20 +13,6 @@ public class ClientSoundHandler {
if (entity instanceof LoudlyEntity) { if (entity instanceof LoudlyEntity) {
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(entity)); Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(entity));
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(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));
// }
// }
// });
} }
} }
} }

View file

@ -62,13 +62,17 @@ public abstract class VehicleFireSoundInstance extends AbstractTickableSoundInst
} }
public static class A10FireSound extends VehicleSoundInstance { public static class A10FireSound extends VehicleSoundInstance {
public A10FireSound(MobileVehicleEntity mobileVehicle) { public A10FireSound(MobileVehicleEntity mobileVehicle) {
super(ModSounds.A_10_FIRE.get(), Minecraft.getInstance(), mobileVehicle); super(ModSounds.A_10_FIRE.get(), Minecraft.getInstance(), mobileVehicle);
} }
@Override @Override
protected boolean canPlay(MobileVehicleEntity mobileVehicle) { protected boolean canPlay(MobileVehicleEntity mobileVehicle) {
return true; if (mobileVehicle instanceof A10Entity a10Entity) {
return a10Entity.isFiring();
}
return false;
} }
@Override @Override
@ -89,6 +93,7 @@ public abstract class VehicleFireSoundInstance extends AbstractTickableSoundInst
} }
public static class HPJ11CloseFireSound extends VehicleSoundInstance { public static class HPJ11CloseFireSound extends VehicleSoundInstance {
public HPJ11CloseFireSound(MobileVehicleEntity mobileVehicle) { public HPJ11CloseFireSound(MobileVehicleEntity mobileVehicle) {
super(ModSounds.HPJ_11_FIRE_3P.get(), Minecraft.getInstance(), mobileVehicle); super(ModSounds.HPJ_11_FIRE_3P.get(), Minecraft.getInstance(), mobileVehicle);
} }

View file

@ -59,11 +59,15 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity, WeaponVehicleEntity, AircraftEntity { public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity, WeaponVehicleEntity, AircraftEntity {
public static Consumer<MobileVehicleEntity> fireSound = vehicle -> {
};
public static final EntityDataAccessor<Integer> LOADED_ROCKET = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> LOADED_ROCKET = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_BOMB = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> LOADED_BOMB = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(A10Entity.class, EntityDataSerializers.INT);
@ -80,6 +84,8 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
public int lockTime; public int lockTime;
public boolean locked; public boolean locked;
private boolean wasFiring = false;
public A10Entity(EntityType<A10Entity> type, Level world) { public A10Entity(EntityType<A10Entity> type, Level world) {
super(type, world); super(type, world);
} }
@ -189,7 +195,12 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
@Override @Override
public void baseTick() { 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(); 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); 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; return 0;
} }
public boolean isFiring() {
return this.entityData.get(FIRE_TIME) > 0;
}
@Override @Override
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
if (getWeaponIndex(0) == 2 || getWeaponIndex(0) == 3) { if (getWeaponIndex(0) == 2 || getWeaponIndex(0) == 3) {

View file

@ -4,10 +4,7 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; 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.vehicle.base.AutoAimable; import com.atsuishio.superbwarfare.entity.vehicle.base.*;
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.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon;
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; 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.Comparator;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter;
public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEntity, CannonEntity, OwnableEntity, AutoAimable { public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEntity, CannonEntity, OwnableEntity, AutoAimable {
public static Consumer<MobileVehicleEntity> fireSound = vehicle -> {
};
public static final EntityDataAccessor<Integer> ANIM_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> ANIM_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> GUN_ROTATE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> GUN_ROTATE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Boolean> ACTIVE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> ACTIVE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.BOOLEAN);
@ -67,15 +68,17 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> FIRE_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public Hpj11Entity(EntityType<Hpj11Entity> type, Level world) { private boolean wasFiring = false;
super(type, world);
}
public int changeTargetTimer = 60; public int changeTargetTimer = 60;
public float gunRot; public float gunRot;
public float gunRotO; public float gunRotO;
public Hpj11Entity(EntityType<Hpj11Entity> type, Level world) {
super(type, world);
}
@Override @Override
protected void defineSynchedData(SynchedEntityData.Builder builder) { protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder); super.defineSynchedData(builder);
@ -187,7 +190,12 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
@Override @Override
public void baseTick() { 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(); super.baseTick();
if (this.entityData.get(ANIM_TIME) > 0) { 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() { public void autoAim() {
if (this.getFirstPassenger() != null || !entityData.get(ACTIVE)) { if (this.getFirstPassenger() != null || !entityData.get(ACTIVE)) {
return; return;