优化部分代码

This commit is contained in:
17146 2025-05-06 16:38:44 +08:00 committed by Light_Quanta
parent 30be20c0b0
commit 654cd23a14
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 15 additions and 23 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundInstance { public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundInstance {
private final Minecraft client; private final Minecraft client;
private final Entity entity; private final Entity entity;
private double lastDistance; private double lastDistance;
@ -27,6 +28,7 @@ public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundIns
protected abstract float getPitch(Entity entity); protected abstract float getPitch(Entity entity);
protected abstract float getVolume(Entity entity); protected abstract float getVolume(Entity entity);
@Override @Override
public void tick() { public void tick() {
var player = this.client.player; var player = this.client.player;

View file

@ -14,6 +14,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
public abstract class VehicleSoundInstance extends AbstractTickableSoundInstance { public abstract class VehicleSoundInstance extends AbstractTickableSoundInstance {
private final Minecraft client; private final Minecraft client;
private final MobileVehicleEntity mobileVehicle; private final MobileVehicleEntity mobileVehicle;
private double lastDistance; private double lastDistance;

View file

@ -1,11 +1,18 @@
package com.atsuishio.superbwarfare.entity; package com.atsuishio.superbwarfare.entity;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import org.jetbrains.annotations.NotNull;
public interface LoudlyEntity { public interface LoudlyEntity {
SoundEvent getCloseSound (); @NotNull
SoundEvent getSound (); default SoundEvent getCloseSound() {
return SoundEvents.EMPTY;
}
@NotNull
SoundEvent getSound();
float getVolume(); float getVolume();
} }

View file

@ -335,11 +335,6 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
super.onRemovedFromLevel(); super.onRemovedFromLevel();
} }
@Override
public SoundEvent getCloseSound() {
return null;
}
@Override @Override
public SoundEvent getSound() { public SoundEvent getSound() {
return ModSounds.SHELL_FLY.get(); return ModSounds.SHELL_FLY.get();

View file

@ -284,11 +284,6 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
level.addFreshEntity(cloud); level.addFreshEntity(cloud);
} }
@Override
public SoundEvent getCloseSound() {
return null;
}
@Override @Override
public SoundEvent getSound() { public SoundEvent getSound() {
return ModSounds.SHELL_FLY.get(); return ModSounds.SHELL_FLY.get();

View file

@ -290,11 +290,6 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
return true; return true;
} }
@Override
public SoundEvent getCloseSound() {
return null;
}
@Override @Override
public SoundEvent getSound() { public SoundEvent getSound() {
return ModSounds.DRONE_SOUND.get(); return ModSounds.DRONE_SOUND.get();

View file

@ -23,13 +23,10 @@ public class ClientSoundHandler {
if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) { if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) {
Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle)); Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle));
} }
if (event.getEntity() instanceof LoudlyEntity) {
if (event.getEntity() instanceof LoudlyEntity loudlyEntity) {
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(event.getEntity())); Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(event.getEntity()));
if (loudlyEntity.getCloseSound() != null) {
Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(event.getEntity())); Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(event.getEntity()));
} }
} }
} }
}
} }