diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/PrismTankRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/PrismTankRenderer.java index 1eb8b7f07..e70ef0d1a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/PrismTankRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/PrismTankRenderer.java @@ -17,6 +17,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.AABB; +import org.jetbrains.annotations.NotNull; import software.bernie.geckolib.cache.object.BakedGeoModel; import software.bernie.geckolib.cache.object.GeoBone; import software.bernie.geckolib.renderer.GeoEntityRenderer; @@ -45,7 +46,7 @@ public class PrismTankRenderer extends GeoEntityRenderer { } @Override - public void render(PrismTankEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) { + public void render(PrismTankEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, @NotNull MultiBufferSource bufferIn, int packedLightIn) { poseStack.pushPose(); poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()))); poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot()))); @@ -83,7 +84,7 @@ public class PrismTankRenderer extends GeoEntityRenderer { bone.setRotY(Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD); } - if (name.equals("head") || name.equals("head2")) { + if (name.equals("head")) { Player player = Minecraft.getInstance().player; bone.setHidden(ClientEventHandler.zoomVehicle && animatable.getFirstPassenger() == player); } 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 3b90b4b0e..2b59f9373 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -28,7 +28,6 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageTypes; @@ -84,12 +83,18 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity .explosionDamage(VehicleConfig.AH_6_CANNON_EXPLOSION_DAMAGE.get().floatValue()) .explosionRadius(VehicleConfig.AH_6_CANNON_EXPLOSION_RADIUS.get().floatValue()) .sound(ModSounds.INTO_CANNON.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_20mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_20mm.png")) + .sound1p(ModSounds.HELICOPTER_CANNON_FIRE_1P.get()) + .sound3p(ModSounds.HELICOPTER_CANNON_FIRE_3P.get()) + .sound3pFar(ModSounds.HELICOPTER_CANNON_FAR.get()) + .sound3pVeryFar(ModSounds.HELICOPTER_CANNON_VERYFAR.get()), new HeliRocketWeapon() .damage(VehicleConfig.AH_6_ROCKET_DAMAGE.get()) .explosionDamage(VehicleConfig.AH_6_ROCKET_EXPLOSION_DAMAGE.get()) .explosionRadius(VehicleConfig.AH_6_ROCKET_EXPLOSION_RADIUS.get()) - .sound(ModSounds.INTO_MISSILE.get()), + .sound(ModSounds.INTO_MISSILE.get()) + .sound1p(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get()) + .sound3p(ModSounds.HELICOPTER_ROCKET_FIRE_3P.get()), } }; } @@ -563,12 +568,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity this.entityData.set(HEAT, this.entityData.get(HEAT) + 4); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4, 1); - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_FAR.get(), 12, 1); - serverPlayer.playSound(ModSounds.HELICOPTER_CANNON_VERYFAR.get(), 24, 1); - } + playShootSound3p(player, 0, 4, 12, 24); } + } else if (getWeaponIndex(0) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) { x = 1.7f; y = 0.62f - 1.45f; @@ -591,9 +593,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity player.level().addFreshEntity(heliRocketEntity); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_3P.get(), 6, 1); - } + playShootSound3p(player, 0, 6, 6, 6); } this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) - 1); @@ -631,6 +631,11 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity return 3; } + @Override + public int getWeaponHeat(Player player) { + return entityData.get(HEAT); + } + @Override public float getRotX(float tickDelta) { return this.getPitch(tickDelta); 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 d5a7c8c21..89c2877c9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -588,6 +588,11 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, return 5; } + @Override + public int getWeaponHeat(Player player) { + return 0; + } + @Override public ResourceLocation getVehicleIcon() { return Mod.loc("textures/vehicle_icon/annihilator_icon.png"); 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 772d6983e..68d07ceae 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -96,18 +96,28 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit .explosionDamage(VehicleConfig.BMP_2_CANNON_EXPLOSION_DAMAGE.get()) .explosionRadius(VehicleConfig.BMP_2_CANNON_EXPLOSION_RADIUS.get().floatValue()) .sound(ModSounds.INTO_MISSILE.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_30mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_30mm.png")) + .sound1p(ModSounds.BMP_CANNON_FIRE_1P.get()) + .sound3p(ModSounds.BMP_CANNON_FIRE_3P.get()) + .sound3pFar(ModSounds.LAV_CANNON_FAR.get()) + .sound3pVeryFar(ModSounds.LAV_CANNON_VERYFAR.get()), new ProjectileWeapon() .damage(9.5f) .headShot(2) .zoom(false) .sound(ModSounds.INTO_CANNON.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/gun_7_62mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/gun_7_62mm.png")) + .sound1p(ModSounds.COAX_FIRE_1P.get()) + .sound3p(ModSounds.M_60_FIRE_3P.get()) + .sound3pFar(ModSounds.M_60_FAR.get()) + .sound3pVeryFar(ModSounds.M_60_VERYFAR.get()), new WgMissileWeapon() .damage(ExplosionConfig.WIRE_GUIDE_MISSILE_DAMAGE.get()) .explosionDamage(ExplosionConfig.WIRE_GUIDE_MISSILE_EXPLOSION_DAMAGE.get()) .explosionRadius(ExplosionConfig.WIRE_GUIDE_MISSILE_EXPLOSION_RADIUS.get()) - .sound(ModSounds.INTO_MISSILE.get()), + .sound(ModSounds.INTO_MISSILE.get()) + .sound1p(ModSounds.BMP_MISSILE_FIRE_1P.get()) + .sound3p(ModSounds.BMP_MISSILE_FIRE_3P.get()), } }; } @@ -345,14 +355,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z, 1, 0.02, 0.02, 0.02, 0, false); - float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT))); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.BMP_CANNON_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_VERYFAR.get(), 24, pitch); - } + playShootSound3p(player, 0, 4, 12, 24); } Level level = player.level(); @@ -410,11 +414,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit this.entityData.set(FIRE_ANIM, 2); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.M_60_FIRE_3P.get(), 3, 1); - serverPlayer.playSound(ModSounds.M_60_FAR.get(), 6, 1); - serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1); - } + playShootSound3p(player, 0, 3, 6, 12); } } else if (getWeaponIndex(0) == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) { Matrix4f transformT = getBarrelTransform(1); @@ -427,9 +427,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit player.level().addFreshEntity(wgMissileEntity); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.BMP_MISSILE_FIRE_3P.get(), 6, 1); - } + playShootSound3p(player, 0, 6, 0, 0); } this.entityData.set(LOADED_MISSILE, this.getEntityData().get(LOADED_MISSILE) - 1); @@ -724,6 +722,16 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit return 3; } + @Override + public int getWeaponHeat(Player player) { + if (getWeaponIndex(0) == 0) { + return entityData.get(HEAT); + } else if (getWeaponIndex(0) == 1) { + return entityData.get(COAX_HEAT); + } + return 0; + } + @Override public ResourceLocation getVehicleIcon() { return Mod.loc("textures/vehicle_icon/bmp2_icon.png"); 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 dd19b54b4..c5264c68d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java @@ -575,6 +575,10 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti return 2; } + @Override + public int getWeaponHeat(Player player) { + return entityData.get(HEAT); + } @Override public Vec3 getBarrelVector(float pPartialTicks) { if (getFirstPassenger() != null) { 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 32644b1ab..8db8db47a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -84,13 +84,21 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt .explosionDamage(VehicleConfig.LAV_150_CANNON_EXPLOSION_DAMAGE.get()) .explosionRadius(VehicleConfig.LAV_150_CANNON_EXPLOSION_RADIUS.get().floatValue()) .sound(ModSounds.INTO_MISSILE.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_20mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/cannon_20mm.png")) + .sound1p(ModSounds.LAV_CANNON_FIRE_1P.get()) + .sound3p(ModSounds.LAV_CANNON_FIRE_3P.get()) + .sound3pFar(ModSounds.LAV_CANNON_FAR.get()) + .sound3pVeryFar(ModSounds.LAV_CANNON_VERYFAR.get()), new ProjectileWeapon() .damage(9.5f) .headShot(2) .zoom(false) .sound(ModSounds.INTO_CANNON.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/gun_7_62mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/gun_7_62mm.png")) + .sound1p(ModSounds.COAX_FIRE_1P.get()) + .sound3p(ModSounds.RPK_FIRE_3P.get()) + .sound3pFar(ModSounds.RPK_FAR.get()) + .sound3pVeryFar(ModSounds.RPK_VERYFAR.get()), } }; } @@ -252,14 +260,8 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z, 1, 0.02, 0.02, 0.02, 0, false); - float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT))); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.LAV_CANNON_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.LAV_CANNON_VERYFAR.get(), 24, pitch); - } + playShootSound3p(player, 0, 4, 12, 24); } Level level = player.level(); @@ -318,11 +320,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt this.entityData.set(FIRE_ANIM, 2); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.RPK_FIRE_3P.get(), 3, 1); - serverPlayer.playSound(ModSounds.RPK_FAR.get(), 6, 1); - serverPlayer.playSound(ModSounds.RPK_VERYFAR.get(), 12, 1); - } + playShootSound3p(player, 0, 3, 6, 12); } } } @@ -591,6 +589,16 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt return 3; } + @Override + public int getWeaponHeat(Player player) { + if (getWeaponIndex(0) == 0) { + return entityData.get(HEAT); + } else if (getWeaponIndex(0) == 1) { + return entityData.get(COAX_HEAT); + } + return 0; + } + @Override public ResourceLocation getVehicleIcon() { return Mod.loc("textures/vehicle_icon/lav150_icon.png"); 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 1addc3fa0..09284e416 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -435,6 +435,11 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity return 5; } + @Override + public int getWeaponHeat(Player player) { + return 0; + } + @Override public Vec3 getBarrelVector(float pPartialTicks) { if (getFirstPassenger() != null) { 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 df4afcd4b..111e40f8f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -504,6 +504,11 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt return 5; } + @Override + public int getWeaponHeat(Player player) { + return 0; + } + @Override public Vec3 getBarrelVector(float pPartialTicks) { if (getFirstPassenger() != null) { 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 92b478b68..af5b4776b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/PrismTankEntity.java @@ -94,7 +94,9 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo return new VehicleWeapon[][]{ new VehicleWeapon[]{ new LaserWeapon() - .sound(ModSounds.INTO_MISSILE.get()), + .sound(ModSounds.INTO_MISSILE.get()) + .sound1p(ModSounds.PRISM_FIRE_1P.get()) + .sound3p(ModSounds.PRISM_FIRE_3P.get()), new LaserWeapon() .sound(ModSounds.INTO_CANNON.get()) } @@ -295,9 +297,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo Level level = player.level(); if (level instanceof ServerLevel) { if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.PRISM_FIRE_3P.get(), 5, 1); - } + playShootSound3p(player, 0, 5, 5, 5); } this.entityData.set(HEAT, entityData.get(HEAT) + 55); @@ -336,9 +336,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo if (level instanceof ServerLevel) { if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.PRISM_FIRE_3P_2.get(), 4, 1); - } + playShootSound3p(player, 0, 4, 4, 4); } this.entityData.set(HEAT, entityData.get(HEAT) + 2); @@ -771,6 +769,11 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo return 3; } + @Override + public int getWeaponHeat(Player player) { + return entityData.get(HEAT); + } + @Override public ResourceLocation getVehicleIcon() { return Mod.loc("textures/vehicle_icon/prism_tank_icon.png"); 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 b7c885a4e..52ade33e8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -66,6 +66,10 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo .headShot(2) .zoom(false) .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")) + .sound1p(ModSounds.M_2_FIRE_1P.get()) + .sound3p(ModSounds.M_2_FIRE_3P.get()) + .sound3pFar(ModSounds.M_2_FAR.get()) + .sound3pVeryFar(ModSounds.M_2_VERYFAR.get()) } }; } @@ -215,11 +219,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT))); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.M_2_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.M_2_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.M_2_VERYFAR.get(), 24, pitch); - } + playShootSound3p(player, 0, 4, 12, 24); } Level level = player.level(); @@ -561,6 +561,11 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo return 1; } + @Override + public int getWeaponHeat(Player player) { + return entityData.get(HEAT); + } + @Override public ResourceLocation getVehicleIcon() { return Mod.loc("textures/vehicle_icon/speedboat_icon.png"); 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 f59d01ef9..897a813ff 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -109,7 +109,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .gravity(0.1f) .sound(ModSounds.INTO_MISSILE.get()) .ammo(ModItems.AP_5_INCHES.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/ap_shell.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/ap_shell.png")) + .sound1p(ModSounds.YX_100_FIRE_1P.get()) + .sound3p(ModSounds.YX_100_FIRE_3P.get()) + .sound3pFar(ModSounds.YX_100_FAR.get()) + .sound3pVeryFar(ModSounds.YX_100_VERYFAR.get()), // HE new CannonShellWeapon() .hitDamage(VehicleConfig.YX_100_HE_CANNON_DAMAGE.get()) @@ -122,7 +126,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .gravity(0.1f) .sound(ModSounds.INTO_CANNON.get()) .ammo(ModItems.HE_5_INCHES.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/he_shell.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/he_shell.png")) + .sound1p(ModSounds.YX_100_FIRE_1P.get()) + .sound3p(ModSounds.YX_100_FIRE_3P.get()) + .sound3pFar(ModSounds.YX_100_FAR.get()) + .sound3pVeryFar(ModSounds.YX_100_VERYFAR.get()), // 同轴重机枪 new ProjectileWeapon() .damage(VehicleConfig.HEAVY_MACHINE_GUN_DAMAGE.get()) @@ -131,7 +139,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .bypassArmorRate(0.4f) .ammo(ModItems.HEAVY_AMMO.get()) .sound(ModSounds.INTO_CANNON.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")) + .sound1p(ModSounds.M_2_FIRE_1P.get()) + .sound3p(ModSounds.M_2_FIRE_3P.get()) + .sound3pFar(ModSounds.M_2_FAR.get()) + .sound3pVeryFar(ModSounds.M_2_VERYFAR.get()), }, new VehicleWeapon[]{ // 机枪 @@ -141,7 +153,11 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti .zoom(false) .bypassArmorRate(0.4f) .ammo(ModItems.HEAVY_AMMO.get()) - .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")), + .icon(Mod.loc("textures/screens/vehicle_weapon/gun_12_7mm.png")) + .sound1p(ModSounds.M_2_FIRE_1P.get()) + .sound3p(ModSounds.M_2_FIRE_3P.get()) + .sound3pFar(ModSounds.M_2_FAR.get()) + .sound3pVeryFar(ModSounds.M_2_VERYFAR.get()), }, new VehicleWeapon[]{ // 蜂群无人机 @@ -465,11 +481,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti level().addFreshEntity(entityToSpawn); if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.YX_100_FIRE_3P.get(), 8, 1); - serverPlayer.playSound(ModSounds.YX_100_FAR.get(), 16, 1); - serverPlayer.playSound(ModSounds.YX_100_VERYFAR.get(), 32, 1); - } + playShootSound3p(player, 0, 8, 16, 32); } this.entityData.set(CANNON_RECOIL_TIME, 40); @@ -568,14 +580,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.entityData.set(COAX_HEAT, this.entityData.get(COAX_HEAT) + 4); this.entityData.set(FIRE_ANIM, 2); - float pitch = this.entityData.get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(COAX_HEAT))); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.M_2_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.M_2_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.M_2_VERYFAR.get(), 24, pitch); - } + playShootSound3p(player, 0, 4, 12, 24); } } } @@ -593,14 +599,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.level().addFreshEntity(projectileEntity); - float pitch = this.entityData.get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(HEAT))); - if (!player.level().isClientSide) { - if (player instanceof ServerPlayer serverPlayer) { - serverPlayer.playSound(ModSounds.M_2_FIRE_3P.get(), 4, pitch); - serverPlayer.playSound(ModSounds.M_2_FAR.get(), 12, pitch); - serverPlayer.playSound(ModSounds.M_2_VERYFAR.get(), 24, pitch); - } + playShootSound3p(player, 1, 4, 12, 24); } this.entityData.set(GUN_FIRE_TIME, 2); @@ -1163,6 +1163,19 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti return 3; } + @Override + public int getWeaponHeat(Player player) { + if (player == getNthEntity(0)) { + return entityData.get(COAX_HEAT); + } + + if (player == getNthEntity(1)) { + return entityData.get(HEAT); + } + + return 0; + } + @Override public void changeWeapon(int index, int value, boolean isScroll) { if (index != 0) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java index d7fa016e5..7455592ab 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ArmedVehicleEntity.java @@ -74,4 +74,6 @@ public interface ArmedVehicleEntity { * @return 放大倍率 */ int zoomFov(); + + int getWeaponHeat(Player player); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java index d75aeef45..3416dc1e2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java @@ -1,6 +1,8 @@ package com.atsuishio.superbwarfare.entity.vehicle.base; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; import java.util.ArrayList; import java.util.List; @@ -144,4 +146,22 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity { selectedWeapons.set(index, type); vehicle.getEntityData().set(VehicleEntity.SELECTED_WEAPON, selectedWeapons); } + + default void playShootSound3p(Player player, int seat, int radius, int radius2, int radius3) { + var weapons = getAvailableWeapons(seat); + var weapon = weapons.get(getWeaponIndex(seat)); + float pitch = getWeaponHeat(player) <= 60 ? 1 : (float) (1 - 0.011 * java.lang.Math.abs(60 - getWeaponHeat(player))); + + if (player instanceof ServerPlayer serverPlayer) { + if (weapon.sound3p != null) { + serverPlayer.playSound(weapon.sound3p, radius, pitch); + } + if (weapon.sound3pFar != null) { + serverPlayer.playSound(weapon.sound3pFar, radius2, pitch); + } + if (weapon.sound3pVeryFar != null) { + serverPlayer.playSound(weapon.sound3pVeryFar, radius3, pitch); + } + } + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java index 6bacdff50..076bda0bb 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java @@ -24,6 +24,14 @@ public abstract class VehicleWeapon { public int backupAmmo; public SoundEvent sound; + // 第一人称射击音效 + public SoundEvent sound1p; + // 第三人称射击音效 + public SoundEvent sound3p; + public SoundEvent sound3pFar; + // 第一人称射击音效 + public SoundEvent sound3pVeryFar; + public VehicleWeapon icon(ResourceLocation icon) { this.icon = icon; @@ -76,4 +84,24 @@ public abstract class VehicleWeapon { this.maxAmmo = maxAmmo; return this; } + + public VehicleWeapon sound1p(SoundEvent sound1p) { + this.sound1p = sound1p; + return this; + } + + public VehicleWeapon sound3p(SoundEvent sound3p) { + this.sound3p = sound3p; + return this; + } + + public VehicleWeapon sound3pFar(SoundEvent sound3pFar) { + this.sound3pFar = sound3pFar; + return this; + } + + public VehicleWeapon sound3pVeryFar(SoundEvent sound3pVeryFar) { + this.sound3pVeryFar = sound3pVeryFar; + return this; + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 02445e014..0a9373b23 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -4,7 +4,8 @@ import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.config.server.MiscConfig; -import com.atsuishio.superbwarfare.entity.vehicle.*; +import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity; +import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; @@ -59,9 +60,6 @@ import software.bernie.geckolib.cache.object.GeoBone; import java.util.List; -import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.COAX_HEAT; -import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.HEAT; - @EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) public class ClientEventHandler { @@ -860,114 +858,18 @@ public class ClientEventHandler { } public static void playVehicleClientSounds(Player player, WeaponVehicleEntity iVehicle, int type) { - if (iVehicle instanceof SpeedboatEntity speedboat) { - float pitch = speedboat.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - speedboat.getEntityData().get(HEAT))); - player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } + var weapons = iVehicle.getAvailableWeapons(type); + var weapon = weapons.get(iVehicle.getWeaponIndex(type)); - if (iVehicle instanceof Ah6Entity ah6Entity) { - float pitch = ah6Entity.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.getEntityData().get(HEAT))); - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - if (ah6Entity.getWeaponIndex(0) == 0) { - player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch); - } else if (ah6Entity.getWeaponIndex(0) == 1) { - player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); - } - } else { - if (ah6Entity.getWeaponIndex(0) == 0) { - player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_3P.get(), 4f, pitch); - } else if (ah6Entity.getWeaponIndex(0) == 1) { - player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_3P.get(), 4f, 1); - } + float pitch = iVehicle.getWeaponHeat(player) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - iVehicle.getWeaponHeat(player))); + + if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || (zoomVehicle && !(iVehicle instanceof Ah6Entity))) { + if (weapon.sound1p != null) { + player.playSound(weapon.sound1p, 1f, pitch); } - - } - if (iVehicle instanceof Lav150Entity lav150) { - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - if (lav150.getWeaponIndex(0) == 0) { - float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT))); - player.playSound(ModSounds.LAV_CANNON_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (lav150.getWeaponIndex(0) == 1) { - float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); - } - } else { - if (lav150.getWeaponIndex(0) == 0) { - float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT))); - player.playSound(ModSounds.LAV_CANNON_FIRE_3P.get(), 4f, pitch); - } else if (lav150.getWeaponIndex(0) == 1) { - float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.M_60_FIRE_3P.get(), 4f, pitch); - } - } - - - } - if (iVehicle instanceof Bmp2Entity bmp2) { - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - if (bmp2.getWeaponIndex(0) == 0) { - float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT))); - player.playSound(ModSounds.BMP_CANNON_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (bmp2.getWeaponIndex(0) == 1) { - float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); - } else if (bmp2.getWeaponIndex(0) == 2) { - player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1); - } - } else { - if (bmp2.getWeaponIndex(0) == 0) { - float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT))); - player.playSound(ModSounds.BMP_CANNON_FIRE_3P.get(), 4f, pitch); - } else if (bmp2.getWeaponIndex(0) == 1) { - float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.M_60_FIRE_3P.get(), 4f, pitch); - } else if (bmp2.getWeaponIndex(0) == 2) { - player.playSound(ModSounds.BMP_MISSILE_FIRE_3P.get(), 4f, 1); - } - } - } - if (iVehicle instanceof Yx100Entity yx100) { - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - if (type == 1) { - float pitch = yx100.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(HEAT))); - player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (type == 0) { - if (yx100.getWeaponIndex(0) == 0 || yx100.getWeaponIndex(0) == 1) { - player.playSound(ModSounds.YX_100_FIRE_1P.get(), 1f, 1); - } else if (yx100.getWeaponIndex(0) == 2) { - float pitch = yx100.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.M_2_FIRE_1P.get(), 1f, pitch); - player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } - } - } else { - if (type == 1) { - float pitch = yx100.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(HEAT))); - player.playSound(ModSounds.M_2_FIRE_3P.get(), 4f, pitch); - } else if (type == 0) { - if (yx100.getWeaponIndex(0) == 0 || yx100.getWeaponIndex(0) == 1) { - player.playSound(ModSounds.YX_100_FIRE_3P.get(), 4f, 1); - } else if (yx100.getWeaponIndex(0) == 2) { - float pitch = yx100.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - yx100.getEntityData().get(COAX_HEAT))); - player.playSound(ModSounds.M_2_FIRE_3P.get(), 4f, pitch); - } - } - } - - } - if (iVehicle instanceof PrismTankEntity prismTank) { - if (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - if (prismTank.getWeaponIndex(0) == 0) { - player.playSound(ModSounds.PRISM_FIRE_1P.get(), 1f, 1); - } - } else { - if (prismTank.getWeaponIndex(0) == 0) { - player.playSound(ModSounds.PRISM_FIRE_3P.get(), 4f, 1); - } + } else { + if (weapon.sound3p != null) { + player.playSound(weapon.sound3p, 3f, pitch); } } } diff --git a/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_3p.ogg b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_3p.ogg index 3765b8f35..946f113cd 100644 Binary files a/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_3p.ogg and b/src/main/resources/assets/superbwarfare/sounds/yx100/yx100_fire_3p.ogg differ