ServerEvents.recipes(event => {
	// All grist starts from cobblestone
    event.shaped('2x kubejs:grist_primordeal_basic', [
        'AAA',
        'ABA',
        'AAA'
    ], {
        'A': '#forge:cobblestone',
        'B': '#forge:gravel'
    }).id('kubejs:grist_primordeal_basic_manual_only');
    event.custom({
        type: 'create:mixing',
        ingredients: [
            '8x #forge:cobblestone',
            '#forge:gravel',
        ],
        heatRequirement: "heated",
        results: [
            '2x kubejs:grist_primordeal_basic'
        ]
    });
    event.shaped('2x kubejs:grist_primordeal_basic_block', [
        'AAA',
        'ABA',
        'AAA'
    ], {
        'A': '#forge:cobblestone',
        'B': 'kubejs:grist_essence'
    }).id('kubejs:grist_primordeal_basic_block_manual_only');
    event.custom({
        type: 'create:mixing',
        ingredients: [
            '8x #forge:cobblestone',
            'kubejs:grist_essence',
        ],
        heatRequirement: "heated",
        results: [
            '2x kubejs:grist_primordeal_basic_block'
        ]
    });
    // Conversions between fluids and items
    global.Grist.forEach(grist => {
        let id = grist.id();
        let fluidID = grist.fluid().id();
        let blockID = grist.block().id();
        event.recipes.thermal.crucible(Fluid.of(fluidID, 250), id);
        event.recipes.thermal.chiller(id, Fluid.of(fluidID, 250));
        event.recipes.createMixing(Fluid.of(fluidID, 250), id).heated();

        // convert between block and normal item
        event.shapeless(blockID, [`9x ${id}`]);
        event.shapeless(`9x ${id}`, [blockID]);

        event.custom({
            type: "industrialforegoing:dissolution_chamber",
            input: [],
            inputFluid: `{Amount:250,FluidName:\"${fluidID}\"}`,
            output: {
                count: 1,
                item: id
            },
            "processingTime": 50
        });
        event.custom({
            type: "industrialforegoing:dissolution_chamber",
            input: [
                {item: id}
            ],
            inputFluid: `{Amount:250,FluidName:\"minecraft:water\"}`,
            output: {
                count: 0,
                item: 'minecraft:air'
            },
            outputFluid: `{Amount:250,FluidName:\"${fluidID}\"}`,
            processingTime: 50
        });
    });

    // Progression along primordeals and universals
    let _ = [{from: 'basic', to: 'improved'}, {from: 'improved', to: 'radiant'}].forEach(upgrade => {
        // Primordeal progression requires one from each element of the lower tier
        event.shaped(`kubejs:grist_primordeal_${upgrade.to}`, [
            'A B',
            ' E ',
            'C D'
        ], {
            'A': `kubejs:grist_agricultural_${upgrade.from}`,
            'B': `kubejs:grist_build_${upgrade.from}`,
            'C': `kubejs:grist_energetic_${upgrade.from}`,
            'D': `kubejs:grist_intelligent_${upgrade.from}`,
            'E': `kubejs:grist_primordeal_${upgrade.from}`,
        }).id(`kubejs:grist_primordeal_${upgrade.to}_manual_only`);

        // After you've unlocked the next tier, you can use the elements of this tier plus one lower primordeal to make more primordeal
        event.shaped(`8x kubejs:grist_primordeal_${upgrade.to}_block`, [
            'AAB',
            'CEB',
            'CDD'
        ], {
            'A': `kubejs:grist_agricultural_${upgrade.to}`,
            'B': `kubejs:grist_build_${upgrade.to}`,
            'C': `kubejs:grist_energetic_${upgrade.to}`,
            'D': `kubejs:grist_intelligent_${upgrade.to}`,
            'E': `kubejs:grist_primordeal_${upgrade.from}`,
        }).id(`kubejs:grist_primordeal_${upgrade.to}_block_manual_only`);

        // Universal grist is cobble surrounded by lower tier universal and primordeal
        event.shaped(`kubejs:grist_universal_${upgrade.to}`, [
            'ABA',
            'BCB',
            'ABA'
        ], {
            'A': `kubejs:grist_universal_${upgrade.from}`,
            'B': `kubejs:grist_primordeal_${upgrade.from}`,
            'C': '#forge:cobblestone'
        }).id(`kubejs:grist_universal_${upgrade.to}_manual_only`);
    })

    // Basic primordeal gets a special case..
    event.shaped(`4x kubejs:grist_primordeal_basic_block`, [
        'AAB',
        'CEB',
        'CDD'
    ], {
        'A': `kubejs:grist_agricultural_basic`,
        'B': `kubejs:grist_build_basic`,
        'C': `kubejs:grist_energetic_basic`,
        'D': `kubejs:grist_intelligent_basic`,
        'E': '#forge:cobblestone',
    }).id('kubejs:grist_primordeal_basic_block_manual_only');
    event.custom({
        type: 'create:mixing',
        ingredients: [
            '2x kubejs:grist_agricultural_basic',
            '2x kubejs:grist_build_basic',
            '2x kubejs:grist_energetic_basic',
            '2x kubejs:grist_intelligent_basic',
            '#forge:cobblestone',
        ],
        heatRequirement: "heated",
        results: [
            '4x kubejs:grist_primordeal_basic_block'
        ]
    });

    // Finally, start creative-tier grist
    event.shaped('kubejs:grist_universal_basic', [
        'A B',
        ' E ',
        'C D'
    ], {
        'A': '#kubejs:grist/agricultural/radiant',
        'B': '#kubejs:grist/build/radiant',
        'C': '#kubejs:grist/energetic/radiant',
        'D': '#kubejs:grist/intelligent/radiant',
        'E': '#kubejs:grist/primordeal/radiant'
    }).id('kubejs:grist_universal_basic_block_manual_only');
});