package top.azimkin.militaryarmor;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.renderer.GeoArmorRenderer;

import java.util.function.Supplier;

@OnlyIn(Dist.CLIENT)
public class ClientItemExtensions implements IClientItemExtensions {
    private final Supplier<? extends GeoArmorRenderer<?>> rendererSupplier;
    private GeoArmorRenderer<?> renderer;

    protected ClientItemExtensions(Supplier<? extends GeoArmorRenderer<?>> renderSupplier) {
        this.rendererSupplier = renderSupplier;
    }

    @Override
    public @NotNull HumanoidModel<?> getHumanoidArmorModel(LivingEntity livingEntity, ItemStack itemStack, EquipmentSlot equipmentSlot, HumanoidModel<?> original) {
        if (renderer == null) {
            renderer = rendererSupplier.get();
        }

        renderer.prepForRender(livingEntity, itemStack, equipmentSlot, original);

        return renderer;
    }
}
