尝试加入移动音源

This commit is contained in:
Atsuishio 2025-05-05 23:11:06 +08:00 committed by Light_Quanta
parent 3a5ec09058
commit f4d0dd52bd
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 53 additions and 13 deletions

View file

@ -0,0 +1,46 @@
package com.atsuishio.superbwarfare.client;
import com.atsuishio.superbwarfare.entity.vehicle.Tom6Entity;
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ClientVehicleSoundsInstance extends AbstractTickableSoundInstance {
private final Tom6Entity tom6Entity;
public ClientVehicleSoundsInstance(Tom6Entity pTom6Entity) {
super(SoundEvents.ELYTRA_FLYING, SoundSource.PLAYERS, SoundInstance.createUnseededRandom());
this.tom6Entity = pTom6Entity;
this.looping = true;
this.delay = 0;
this.volume = 0.0F;
this.x = pTom6Entity.getX();
this.y = pTom6Entity.getY();
this.z = pTom6Entity.getZ();
}
public void tick() {
if (this.tom6Entity.isRemoved()) {
this.stop();
} else {
this.x = tom6Entity.getX();
this.y = tom6Entity.getY();
this.z = tom6Entity.getZ();
float $$0 = (float) tom6Entity.getDeltaMovement().horizontalDistance();
if ($$0 >= 0.01F) {
this.pitch = Mth.clamp(this.pitch + 0.0025F, 0.0F, 1.0F);
this.volume = Mth.lerp(Mth.clamp($$0, 0.0F, 0.5F), 0.0F, 0.7F);
} else {
this.pitch = 0.0F;
this.volume = 0.0F;
}
}
}
}

View file

@ -116,7 +116,7 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
if (sourceEntity instanceof Player player) { if (sourceEntity instanceof Player player) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.target.down", player.displayClientMessage(Component.translatable("tips.superbwarfare.target.down",
FormatTool.format1D((entity.position()).distanceTo((sourceEntity.position()))), "m"), true); FormatTool.format1D(entity.position().distanceTo(sourceEntity.position())), "m"), true);
SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 1, 1); SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 1, 1);
targetEntity.entityData.set(DOWN_TIME, 40); targetEntity.entityData.set(DOWN_TIME, 40);
} }

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig;
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
import com.atsuishio.superbwarfare.entity.projectile.MelonBombEntity; import com.atsuishio.superbwarfare.entity.projectile.MelonBombEntity;
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity; import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition; import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
@ -45,7 +46,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class A10Entity extends MobileVehicleEntity implements GeoEntity { public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float yRotSync; private float yRotSync;
private boolean fly; private boolean fly;
@ -340,7 +341,7 @@ public class A10Entity extends MobileVehicleEntity implements GeoEntity {
float x = 0f; float x = 0f;
float y = 0.1f; float y = 0.1f;
float z = 3.8494875f; float z = 3.95f;
// TODO 正确调整乘客位置 // TODO 正确调整乘客位置
y += (float) passenger.getVehicleAttachmentPoint(this).y; y += (float) passenger.getVehicleAttachmentPoint(this).y;

View file

@ -156,9 +156,9 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
this.setXRot(Mth.clamp(this.getXRot() + 0.1f, -89, 89)); this.setXRot(Mth.clamp(this.getXRot() + 0.1f, -89, 89));
} }
} else if (passenger instanceof Player player) { } else if (passenger instanceof Player player) {
if (level().isClientSide && this.getEnergy() > 0) { // if (level().isClientSide && this.getEnergy() > 0) {
level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1.2f), false); // level().playLocalSound(this.getX(), this.getY() + this.getBbHeight() * 0.5, this.getZ(), this.getEngineSound(), this.getSoundSource(), Math.min((this.forwardInputDown ? 7.5f : 5f) * 2 * Mth.abs(this.entityData.get(POWER)), 0.25f), (random.nextFloat() * 0.1f + 1.2f), false);
} // }
if (forwardInputDown && getEnergy() > 0) { if (forwardInputDown && getEnergy() > 0) {
this.consumeEnergy(VehicleConfig.TOM_6_ENERGY_COST.get()); this.consumeEnergy(VehicleConfig.TOM_6_ENERGY_COST.get());

View file

@ -152,13 +152,6 @@ public abstract class CameraMixin {
return; return;
} }
// if (player.getVehicle() instanceof A10Entity vehicle && (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || ClientEventHandler.zoomVehicle)) {
// setRotation(Mth.lerp(partialTicks, vehicle.yRotO, vehicle.getYRot()), Mth.lerp(partialTicks, vehicle.xRotO, vehicle.getXRot()));
// setPosition(Mth.lerp(partialTicks, player.xo, player.getX()), Mth.lerp(partialTicks, player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(partialTicks, player.zo, player.getZ()));
// info.cancel();
// return;
// }
if (player.getVehicle() instanceof VehicleEntity vehicle && vehicle instanceof CannonEntity cannon && (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || ClientEventHandler.zoomVehicle)) { if (player.getVehicle() instanceof VehicleEntity vehicle && vehicle instanceof CannonEntity cannon && (Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON || ClientEventHandler.zoomVehicle)) {
setRotation(Mth.lerp(partialTicks, player.yRotO, player.getYRot()), Mth.lerp(partialTicks, player.xRotO, player.getXRot())); setRotation(Mth.lerp(partialTicks, player.yRotO, player.getYRot()), Mth.lerp(partialTicks, player.xRotO, player.getXRot()));
if (!(cannon instanceof AnnihilatorEntity) && ClientEventHandler.zoomVehicle) { if (!(cannon instanceof AnnihilatorEntity) && ClientEventHandler.zoomVehicle) {