ServerEvents.recipes(event => {
    //======== the below code is broken ========//
    // event.forEachRecipe({
    //     type: "create:milling",
    //     input: '#minecraft:flowers',
    // }, original => {
    //     let ingredients = original.get("ingredients");
    //     let results = original.get("results");
    //     console.log(JSON.stringify(ingredients), JSON.stringify(results));
    //     let newResults = Array(results.length + 1);
    //     for (let i = 0; i < results.length; i++) {
    //         newResults[i] = results[i];
    //     }
    //     newResults[results.length] = Item.of('kubejs:pollen').withChance(0.25);
    //     event.recipes.create.crushing(
    //         newResults,
    //         ingredients,
    //     ).processingTime(original.get('processingTime'));
    // });

    const {crushing} = event.recipes.create;
    // "minecraft:azure_bluet", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:light_gray_dye", 2),
            Item.of("minecraft:white_dye", 2).withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:azure_bluet",
    ).processingTime(50);
    // "minecraft:allium", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:magenta_dye", 2),
            Item.of("minecraft:purple_dye", 2).withChance(0.1),
            Item.of("minecraft:pink_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:allium",
    ).processingTime(50);
    // "minecraft:lilac", "processingTime": 100
    crushing(
        [
            Item.of("minecraft:magenta_dye", 3),
            Item.of("minecraft:magenta_dye").withChance(0.25),
            Item.of("minecraft:purple_dye").withChance(0.25),
            Item.of("kubejs:pollen").withChance(0.75),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:lilac",
    ).processingTime(100);
    // "minecraft:sunflower", "processingTime": 100
    crushing(
        [
            Item.of("minecraft:yellow_dye", 3),
            Item.of("minecraft:yellow_dye").withChance(0.25),
            Item.of("minecraft:orange_dye").withChance(0.25),
            Item.of("kubejs:pollen").withChance(0.75),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:sunflower",
    ).processingTime(100);
    // "minecraft:white_tulip", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:white_dye", 2),
            Item.of("minecraft:lime_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:white_tulip",
    ).processingTime(50);
    // "minecraft:lily_of_the_valley", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:white_dye", 2),
            Item.of("minecraft:white_dye").withChance(0.1),
            Item.of("minecraft:lime_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:lily_of_the_valley",
    ).processingTime(50);
    // "minecraft:pink_tulip", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:pink_dye", 2),
            Item.of("minecraft:lime_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:pink_tulip",
    ).processingTime(50);
    // "minecraft:wither_rose", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:black_dye", 2),
            Item.of("minecraft:black_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:wither_rose",
    ).processingTime(50);
    // "minecraft:orange_tulip", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:orange_dye", 2),
            Item.of("minecraft:lime_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:orange_tulip",
    ).processingTime(50);
    // "minecraft:blue_orchid", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:light_blue_dye", 2),
            Item.of("minecraft:light_gray_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:blue_orchid",
    ).processingTime(50);
    // "minecraft:dandelion", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:yellow_dye", 2),
            Item.of("minecraft:yellow_dye").withChance(0.05),
            Item.of("kubejs:pollen").withChance(0.5),
        ],
        "minecraft:dandelion",
    ).processingTime(50);
    // "minecraft:peony", "processingTime": 100
    crushing(
        [
            Item.of("minecraft:pink_dye", 3),
            Item.of("minecraft:pink_dye").withChance(0.25),
            Item.of("minecraft:magenta_dye").withChance(0.25),
            Item.of("kubejs:pollen").withChance(0.75),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:peony",
    ).processingTime(100);
    // "minecraft:rose_bush", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:red_dye", 3),
            Item.of("minecraft:red_dye", 2).withChance(0.25),
            Item.of("minecraft:green_dye", 2).withChance(0.05),
            Item.of("kubejs:pollen").withChance(0.75),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:rose_bush",
    ).processingTime(50);
    // "minecraft:oxeye_daisy", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:light_gray_dye", 2),
            Item.of("minecraft:white_dye").withChance(0.2),
            Item.of("minecraft:yellow_dye").withChance(0.05),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:oxeye_daisy",
    ).processingTime(50);
    // "minecraft:red_tulip", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:red_dye", 2),
            Item.of("minecraft:lime_dye").withChance(0.1),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:red_tulip",
    ).processingTime(50);
    // "minecraft:poppy", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:red_dye", 2),
            Item.of("minecraft:green_dye").withChance(0.05),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:poppy",
    ).processingTime(50);
    // "minecraft:cornflower", "processingTime": 50
    crushing(
        [
            Item.of("minecraft:blue_dye", 2),
            Item.of("kubejs:pollen").withChance(0.25),
        ],
        "minecraft:cornflower",
    ).processingTime(50);
});

BlockEvents.rightClicked('minecraft:grass_block', event => {
    const {player, block, item, level} = event;
    if (item.id === "kubejs:pollen") {
        if (block.up.id != "minecraft:air") {
            return;
        }
        player.swing(event.hand, true);
        if (!player.creative) {
            item.count -= 1;
        }
        level.spawnParticles(
            "minecraft:happy_villager", true,
            block.x + 0.5, block.y + 1, block.z + 0.5,
            0.5, 0.5, 0.5,
            4, 0.1
        );
        event.level.runCommandSilent(`/playsound minecraft:item.bone_meal.use block @a ${block.x + 0.5} ${block.y + 1} ${block.z + 0.5} 1 1 1`);
        player.playSound("minecraft:item.bone_meal.use", 1.0, 1.0);
        if (Math.random() > 0.1) {
            return;
        }
        const FLOWERS = [
            "minecraft:dandelion",
            "minecraft:poppy",
            "minecraft:blue_orchid",
            "minecraft:allium",
            "minecraft:azure_bluet",
            "minecraft:red_tulip",
            "minecraft:orange_tulip",
            "minecraft:white_tulip",
            "minecraft:pink_tulip",
            "minecraft:oxeye_daisy",
            "minecraft:cornflower",
            "minecraft:lily_of_the_valley",
            "minecraft:sunflower",
            "minecraft:lilac",
            "minecraft:rose_bush",
            "minecraft:peony",
        ];
        const flowerID = FLOWERS[Math.floor(Math.random() * FLOWERS.length)];
        block.up.set(flowerID);
        return;
    }
});