package net.halbear.skyboxmod.utility;

import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.ColorTargetState;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.halbear.skyboxmod.SkyboxMod;
import net.halbear.skyboxmod.rendering.skybox.SkyBoxRendering;
import net.minecraft.resources.Identifier;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RegisterRenderPipelinesEvent;

import static net.minecraft.client.renderer.RenderPipelines.MATRICES_PROJECTION_SNIPPET;

@EventBusSubscriber(modid = SkyboxMod.MODID, value = Dist.CLIENT)
public class ModEventHandler {

    @SubscribeEvent
    public static void onRegisterPipelines(RegisterRenderPipelinesEvent event) {
        SkyBoxRendering.CUSTOM_SKYBOX_PIPELINE = RenderPipeline.builder(new RenderPipeline.Snippet[]{MATRICES_PROJECTION_SNIPPET})
                .withLocation(Identifier.fromNamespaceAndPath(SkyboxMod.MODID, "pipeline/custom_skybox"))
                .withVertexShader(Identifier.withDefaultNamespace("core/position_tex"))
                .withFragmentShader(Identifier.withDefaultNamespace("core/position_tex"))
                .withSampler("Sampler0")
                .withCull(false)
                .withColorTargetState(new ColorTargetState(BlendFunction.TRANSLUCENT)).withVertexFormat(DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.QUADS).build();

        event.registerPipeline(SkyBoxRendering.CUSTOM_SKYBOX_PIPELINE);
        System.out.println("Hal's Skybox Mod pipeline Registered");
    }
}