优化部分代码

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;
public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundInstance {
private final Minecraft client;
private final Entity entity;
private double lastDistance;
@ -27,6 +28,7 @@ public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundIns
protected abstract float getPitch(Entity entity);
protected abstract float getVolume(Entity entity);
@Override
public void tick() {
var player = this.client.player;
@ -64,7 +66,7 @@ public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundIns
this.lastDistance = 0;
}
}
public static class EntitySound extends LoudlyEntitySoundInstance {
public EntitySound(Entity entity) {
super(entity instanceof LoudlyEntity loudlyEntity ? loudlyEntity.getSound() : null, Minecraft.getInstance(), entity);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,12 +23,9 @@ public class ClientSoundHandler {
if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) {
Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle));
}
if (event.getEntity() instanceof LoudlyEntity loudlyEntity) {
if (event.getEntity() instanceof LoudlyEntity) {
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()));
}
}
}