优化部分代码
This commit is contained in:
parent
30be20c0b0
commit
654cd23a14
7 changed files with 15 additions and 23 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue