添加lav引擎音效

This commit is contained in:
Atsuihsio 2025-01-15 19:00:55 +08:00
parent f40776a9ac
commit 16f42f799e
6 changed files with 48 additions and 6 deletions

View file

@ -26,6 +26,7 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
@ -138,6 +139,24 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
if (source.is(ModDamageTypes.VEHICLE_STRIKE)) {
amount *= 0.7f;
}
if (source.is(DamageTypes.PLAYER_ATTACK)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_ATTACK)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_ATTACK_NO_AGGRO)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.MOB_PROJECTILE)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.ARROW)) {
amount *= 0.05f;
}
if (source.is(DamageTypes.TRIDENT)) {
amount *= 0.05f;
}
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
this.hurt(0.5f * Math.max(amount - 15, 0));
@ -365,10 +384,6 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
this.extraEnergy(VehicleConfig.SPEEDBOAT_ENERGY_COST.get());
}
if (level().isClientSide) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown || this.backInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1f), false);
}
this.entityData.set(POWER, this.entityData.get(POWER) * 0.97f);
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * (float)Math.max(0.7f - 0.1f * this.getDeltaMovement().horizontalDistance(), 0.3));
@ -451,7 +466,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
@Override
public SoundEvent getEngineSound() {
return ModSounds.BOAT_ENGINE.get();
return ModSounds.LAV_ENGINE.get();
}
@Override

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.event;
import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity;
import com.atsuishio.superbwarfare.entity.vehicle.Lav150Entity;
import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.SeekTool;
@ -8,6 +9,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
@ -19,6 +21,7 @@ import org.joml.Math;
import java.util.List;
import static com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity.PROPELLER_ROT;
import static com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity.POWER;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ClientSoundHandler {
@ -49,7 +52,15 @@ public class ClientSoundHandler {
if (player.getVehicle() == ah6Entity) {
player.playSound(ModSounds.HELICOPTER_ENGINE_1P.get(), 2 * (mobileVehicle.getEntityData().get(PROPELLER_ROT) - 0.012f), (float) ((2 * Math.random() - 1) * 0.1f + 1.0f));
} else {
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 5 * (mobileVehicle.getEntityData().get(PROPELLER_ROT) - 0.012f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1.0f), false);
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 5 * (mobileVehicle.getEntityData().get(PROPELLER_ROT) - 0.012f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1), false);
}
}
if (e instanceof Lav150Entity lav150) {
distanceReduce = (float) Math.max((1 - distance / 64), 0);
if (player.getVehicle() == lav150) {
player.playSound(ModSounds.LAV_ENGINE_1P.get(), 2 * (Mth.abs(mobileVehicle.getEntityData().get(POWER)) - 0.006f), (float) ((2 * Math.random() - 1) * 0.1f + 0.95f));
} else {
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 5 * (Mth.abs(mobileVehicle.getEntityData().get(POWER)) - 0.006f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1), false);
}
}
}

View file

@ -400,5 +400,7 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> LAV_CANNON_FIRE_3P = REGISTRY.register("lav_cannon_fire_3p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("lav_fire_3p")));
public static final RegistryObject<SoundEvent> LAV_CANNON_FAR = REGISTRY.register("lav_cannon_far", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("lav_far")));
public static final RegistryObject<SoundEvent> LAV_CANNON_VERYFAR = REGISTRY.register("lav_cannon_veryfar", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("lav_veryfar")));
public static final RegistryObject<SoundEvent> LAV_ENGINE = REGISTRY.register("lav_engine", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("lav_engine")));
public static final RegistryObject<SoundEvent> LAV_ENGINE_1P = REGISTRY.register("lav_engine_1p", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("lav_engine_1p")));
}

View file

@ -2736,5 +2736,19 @@
"stream": false
}
]
},
"lav_engine": {
"sounds": [
{
"name": "superbwarfare:lav/lav_engine"
}
]
},
"lav_engine_1p": {
"sounds": [
{
"name": "superbwarfare:lav/lav_engine_1p"
}
]
}
}