package com.trunksbomb.minetriad;

import com.trunksbomb.minetriad.client.render.FirstPersonCardHandRenderer;
import com.trunksbomb.minetriad.client.render.DuelTableBlockEntityRenderer;
import com.trunksbomb.minetriad.client.screen.CardBinderScreen;
import com.trunksbomb.minetriad.registry.TriadItems;
import com.trunksbomb.minetriad.registry.TriadBlockEntities;
import com.trunksbomb.minetriad.registry.TriadMenus;

import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.gui.screens.MenuScreens;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.client.event.RenderHandEvent;

@Mod(value = MineTriad.MOD_ID, dist = Dist.CLIENT)
public final class MineTriadClient {
    public MineTriadClient(IEventBus modEventBus) {
    }

    @EventBusSubscriber(modid = MineTriad.MOD_ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
    public static final class ClientModEvents {
        @SubscribeEvent
        public static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
            event.registerBlockEntityRenderer(TriadBlockEntities.DUEL_TABLE.get(), DuelTableBlockEntityRenderer::new);
        }

        @SubscribeEvent
        public static void registerScreens(RegisterMenuScreensEvent event) {
            event.register(TriadMenus.CARD_BINDER.get(), CardBinderScreen::new);
        }
    }

    @EventBusSubscriber(modid = MineTriad.MOD_ID, value = Dist.CLIENT)
    public static final class ClientGameEvents {
        @SubscribeEvent
        public static void onRenderHand(RenderHandEvent event) {
            if (!event.getItemStack().is(TriadItems.TRIAD_CARD.get())) {
                return;
            }

            event.setCanceled(true);
            FirstPersonCardHandRenderer.render(
                    event.getHand(),
                    event.getPoseStack(),
                    event.getMultiBufferSource(),
                    event.getPackedLight(),
                    event.getInterpolatedPitch(),
                    event.getSwingProgress(),
                    event.getEquipProgress(),
                    event.getItemStack());
        }
    }
}
