package top.leisuretimedock.dglabgame.client.gui;

import com.lowdragmc.lowdraglib.gui.modular.IUIHolder;
import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.lowdragmc.lowdraglib.gui.modular.ModularUIGuiContainer;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public interface ILdlibGui {
    WidgetGroup createGui();
    @OnlyIn(Dist.CLIENT)
    default void display() {
        WidgetGroup gui = createGui();
        if (gui != null) {
            Minecraft minecraft = Minecraft.getInstance();
            ModularUI modularUI = new ModularUI(gui, IUIHolder.EMPTY, minecraft.player);
            modularUI.initWidgets();
            ModularUIGuiContainer guiScreen = null;
            if (minecraft.player != null) {
                guiScreen = new ModularUIGuiContainer(modularUI, minecraft.player.containerMenu.containerId);
            }
            minecraft.setScreen(guiScreen);
            if (guiScreen != null) {
                minecraft.player.containerMenu = guiScreen.getMenu();
            }
        }
    }
}
