修改直升机音效
This commit is contained in:
parent
daa8c777d2
commit
38faab6b19
3 changed files with 88 additions and 25 deletions
|
@ -138,34 +138,34 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
|
||||||
this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 0.7f) * diffY * this.entityData.get(POWER) + 0.5f * this.entityData.get(DELTA_ROT), -5f, 5f));
|
this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 0.7f) * diffY * this.entityData.get(POWER) + 0.5f * this.entityData.get(DELTA_ROT), -5f, 5f));
|
||||||
this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 0.6f) * diffX * this.entityData.get(POWER), -80, 80));
|
this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 0.6f) * diffX * this.entityData.get(POWER), -80, 80));
|
||||||
this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(POWER), -50, 50));
|
this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(POWER), -50, 50));
|
||||||
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
boolean up = this.upInputDown || this.forwardInputDown;
|
boolean up = this.upInputDown || this.forwardInputDown;
|
||||||
boolean down = this.downInputDown || this.backInputDown;
|
boolean down = this.downInputDown || this.backInputDown;
|
||||||
|
|
||||||
if (!engineStart && up) {
|
if (!engineStart && up) {
|
||||||
engineStart = true;
|
engineStart = true;
|
||||||
this.level().playSound(null, this, ModSounds.HELICOPTER_ENGINE_START.get(), this.getSoundSource(), 3, 1);
|
this.level().playSound(null, this, ModSounds.HELICOPTER_ENGINE_START.get(), this.getSoundSource(), 3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (up && engineStartOver) {
|
if (up && engineStartOver) {
|
||||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f));
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (down && engineStartOver) {
|
if (down && engineStartOver) {
|
||||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f));
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engineStart && !engineStartOver) {
|
if (engineStart && !engineStartOver) {
|
||||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0012f, 0.045f));
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0012f, 0.045f));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(up || down) && engineStartOver) {
|
if (!(up || down) && engineStartOver) {
|
||||||
if (this.getDeltaMovement().y() + 0.06 < 0) {
|
if (this.getDeltaMovement().y() + 0.06 < 0) {
|
||||||
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0002f, 0.12f));
|
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0002f, 0.12f));
|
||||||
} else {
|
} else {
|
||||||
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.onGround() ? 0.00005f : 0.0006f), 0));
|
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.onGround() ? 0.00005f : 0.0006f), 0));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,6 +173,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
|
||||||
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.95f);
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.95f);
|
||||||
this.entityData.set(PROPELLER_ROT, Mth.lerp(0.0001f, this.entityData.get(POWER), this.entityData.get(POWER)));
|
this.entityData.set(PROPELLER_ROT, Mth.lerp(0.0001f, this.entityData.get(POWER), this.entityData.get(POWER)));
|
||||||
this.setPropellerRot(this.getPropellerRot() + 30 * this.entityData.get(PROPELLER_ROT));
|
this.setPropellerRot(this.getPropellerRot() + 30 * this.entityData.get(PROPELLER_ROT));
|
||||||
|
this.entityData.set(PROPELLER_ROT, this.entityData.get(PROPELLER_ROT) * 0.9995f);
|
||||||
|
|
||||||
setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f));
|
setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(POWER), 0.0f));
|
||||||
|
|
||||||
|
@ -191,9 +192,9 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico
|
||||||
engineStartOver = false;
|
engineStartOver = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level().isClientSide) {
|
// if (level().isClientSide) {
|
||||||
level().playLocalSound(this.getX() + this.getDeltaMovement().x, this.getY() + this.getBbHeight() + this.getDeltaMovement().y + 0.06, this.getZ() + this.getDeltaMovement().z, this.getEngineSound(), this.getSoundSource(), Math.max((this.upInputDown ? 10f : 3f) * 6 * this.entityData.get(POWER) - 0.038f, 0), (random.nextFloat() * 0.1f + 1.0f), false);
|
// level().playLocalSound(this.getX() + this.getDeltaMovement().x, this.getY() + this.getBbHeight() + this.getDeltaMovement().y + 0.06, this.getZ() + this.getDeltaMovement().z, this.getEngineSound(), this.getSoundSource(), Math.max((this.upInputDown ? 10f : 3f) * 6 * this.entityData.get(POWER) - 0.038f, 0), (random.nextFloat() * 0.1f + 1.0f), false);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.atsuishio.superbwarfare.event;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.entity.Ah6Entity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.MobileVehicleEntity;
|
||||||
|
import com.atsuishio.superbwarfare.tools.SeekTool;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import org.joml.Math;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.atsuishio.superbwarfare.entity.MobileVehicleEntity.POWER;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||||
|
public class ClientSoundHandler {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void handleClientTick(TickEvent.ClientTickEvent event) {
|
||||||
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
|
var options = Minecraft.getInstance().options;
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Entity> engineVehicle = SeekTool.getVehicleWithinRange(player, player.level(), 196);
|
||||||
|
|
||||||
|
for (var e : engineVehicle) {
|
||||||
|
if (e instanceof MobileVehicleEntity mobileVehicle){
|
||||||
|
|
||||||
|
Vec3 listener = player.getEyePosition();
|
||||||
|
Vec3 engineRealPos = e.getEyePosition();
|
||||||
|
Vec3 toVec = listener.vectorTo(engineRealPos).normalize();
|
||||||
|
double distance = listener.distanceTo(engineRealPos);
|
||||||
|
|
||||||
|
var engineSoundPos = new Vec3(listener.x + toVec.x, listener.y + toVec.y, listener.z + toVec.z);
|
||||||
|
SoundEvent engineSound = mobileVehicle.getEngineSound();
|
||||||
|
float distanceReduce;
|
||||||
|
if (e instanceof Ah6Entity ah6Entity) {
|
||||||
|
distanceReduce = (float) (1 - distance / 128);
|
||||||
|
player.level().playLocalSound(BlockPos.containing(engineSoundPos), engineSound, mobileVehicle.getSoundSource(), 20 * (mobileVehicle.getEntityData().get(POWER) - 0.012f) * distanceReduce * distanceReduce, (float) ((2 * Math.random() - 1) * 0.1f + 1.0f), false);
|
||||||
|
// player.displayClientMessage(Component.literal("Angle:" + engineSoundPos), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.tools;
|
package com.atsuishio.superbwarfare.tools;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.entity.ClaymoreEntity;
|
import com.atsuishio.superbwarfare.entity.ClaymoreEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.MobileVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.VehicleEntity;
|
import com.atsuishio.superbwarfare.entity.VehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -24,6 +25,13 @@ import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
public class SeekTool {
|
public class SeekTool {
|
||||||
|
|
||||||
|
public static List<Entity> getVehicleWithinRange(Player player, Level level, double range) {
|
||||||
|
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
|
||||||
|
.filter(e -> e.position().distanceTo(player.getEyePosition()) <= range
|
||||||
|
&& e instanceof MobileVehicleEntity)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
public static Entity seekEntity(Entity entity, Level level, double seekRange, double seekAngle) {
|
public static Entity seekEntity(Entity entity, Level level, double seekRange, double seekAngle) {
|
||||||
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
|
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
|
||||||
.filter(e -> {
|
.filter(e -> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue