// >>> Colorful Lighting auto-patch (do not edit) >>>
#ifndef COLORFUL_LIGHTING_PATCH
#define COLORFUL_LIGHTING_PATCH
vec3 cl_tint = vec3(1.0);
float cl_blockW = 0.0;
float cl_washW = 0.0;   // hue strength after skylight washout; 0.35 floor keeps color visible at noon
float cl_colored = 0.0; // 1.0 when this vertex carries colored-light data
uniform float cl_skyWash; // day/night-aware sky wash strength, set via shaders.properties; 0.0 if absent
vec4 cl_decodeLight(vec4 cl_raw) {
    float cl_x = cl_raw.x;
    float cl_y = cl_raw.y;
    if (cl_x < 0.0) cl_x += 65536.0;
    if (cl_y < 0.0) cl_y += 65536.0;
    if (cl_y < 61440.0) return cl_raw;
    float cl_sky4 = mod(cl_y, 16.0);
    float cl_b = floor(mod(cl_y, 4096.0) * 0.0625);
    float cl_g = floor(cl_x * 0.00390625);
    float cl_r = cl_x - cl_g * 256.0;
    float cl_m = max(cl_r, max(cl_g, cl_b));
    if (cl_m > 0.5) {
        cl_tint = vec3(cl_r, cl_g, cl_b) / cl_m;
        cl_colored = 1.0;
        cl_washW = max(0.35, 1.0 - cl_skyWash * cl_sky4 * 0.0666667);
    }
    cl_blockW = clamp(cl_m * 0.00392157, 0.0, 1.0) * cl_washW;
    return vec4(cl_m * 0.94117647 + 8.0, cl_sky4 * 16.0 + 8.0, cl_raw.z, cl_raw.w);
}
#endif
// <<< Colorful Lighting auto-patch <<<

attribute vec2 mc_Entity;

uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;

varying vec4 v_Color;
varying vec2 v_TexCoord, v_LMCoord;
varying vec3 v_Normal;
varying vec3 v_EmissiveColor;

void main() {
    vec3 pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
    pos = (gbufferModelViewInverse * vec4(pos, 1.0)).xyz;

    gl_Position = gl_ProjectionMatrix * gbufferModelView * vec4(pos, 1.0);
    gl_FogFragCoord = length(pos);

    v_Normal = gl_NormalMatrix * gl_Normal;
    v_Normal = (gbufferModelViewInverse * vec4(v_Normal, 0.0)).xyz;

    v_Color = vec4(gl_Color.rgb, gl_Color.a);
    v_TexCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
    v_LMCoord = (gl_TextureMatrix[1] * cl_decodeLight(gl_MultiTexCoord1)).xy;

    // v_EmissiveColor = vec3(0.0);
    // switch (int(mc_Entity.x)) {
    //     case 10001: {
    //         v_EmissiveColor = vec3(1.0, 0.0, 0.0);
    //         break;
    //     }
    //     case 10002: {
    //         v_EmissiveColor = vec3(1.0, 0.5, 0.1);
    //         break;
    //     }
    //     case 10003: {
    //         v_EmissiveColor = vec3(1.0, 0.9, 0.3);
    //         break;
    //     }
    //     case 10004: {
    //         v_EmissiveColor = vec3(0.6, 0.9, 0.6);
    //         break;
    //     }
    //     case 10005: {
    //         v_EmissiveColor = vec3(0.2, 0.9, 1.0);
    //         break;
    //     }
    //     case 10006: {
    //         v_EmissiveColor = vec3(0.5, 1.0, 0.85);
    //         break;
    //     }
    //     case 10007: {
    //         v_EmissiveColor = vec3(0.6, 0.2, 1.0);
    //         break;
    //     }
    //     case 10008: {
    //         v_EmissiveColor = vec3(0.8, 0.9, 1.0);
    //         break;
    //     }
    //     default: break;
    // }
    v_Color.rgb *= mix(vec3(1.0), cl_tint, cl_blockW); // Colorful Lighting
}
