package net.minecraft.client.resources.sounds;

import net.minecraft.client.sounds.SoundManager;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource;
import javax.annotation.Nullable;
import net.minecraft.client.sounds.WeighedSoundEvents;

public abstract class AbstractSoundInstance implements SoundInstance {
    protected Sound sound;
    @Nullable
    private WeighedSoundEvents soundEvent;
    protected final SoundSource source;
    protected final ResourceLocation location;
    protected float volume;
    protected float pitch;
    protected float x;
    protected float y;
    protected float z;
    protected boolean looping;
    protected int delay;
    protected Attenuation attenuation;
    protected boolean priority;
    protected boolean relative;
    
    protected AbstractSoundInstance(final SoundEvent aah, final SoundSource aaj) {
        this(aah.getLocation(), aaj);
    }
    
    protected AbstractSoundInstance(final ResourceLocation sm, final SoundSource aaj) {
        this.volume = 1.0f;
        this.pitch = 1.0f;
        this.attenuation = Attenuation.LINEAR;
        this.location = sm;
        this.source = aaj;
    }
    
    @Override
    public ResourceLocation getLocation() {
        return this.location;
    }
    
    @Override
    public WeighedSoundEvents resolve(final SoundManager edz) {
        this.soundEvent = edz.getSoundEvent(this.location);
        if (this.soundEvent == null) {
            this.sound = SoundManager.EMPTY_SOUND;
        }
        else {
            this.sound = this.soundEvent.getSound();
        }
        return this.soundEvent;
    }
    
    @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();
    }
    
    @Override
    public float getPitch() {
        return this.pitch * this.sound.getPitch();
    }
    
    @Override
    public float getX() {
        return this.x;
    }
    
    @Override
    public float getY() {
        return this.y;
    }
    
    @Override
    public float getZ() {
        return this.z;
    }
    
    @Override
    public Attenuation getAttenuation() {
        return this.attenuation;
    }
    
    @Override
    public boolean isRelative() {
        return this.relative;
    }
}
