onEvent('recipes', e => {
    let colors = ['white', 'orange', 'magenta', 'light_blue', 'yellow', 'lime', 'pink', 'gray', 'light_gray', 'cyan', 'purple', 'blue', 'brown', 'green', 'red', 'black']

    colors.forEach(color => {
        //===== remove recipes =====//
        if (color !== 'white') {
            removeRecipeByID(e, [
                `minecraft:${color}_wool`,
                `minecraft:${color}_carpet_from_white_carpet`,
                `minecraft:${color}_stained_glass_plane_from_glass_pane`
            ]);
        };
        //===== readd recipe from colorless =====//
        e.shaped(`minecraft:${color}_stained_glass_pane`, ['CCC', 'CDC', 'CCC'], {
            D: `#forge:dyes/${color}`,
            C: 'minecraft:glass_pane'
        }).id(`kubejs:minecraft/${color}_stained_glass_pane`);
    });
    //code inproved by AI

    function extractID(str) {
        const match = str.match(/(.*?)(:)(.*?)color(.*$)/);
        if (match === null) {
            throw new Error(`Failed to extract ID from string: "${str}"`);
        }
        return [match[1], match[3], match[4]];
    }

    function buildColorConversion(str, type) {
        const colorRegex = new RegExp(colors.join('|'), 'i');
        str = str.replace(colorRegex, 'color');

        const itemID = extractID(str);
        
        colors.forEach(color => {
            let altColorItem = colors.filter(c => c !== color).map(c => str.replace('color', c));
            let outputItem = `${itemID[0]}:${itemID[1]}${color}${itemID[2]}`;

            if (type == 0) {
                e.shaped(Item.of(outputItem, 8), ['CCC', 'CDC', 'CCC'], {
                    D: `#forge:dyes/${color}`,
                    C: altColorItem
                }).id(`kubejs:${outputItem.replace(':', '/')}`);
            }
            if (type == 1) {
                e.shapeless(outputItem, [`#forge:dyes/${color}`, altColorItem]).id(`kubejs:${outputItem.replace(':', '/')}`);
            }
        });
    }

    buildColorConversion('minecraft:white_wool', 1);
    buildColorConversion('minecraft:white_bed', 1);
    buildColorConversion('minecraft:white_stained_glass', 0);
    buildColorConversion('minecraft:white_stained_glass_pane', 0);
    buildColorConversion('minecraft:white_carpet', 0);
    utils.listOf([
        'connectedglass:borderless_glass_white',
        'connectedglass:borderless_glass_white_pane',
        'connectedglass:clear_glass_white',
        'connectedglass:clear_glass_white_pane',
        'connectedglass:scratched_glass_white',
        'connectedglass:scratched_glass_white_pane',
        'connectedglass:tinted_borderless_glass_white'
    ]).forEach(glass =>  buildColorConversion(glass, 0));

});