package com.acethewildfire.acesbs.sounds;

import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;

public class PlayerAttachedSound extends MovingSoundInstance {

    private final PlayerEntity player;

    public PlayerAttachedSound(PlayerEntity player, SoundEvent sound) {
        super(sound, SoundCategory.PLAYERS, SoundInstance.createRandom());
        this.player = player;
        this.repeat = true;
        this.repeatDelay = 0;
        this.volume = 1.0f;
    }

    @Override
    public void tick() {
        if (player.isRemoved() || player.isDead()) {
            setDone();
            return;
        }

        this.x = (float) player.getX();
        this.y = (float) player.getEyeY();
        this.z = (float) player.getZ();
    }
}
