// priority: 0


    (function () {
        console.info('[EH] Loading custom JEI conversions (crushing_hammers)...');

        // unique per file
        var CATEGORY_ID = 'kubejs:crushing_hammers';

        // data
        var CustomConversions = [
            { input: 'minecraft:stone', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:cobblestone', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:gravel', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:sand', description: ' In                            Out' },
            { input: 'minecraft:sand', catalystBlock: 'ex_hammers:stone_hammer', output: 'ex_hammers:dust', description: ' In                            Out' },
            { input: 'minecraft:stone', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:cobblestone', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:gravel', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:sand', description: ' In                            Out' },
            { input: 'minecraft:sand', catalystBlock: 'ex_hammers:iron_hammer', output: 'ex_hammers:dust', description: ' In                            Out' },
            { input: 'minecraft:stone', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:cobblestone', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:gravel', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:sand', description: ' In                            Out' },
            { input: 'minecraft:sand', catalystBlock: 'ex_hammers:diamond_hammer', output: 'ex_hammers:dust', description: ' In                            Out' },
            { input: 'minecraft:stone', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:cobblestone', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:gravel', description: ' In                            Out' },
            { input: 'minecraft:gravel', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:sand', description: ' In                            Out' },
            { input: 'minecraft:sand', catalystBlock: 'ex_hammers:netherite_hammer', output: 'ex_hammers:dust', description: ' In                            Out' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'ex_hammers:plant_fiber', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'ex_hammers:plant_fiber', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'ex_hammers:plant_fiber', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'ex_hammers:plant_fiber', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'gtceu:rubber_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'gtceu:rubber_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'gtceu:rubber_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'gtceu:rubber_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:spruce_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:spruce_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:spruce_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:spruce_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:birch_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:birch_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:birch_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:birch_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:jungle_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:jungle_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:jungle_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:jungle_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:acacia_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:acacia_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:acacia_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:acacia_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:dark_oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:dark_oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:dark_oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:dark_oak_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:mangrove_propagule', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:mangrove_propagule', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:mangrove_propagule', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:mangrove_propagule', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'minecraft:flowering_azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'minecraft:flowering_azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'minecraft:flowering_azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'minecraft:flowering_azalea', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'vinery:dark_cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'vinery:dark_cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'vinery:dark_cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'vinery:dark_cherry_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:stone_hammer', output: 'vinery:apple_tree_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:iron_hammer', output: 'vinery:apple_tree_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:diamond_hammer', output: 'vinery:apple_tree_sapling', description: ' Sapling or Plant Fiber' },
            { input: 'minecraft:dirt', catalystBlock: 'ex_hammers:netherite_hammer', output: 'vinery:apple_tree_sapling', description: ' Sapling or Plant Fiber' },
        ];

        function err(msg) { console.error('[EH] ' + msg); }

        function verifyRecipe(recipe) {
            return !!(recipe && recipe.data && recipe.data.input && recipe.data.catalystBlock && recipe.data.output);
        }

        function handleLookup(builder, recipe, focuses) {
            try {
                if (!verifyRecipe(recipe)) return;

                var inStack = Item.of(String(recipe.data.input));
                var catalystStack = Item.of(String(recipe.data.catalystBlock));
                var outStack = Item.of(String(recipe.data.output));

                builder.addSlot('INPUT', 0, 0)
                    .addItemStack(inStack)
                    .setSlotName('input');

                builder.addSlot('CATALYST', 43, 0)
                    .addItemStack(catalystStack)
                    .setSlotName('catalyst');

                builder.addSlot('OUTPUT', 84, 0)
                    .addItemStack(outStack)
                    .setSlotName('output');

                builder.addInvisibleIngredients('INPUT').addItemStack(inStack);
                builder.addInvisibleIngredients('CATALYST').addItemStack(catalystStack);
                builder.addInvisibleIngredients('OUTPUT').addItemStack(outStack);

            } catch (e) {
                err('handleLookup error: ' + String(e));
            }
        }

        function render(recipe, recipeSlotsView, guiGraphics, mouseX, mouseY) {
            try {
                if (!verifyRecipe(recipe)) return;

                var desc = (recipe.data.description) ? String(recipe.data.description) : '';
                if (desc.length > 0) {
                    guiGraphics.drawWordWrap(Client.font, Text.of(desc), 0, 20, 160, 50);
                }
            } catch (e) {
                err('draw error: ' + String(e));
            }
        }

        JEIAddedEvents.registerCategories(function (event) {
            var guiHelper = event.JEI_HELPERS.guiHelper;

            event.custom(CATEGORY_ID, function (category) {
                category.width = 100;
                category.height = 30;

                category
                    .title('Crushing Hammers')
                    .background(guiHelper.createBlankDrawable(100, 50))
                    .icon(guiHelper.createDrawableItemStack(Item.of('ex_hammers:diamond_hammer')))
                    .isRecipeHandled(function (recipe) { return verifyRecipe(recipe); })
                    .handleLookup(function (builder, recipe, focuses) { handleLookup(builder, recipe, focuses); })
                    .setDrawHandler(function (recipe, recipeSlotsView, guiGraphics, mouseX, mouseY) {
                        render(recipe, recipeSlotsView, guiGraphics, mouseX, mouseY);
                    });
            });
        });

        JEIAddedEvents.registerRecipes(function (event) {
            var cat = event.custom(CATEGORY_ID);

            for (var i = 0; i < CustomConversions.length; i++) {
                var entry = CustomConversions[i];
                cat.add({
                    input: entry.input,
                    catalystBlock: entry.catalystBlock,
                    output: entry.output,
                    description: entry.description || ''
                });
            }

            console.info('[EH] Registered ' + CustomConversions.length + ' custom conversion JEI entries (' + CATEGORY_ID + ').');
        });
    })();
