package me.km.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
import static me.km.utils.ReflectionUtils.getField;
import static me.km.utils.ReflectionUtils.getMethod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.overlay.BossOverlayGui;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.entity.Entity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;

@OnlyIn(Dist.CLIENT)
public class ClientReflectionUtils {
    private final static Method CAN_RENDER_NAME =
            getMethod(EntityRenderer.class, "func_177070_b", Entity.class);

    public static boolean canRenderName(EntityRenderer<?> lr, Entity liv) {
        try {
            return (boolean) CAN_RENDER_NAME.invoke(lr, liv);
        } catch (Exception ex) {
            LogManager.getLogger().warn("canRenderName - " + ex);
            return false;
        }
    }

    private final static Field BOSS_BAR_MAP = getField(BossOverlayGui.class, "field_184060_g");

    public static boolean isRenderingBossBar() {
        Minecraft mc = Minecraft.getInstance();
        return !ReflectionUtils
                .getFieldValue(Map.class, mc.ingameGUI.getBossOverlay(), BOSS_BAR_MAP).isEmpty();
    }
}
