diff --git a/src/main/java/com/atsuishio/superbwarfare/client/LoudlyEntitySoundInstance.java b/src/main/java/com/atsuishio/superbwarfare/client/LoudlyEntitySoundInstance.java index f21105a9d..9dc2fc6b7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/LoudlyEntitySoundInstance.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/LoudlyEntitySoundInstance.java @@ -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); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/VehicleSoundInstance.java b/src/main/java/com/atsuishio/superbwarfare/client/VehicleSoundInstance.java index 14b92d1fa..ff5667e73 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/VehicleSoundInstance.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/VehicleSoundInstance.java @@ -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; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/LoudlyEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/LoudlyEntity.java index c3433a249..487426b9d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/LoudlyEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/LoudlyEntity.java @@ -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(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java index 4bc9c49f0..cdc4d41a8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/CannonShellEntity.java @@ -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(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java index 1e3e1566d..177a01e48 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java @@ -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(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java index 47755055f..201cb517c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/SwarmDroneEntity.java @@ -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(); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java index 0740b294f..9d028014e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java @@ -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())); } } }