优化部分代码
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;
|
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;
|
||||||
|
@ -64,7 +66,7 @@ public abstract class LoudlyEntitySoundInstance extends AbstractTickableSoundIns
|
||||||
this.lastDistance = 0;
|
this.lastDistance = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EntitySound extends LoudlyEntitySoundInstance {
|
public static class EntitySound extends LoudlyEntitySoundInstance {
|
||||||
public EntitySound(Entity entity) {
|
public EntitySound(Entity entity) {
|
||||||
super(entity instanceof LoudlyEntity loudlyEntity ? loudlyEntity.getSound() : null, Minecraft.getInstance(), 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;
|
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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -23,12 +23,9 @@ 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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue