122 lines
2.8 KiB
Java
122 lines
2.8 KiB
Java
package net.minecraft.client.resources.sounds;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.resources.sounds.SoundInstance.Attenuation;
|
|
import net.minecraft.client.sounds.SoundManager;
|
|
import net.minecraft.client.sounds.WeighedSoundEvents;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.util.RandomSource;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public abstract class AbstractSoundInstance implements SoundInstance {
|
|
protected Sound sound;
|
|
protected final SoundSource source;
|
|
protected final ResourceLocation location;
|
|
protected float volume = 1.0F;
|
|
protected float pitch = 1.0F;
|
|
protected double x;
|
|
protected double y;
|
|
protected double z;
|
|
protected boolean looping;
|
|
/**
|
|
* The number of ticks between repeating the sound
|
|
*/
|
|
protected int delay;
|
|
protected Attenuation attenuation = Attenuation.LINEAR;
|
|
protected boolean relative;
|
|
protected RandomSource random;
|
|
|
|
protected AbstractSoundInstance(SoundEvent soundEvent, SoundSource source, RandomSource random) {
|
|
this(soundEvent.location(), source, random);
|
|
}
|
|
|
|
protected AbstractSoundInstance(ResourceLocation location, SoundSource source, RandomSource random) {
|
|
this.location = location;
|
|
this.source = source;
|
|
this.random = random;
|
|
}
|
|
|
|
@Override
|
|
public ResourceLocation getLocation() {
|
|
return this.location;
|
|
}
|
|
|
|
@Override
|
|
public WeighedSoundEvents resolve(SoundManager manager) {
|
|
if (this.location.equals(SoundManager.INTENTIONALLY_EMPTY_SOUND_LOCATION)) {
|
|
this.sound = SoundManager.INTENTIONALLY_EMPTY_SOUND;
|
|
return SoundManager.INTENTIONALLY_EMPTY_SOUND_EVENT;
|
|
} else {
|
|
WeighedSoundEvents weighedSoundEvents = manager.getSoundEvent(this.location);
|
|
if (weighedSoundEvents == null) {
|
|
this.sound = SoundManager.EMPTY_SOUND;
|
|
} else {
|
|
this.sound = weighedSoundEvents.getSound(this.random);
|
|
}
|
|
|
|
return weighedSoundEvents;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Sound getSound() {
|
|
return this.sound;
|
|
}
|
|
|
|
@Override
|
|
public SoundSource getSource() {
|
|
return this.source;
|
|
}
|
|
|
|
@Override
|
|
public boolean isLooping() {
|
|
return this.looping;
|
|
}
|
|
|
|
@Override
|
|
public int getDelay() {
|
|
return this.delay;
|
|
}
|
|
|
|
@Override
|
|
public float getVolume() {
|
|
return this.volume * this.sound.getVolume().sample(this.random);
|
|
}
|
|
|
|
@Override
|
|
public float getPitch() {
|
|
return this.pitch * this.sound.getPitch().sample(this.random);
|
|
}
|
|
|
|
@Override
|
|
public double getX() {
|
|
return this.x;
|
|
}
|
|
|
|
@Override
|
|
public double getY() {
|
|
return this.y;
|
|
}
|
|
|
|
@Override
|
|
public double getZ() {
|
|
return this.z;
|
|
}
|
|
|
|
@Override
|
|
public Attenuation getAttenuation() {
|
|
return this.attenuation;
|
|
}
|
|
|
|
@Override
|
|
public boolean isRelative() {
|
|
return this.relative;
|
|
}
|
|
|
|
public String toString() {
|
|
return "SoundInstance[" + this.location + "]";
|
|
}
|
|
}
|