package net.minecraft.client.resources.sounds;

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

public abstract class AbstractSoundInstance implements SoundInstance {
    protected Sound sound;
    protected final SoundSource source;
    protected final ResourceLocation location;
    protected float volume;
    protected float pitch;
    protected double x;
    protected double y;
    protected double z;
    protected boolean looping;
    protected int delay;
    protected Attenuation attenuation;
    protected boolean priority;
    protected boolean relative;
    
    protected AbstractSoundInstance(final SoundEvent ack, final SoundSource acm) {
        this(ack.getLocation(), acm);
    }
    
    protected AbstractSoundInstance(final ResourceLocation uh, final SoundSource acm) {
        this.volume = 1.0f;
        this.pitch = 1.0f;
        this.attenuation = Attenuation.LINEAR;
        this.location = uh;
        this.source = acm;
    }
    
    @Override
    public ResourceLocation getLocation() {
        return this.location;
    }
    
    @Override
    public WeighedSoundEvents resolve(final SoundManager epn) {
        final WeighedSoundEvents epo3 = epn.getSoundEvent(this.location);
        if (epo3 == null) {
            this.sound = SoundManager.EMPTY_SOUND;
        }
        else {
            this.sound = epo3.getSound();
        }
        return epo3;
    }
    
    @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 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;
    }
    
    @Override
    public String toString() {
        return "SoundInstance[" + this.location + "]";
    }
}
