import { world, system, ItemStack, ItemTypes, Dimension } from "@minecraft/server";

export const defaultFuelItems = {
    // ==== Teus itens originais (com 1 ajuste em dried_kelp_block) ====
    "minecraft:coal": { duration: 1600 }, // 80s (8 itens)
    "minecraft:charcoal": { duration: 1600 }, // 80s (8)
    "minecraft:oak_log": { duration: 300 }, // 15s (1.5)
    "minecraft:spruce_log": { duration: 300 },
    "minecraft:birch_log": { duration: 300 },
    "minecraft:jungle_log": { duration: 300 },
    "minecraft:acacia_log": { duration: 300 },
    "minecraft:dark_oak_log": { duration: 300 },
    "minecraft:mangrove_log": { duration: 300 },
    "minecraft:oak_planks": { duration: 300 },
    "minecraft:spruce_planks": { duration: 300 },
    "minecraft:birch_planks": { duration: 300 },
    "minecraft:jungle_planks": { duration: 300 },
    "minecraft:acacia_planks": { duration: 300 },
    "minecraft:dark_oak_planks": { duration: 300 },
    "minecraft:mangrove_planks": { duration: 300 },
    "minecraft:stick": { duration: 100 }, // 5s (0.5)
    "minecraft:coal_block": { duration: 16000 }, // 800s (80)
    "minecraft:lava_bucket": { duration: 20000 }, // 1000s (100)
    "minecraft:blaze_rod": { duration: 2400 }, // 120s (12)
    "minecraft:dried_kelp_block": { duration: 4000 }, // 200s (20)  << corrigido
    "minecraft:bamboo": { duration: 50 }, // 2.5s (0.25)
    "minecraft:wooden_slab": { duration: 150 }, // 7.5s (0.75)
    "minecraft:wooden_button": { duration: 100 }, // 5s
    "minecraft:wooden_pressure_plate": { duration: 100 }, // 5s
    "minecraft:wooden_trapdoor": { duration: 300 }, // 15s
    "minecraft:wooden_door": { duration: 200 }, // 10s
    "minecraft:wooden_fence": { duration: 300 }, // 15s
    "minecraft:wooden_fence_gate": { duration: 300 }, // 15s
    "minecraft:wooden_stairs": { duration: 300 }, // 15s
    "minecraft:wooden_sign": { duration: 200 }, // 10s
    "minecraft:bow": { duration: 300 }, // 15s
    "minecraft:fishing_rod": { duration: 300 }, // 15s
    "minecraft:noteblock": { duration: 300 }, // 15s
    "minecraft:jukebox": { duration: 300 }, // 15s
    "minecraft:bookshelf": { duration: 300 }, // 15s
    "minecraft:crafting_table": { duration: 300 }, // 15s
    "minecraft:chest": { duration: 300 }, // 15s
    "minecraft:trapped_chest": { duration: 300 }, // 15s
    "minecraft:daylight_detector": { duration: 300 }, // 15s
    "minecraft:loom": { duration: 300 }, // 15s
    "minecraft:barrel": { duration: 300 }, // 15s
    "minecraft:cartography_table": { duration: 300 }, // 15s
    "minecraft:fletching_table": { duration: 300 }, // 15s
    "minecraft:smithing_table": { duration: 300 }, // 15s
    "minecraft:composter": { duration: 300 }, // 15s
    "minecraft:lectern": { duration: 300 }, // 15s
    "minecraft:bowl": { duration: 100 }, // 5s
    "minecraft:sapling": { duration: 100 }, // 5s
    "minecraft:wooden_sword": { duration: 200 }, // 10s
    "minecraft:wooden_pickaxe": { duration: 200 }, // 10s
    "minecraft:wooden_axe": { duration: 200 }, // 10s
    "minecraft:wooden_shovel": { duration: 200 }, // 10s
    "minecraft:wooden_hoe": { duration: 200 }, // 10s
    "minecraft:cherry_log": { duration: 300 },
    "minecraft:cherry_planks": { duration: 300 },
    "minecraft:pale_oak_log": { duration: 300 },
    "minecraft:pale_oak_planks": { duration: 300 },
    "minecraft:oak_wood": { duration: 300 },
    "minecraft:spruce_wood": { duration: 300 },
    "minecraft:birch_wood": { duration: 300 },
    "minecraft:jungle_wood": { duration: 300 },
    "minecraft:acacia_wood": { duration: 300 },
    "minecraft:dark_oak_wood": { duration: 300 },
    "minecraft:mangrove_wood": { duration: 300 },
    "minecraft:cherry_wood": { duration: 300 },
    "minecraft:pale_oak_wood": { duration: 300 },
    "minecraft:stripped_oak_log": { duration: 300 },
    "minecraft:stripped_spruce_log": { duration: 300 },
    "minecraft:stripped_birch_log": { duration: 300 },
    "minecraft:stripped_jungle_log": { duration: 300 },
    "minecraft:stripped_acacia_log": { duration: 300 },
    "minecraft:stripped_dark_oak_log": { duration: 300 },
    "minecraft:stripped_mangrove_log": { duration: 300 },
    "minecraft:stripped_cherry_log": { duration: 300 },
    "minecraft:stripped_pale_oak_log": { duration: 300 },
    "minecraft:stripped_oak_wood": { duration: 300 },
    "minecraft:stripped_spruce_wood": { duration: 300 },
    "minecraft:stripped_birch_wood": { duration: 300 },
    "minecraft:stripped_jungle_wood": { duration: 300 },
    "minecraft:stripped_acacia_wood": { duration: 300 },
    "minecraft:stripped_dark_oak_wood": { duration: 300 },
    "minecraft:stripped_mangrove_wood": { duration: 300 },
    "minecraft:stripped_cherry_wood": { duration: 300 },
    "minecraft:stripped_pale_oak_wood": { duration: 300 },
    "minecraft:bamboo_planks": { duration: 300 },
    "minecraft:bamboo_mosaic": { duration: 300 },
    "minecraft:bamboo_mosaic_stairs": { duration: 300 },
    "minecraft:bamboo_mosaic_slab": { duration: 300 },
    "minecraft:bamboo_block": { duration: 300 },
    "minecraft:stripped_bamboo_block": { duration: 300 },
    "minecraft:ladder": { duration: 300 },
    "minecraft:scaffolding": { duration: 50 }, // 2.5s (0.25)
    "minecraft:crossbow": { duration: 300 },
    "minecraft:chiseled_bookshelf": { duration: 300 },
    "minecraft:oak_boat": { duration: 1200 },
    "minecraft:spruce_boat": { duration: 1200 },
    "minecraft:birch_boat": { duration: 1200 },
    "minecraft:jungle_boat": { duration: 1200 },
    "minecraft:acacia_boat": { duration: 1200 },
    "minecraft:dark_oak_boat": { duration: 1200 },
    "minecraft:mangrove_boat": { duration: 1200 },
    "minecraft:cherry_boat": { duration: 1200 },
    "minecraft:pale_oak_boat": { duration: 1200 },
    "minecraft:oak_chest_boat": { duration: 1200 },
    "minecraft:spruce_chest_boat": { duration: 1200 },
    "minecraft:birch_chest_boat": { duration: 1200 },
    "minecraft:jungle_chest_boat": { duration: 1200 },
    "minecraft:acacia_chest_boat": { duration: 1200 },
    "minecraft:dark_oak_chest_boat": { duration: 1200 },
    "minecraft:mangrove_chest_boat": { duration: 1200 },
    "minecraft:cherry_chest_boat": { duration: 1200 },
    "minecraft:pale_oak_chest_boat": { duration: 1200 },
    "minecraft:bamboo_raft": { duration: 1200 },
    "minecraft:bamboo_raft_with_chest": { duration: 1200 },
    "minecraft:beehive": { duration: 300 }, 
    "minecraft:bee_nest": { duration: 300 },
    "minecraft:mangrove_roots": { duration: 300 },
    "minecraft:leaf_litter": { duration: 100 },
    "vtng_fn:dimensional_fuel": { duration: 9999 },
};

export const redstoneFuelItems = {
    "minecraft:redstone": { duration: 100 }, // 15s
    "minecraft:redstone_torch": { duration: 100 }, // 15s
    "minecraft:redstone_block": { duration: 500 }, // 150s (2,5 minutos)
    "vtng_fn:redstone_energy": { duration: 300 }, // 15s
};

export const furnace = {
    "minecraft:oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:spruce_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:birch_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:jungle_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:acacia_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:dark_oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:mangrove_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:oak_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:spruce_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:birch_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:jungle_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:acacia_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:dark_oak_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:mangrove_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_spruce_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_birch_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_jungle_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_acacia_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_dark_oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_mangrove_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_oak_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_spruce_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_birch_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_jungle_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_acacia_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_dark_oak_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_mangrove_wood": { output: "minecraft:charcoal", xp: 0.15 },

    "minecraft:coal_ore": { output: "minecraft:coal", xp: 0.1 },
    "minecraft:deepslate_coal_ore": { output: "minecraft:coal", xp: 0.1 },

    "minecraft:iron_ore": { output: "minecraft:iron_ingot", xp: 0.7 },
    "minecraft:deepslate_iron_ore": { output: "minecraft:iron_ingot", xp: 0.7 },
    "minecraft:gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:deepslate_gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:nether_gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },

    "minecraft:copper_ore": { output: "minecraft:copper_ingot", xp: 0.7 },
    "minecraft:deepslate_copper_ore": { output: "minecraft:copper_ingot", xp: 0.7 },
    "minecraft:raw_iron": { output: "minecraft:iron_ingot", xp: 0.7 },
    "minecraft:raw_gold": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:raw_copper": { output: "minecraft:copper_ingot", xp: 0.7 },

    "minecraft:sand": { output: "minecraft:glass", xp: 0.1 },
    "minecraft:red_sand": { output: "minecraft:glass", xp: 0.1 },
    "minecraft:clay": { output: "minecraft:terracotta", xp: 0.35 },
    "minecraft:clay_ball": { output: "minecraft:brick", xp: 0.3 },

    "minecraft:netherrack": { output: "minecraft:nether_brick", xp: 0.1 },
    "minecraft:wet_sponge": { output: "minecraft:sponge", xp: 0.15 },
    "minecraft:cactus": { output: "minecraft:green_dye", xp: 1.0 },
    "minecraft:kelp": { output: "minecraft:dried_kelp", xp: 0.1 },
    "minecraft:sea_pickle": { output: "minecraft:lime_dye", xp: 0.1 }, // ver nota abaixo

    "minecraft:stone": { output: "minecraft:smooth_stone", xp: 0.1 },
    "minecraft:cobblestone": { output: "minecraft:stone", xp: 0.1 },
    "minecraft:stone_bricks": { output: "minecraft:cracked_stone_bricks", xp: 0.1 },
    "minecraft:quartz_block": { output: "minecraft:smooth_quartz", xp: 0.1 },
    "minecraft:nether_quartz_ore": { output: "minecraft:quartz", xp: 0.2 },

    "minecraft:ancient_debris": { output: "minecraft:netherite_scrap", xp: 2.0 },
    "minecraft:chorus_fruit": { output: "minecraft:popped_chorus_fruit", xp: 0.1 },

    "minecraft:potato": { output: "minecraft:baked_potato", xp: 0.35 },
    "minecraft:beef": { output: "minecraft:cooked_beef", xp: 0.35 },
    "minecraft:chicken": { output: "minecraft:cooked_chicken", xp: 0.35 },
    "minecraft:porkchop": { output: "minecraft:cooked_porkchop", xp: 0.35 },
    "minecraft:mutton": { output: "minecraft:cooked_mutton", xp: 0.35 },
    "minecraft:rabbit": { output: "minecraft:cooked_rabbit", xp: 0.35 },
    "minecraft:salmon": { output: "minecraft:cooked_salmon", xp: 1.0 },
    "minecraft:cod": { output: "minecraft:cooked_cod", xp: 0.35 },

    "minecraft:cherry_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:cherry_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_cherry_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_cherry_wood": { output: "minecraft:charcoal", xp: 0.15 },

    "minecraft:pale_oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:pale_oak_wood": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_pale_oak_log": { output: "minecraft:charcoal", xp: 0.15 },
    "minecraft:stripped_pale_oak_wood": { output: "minecraft:charcoal", xp: 0.15 },

    "minecraft:diamond_ore": { output: "minecraft:diamond", xp: 1.0 },
    "minecraft:deepslate_diamond_ore": { output: "minecraft:diamond", xp: 1.0 },
    "minecraft:emerald_ore": { output: "minecraft:emerald", xp: 1.0 },
    "minecraft:deepslate_emerald_ore": { output: "minecraft:emerald", xp: 1.0 },
    "minecraft:redstone_ore": { output: "minecraft:redstone", xp: 0.3 },
    "minecraft:deepslate_redstone_ore": { output: "minecraft:redstone", xp: 0.3 },
    "minecraft:lapis_ore": { output: "minecraft:lapis_lazuli", xp: 0.2 },
    "minecraft:deepslate_lapis_ore": { output: "minecraft:lapis_lazuli", xp: 0.2 },

    "minecraft:sandstone": { output: "minecraft:smooth_sandstone", xp: 0.1 },
    "minecraft:red_sandstone": { output: "minecraft:smooth_red_sandstone", xp: 0.1 },
    "minecraft:basalt": { output: "minecraft:smooth_basalt", xp: 0.1 },
    "minecraft:cobbled_deepslate": { output: "minecraft:deepslate", xp: 0.1 },
    "minecraft:deepslate_bricks": { output: "minecraft:cracked_deepslate_bricks", xp: 0.1 },
    "minecraft:deepslate_tiles": { output: "minecraft:cracked_deepslate_tiles", xp: 0.1 },
    "minecraft:polished_blackstone_bricks": { output: "minecraft:cracked_polished_blackstone_bricks", xp: 0.1 },
    "minecraft:nether_bricks": { output: "minecraft:cracked_nether_bricks", xp: 0.1 },

    "minecraft:white_terracotta": { output: "minecraft:white_glazed_terracotta", xp: 0.1 },
    "minecraft:orange_terracotta": { output: "minecraft:orange_glazed_terracotta", xp: 0.1 },
    "minecraft:magenta_terracotta": { output: "minecraft:magenta_glazed_terracotta", xp: 0.1 },
    "minecraft:light_blue_terracotta": { output: "minecraft:light_blue_glazed_terracotta", xp: 0.1 },
    "minecraft:yellow_terracotta": { output: "minecraft:yellow_glazed_terracotta", xp: 0.1 },
    "minecraft:lime_terracotta": { output: "minecraft:lime_glazed_terracotta", xp: 0.1 },
    "minecraft:pink_terracotta": { output: "minecraft:pink_glazed_terracotta", xp: 0.1 },
    "minecraft:gray_terracotta": { output: "minecraft:gray_glazed_terracotta", xp: 0.1 },
    "minecraft:light_gray_terracotta": { output: "minecraft:light_gray_glazed_terracotta", xp: 0.1 },
    "minecraft:cyan_terracotta": { output: "minecraft:cyan_glazed_terracotta", xp: 0.1 },
    "minecraft:purple_terracotta": { output: "minecraft:purple_glazed_terracotta", xp: 0.1 },
    "minecraft:blue_terracotta": { output: "minecraft:blue_glazed_terracotta", xp: 0.1 },
    "minecraft:brown_terracotta": { output: "minecraft:brown_glazed_terracotta", xp: 0.1 },
    "minecraft:green_terracotta": { output: "minecraft:green_glazed_terracotta", xp: 0.1 },
    "minecraft:red_terracotta": { output: "minecraft:red_glazed_terracotta", xp: 0.1 },
    "minecraft:black_terracotta": { output: "minecraft:black_glazed_terracotta", xp: 0.1 },

    "minecraft:golden_sword": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_shovel": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_pickaxe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_axe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_hoe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_helmet": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_chestplate": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_leggings": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_boots": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_horse_armor": { output: "minecraft:gold_nugget", xp: 0.1 },

    "minecraft:iron_sword": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_shovel": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_pickaxe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_axe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_hoe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_helmet": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_chestplate": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_leggings": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_boots": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_horse_armor": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_helmet": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_chestplate": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_leggings": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_boots": { output: "minecraft:iron_nugget", xp: 0.1 }
};

export const blastFurnace = {
    "minecraft:iron_ore": { output: "minecraft:iron_ingot", xp: 0.7 },
    "minecraft:deepslate_iron_ore": { output: "minecraft:iron_ingot", xp: 0.7 },
    "minecraft:raw_iron": { output: "minecraft:iron_ingot", xp: 0.7 },

    "minecraft:copper_ore": { output: "minecraft:copper_ingot", xp: 0.7 },
    "minecraft:deepslate_copper_ore": { output: "minecraft:copper_ingot", xp: 0.7 },
    "minecraft:raw_copper": { output: "minecraft:copper_ingot", xp: 0.7 },

    "minecraft:gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:deepslate_gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:nether_gold_ore": { output: "minecraft:gold_ingot", xp: 1.0 },
    "minecraft:raw_gold": { output: "minecraft:gold_ingot", xp: 1.0 },

    "minecraft:diamond_ore": { output: "minecraft:diamond", xp: 1.0 },
    "minecraft:deepslate_diamond_ore": { output: "minecraft:diamond", xp: 1.0 },

    "minecraft:emerald_ore": { output: "minecraft:emerald", xp: 1.0 },
    "minecraft:deepslate_emerald_ore": { output: "minecraft:emerald", xp: 1.0 },

    "minecraft:lapis_ore": { output: "minecraft:lapis_lazuli", xp: 0.2 },
    "minecraft:deepslate_lapis_ore": { output: "minecraft:lapis_lazuli", xp: 0.2 },

    "minecraft:redstone_ore": { output: "minecraft:redstone", xp: 0.3 },
    "minecraft:deepslate_redstone_ore": { output: "minecraft:redstone", xp: 0.3 },

    "minecraft:coal_ore": { output: "minecraft:coal", xp: 0.1 },
    "minecraft:deepslate_coal_ore": { output: "minecraft:coal", xp: 0.1 },

    "minecraft:nether_quartz_ore": { output: "minecraft:quartz", xp: 0.2 },
    "minecraft:ancient_debris": { output: "minecraft:netherite_scrap", xp: 2.0 },

    "minecraft:golden_sword": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_shovel": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_pickaxe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_axe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_hoe": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_helmet": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_chestplate": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_leggings": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_boots": { output: "minecraft:gold_nugget", xp: 0.1 },
    "minecraft:golden_horse_armor": { output: "minecraft:gold_nugget", xp: 0.1 },

    "minecraft:iron_sword": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_shovel": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_pickaxe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_axe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_hoe": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_helmet": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_chestplate": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_leggings": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_boots": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:iron_horse_armor": { output: "minecraft:iron_nugget", xp: 0.1 },

    "minecraft:chainmail_helmet": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_chestplate": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_leggings": { output: "minecraft:iron_nugget", xp: 0.1 },
    "minecraft:chainmail_boots": { output: "minecraft:iron_nugget", xp: 0.1 }
};

export const smoker = {
    "minecraft:potato": { output: "minecraft:baked_potato", xp: 0.35 },
    "minecraft:beef": { output: "minecraft:cooked_beef", xp: 0.35 },
    "minecraft:chicken": { output: "minecraft:cooked_chicken", xp: 0.35 },
    "minecraft:porkchop": { output: "minecraft:cooked_porkchop", xp: 0.35 },
    "minecraft:mutton": { output: "minecraft:cooked_mutton", xp: 0.35 },
    "minecraft:rabbit": { output: "minecraft:cooked_rabbit", xp: 0.35 },
    "minecraft:cod": { output: "minecraft:cooked_cod", xp: 0.35 },
    "minecraft:salmon": { output: "minecraft:cooked_salmon", xp: 1.0 },
    "minecraft:kelp": { output: "minecraft:dried_kelp", xp: 0.1 }
};



export const iceFuelItems = {
    "minecraft:snowball": { duration: 200 }, // 10s
    "minecraft:snow": { duration: 800 }, // 40s
    "minecraft:snow_layer": { duration: 300 }, // 15s
    "minecraft:powder_snow_bucket": { duration: 1800 }, // 90s (1 minuto e 30s)
};

export const iceFurnace = {
    // ——— os seus (mantidos, com 1 ajuste no final)
    "minecraft:iron_ingot": { output: "minecraft:raw_iron", xp: 0.35 },
    "minecraft:gold_ingot": { output: "minecraft:raw_gold", xp: 0.5 },
    "minecraft:copper_ingot": { output: "minecraft:raw_copper", xp: 0.35 },
    "minecraft:glass": { output: "minecraft:sand", xp: 0.5 },
    "minecraft:terracotta": { output: "minecraft:clay", xp: 0.18 },
    "minecraft:brick": { output: "minecraft:clay_ball", xp: 0.15 },
    "minecraft:nether_brick": { output: "minecraft:netherrack", xp: 0.05 },
    "minecraft:sponge": { output: "minecraft:wet_sponge", xp: 0.08 },
    "minecraft:green_dye": { output: "minecraft:cactus", xp: 0.5 },
    "minecraft:dried_kelp": { output: "minecraft:kelp", xp: 0.05 },
    "minecraft:lime_dye": { output: "minecraft:sea_pickle", xp: 0.1 },
    "minecraft:smooth_stone": { output: "minecraft:stone", xp: 0.05 },
    "minecraft:stone": { output: "minecraft:cobblestone", xp: 0.05 },
    "minecraft:cracked_stone_bricks": { output: "minecraft:stone_bricks", xp: 0.05 },
    "minecraft:smooth_quartz": { output: "minecraft:quartz_block", xp: 0.05 },
    "minecraft:netherite_scrap": { output: "minecraft:ancient_debris", xp: 1.0 },
    "minecraft:popped_chorus_fruit": { output: "minecraft:chorus_fruit", xp: 0.05 },
    "minecraft:baked_potato": { output: "minecraft:potato", xp: 0.18 },
    "minecraft:cooked_beef": { output: "minecraft:beef", xp: 0.18 },
    "minecraft:cooked_chicken": { output: "minecraft:chicken", xp: 0.18 },
    "minecraft:cooked_porkchop": { output: "minecraft:porkchop", xp: 0.18 },
    "minecraft:cooked_mutton": { output: "minecraft:mutton", xp: 0.18 },
    "minecraft:cooked_rabbit": { output: "minecraft:rabbit", xp: 0.18 },
    "minecraft:cooked_salmon": { output: "minecraft:salmon", xp: 0.5 },
    "minecraft:cooked_cod": { output: "minecraft:cod", xp: 0.18 },

    "minecraft:smooth_sandstone": { output: "minecraft:sandstone", xp: 0.05 },
    "minecraft:smooth_red_sandstone": { output: "minecraft:red_sandstone", xp: 0.05 },
    "minecraft:smooth_basalt": { output: "minecraft:basalt", xp: 0.05 },
    "minecraft:deepslate": { output: "minecraft:cobbled_deepslate", xp: 0.05 },
    "minecraft:cracked_deepslate_bricks": { output: "minecraft:deepslate_bricks", xp: 0.05 },
    "minecraft:cracked_deepslate_tiles": { output: "minecraft:deepslate_tiles", xp: 0.05 },
    "minecraft:cracked_polished_blackstone_bricks": { output: "minecraft:polished_blackstone_bricks", xp: 0.05 },
    "minecraft:cracked_nether_bricks": { output: "minecraft:nether_bricks", xp: 0.05 },

    "minecraft:white_glazed_terracotta": { output: "minecraft:white_terracotta", xp: 0.1 },
    "minecraft:orange_glazed_terracotta": { output: "minecraft:orange_terracotta", xp: 0.1 },
    "minecraft:magenta_glazed_terracotta": { output: "minecraft:magenta_terracotta", xp: 0.1 },
    "minecraft:light_blue_glazed_terracotta": { output: "minecraft:light_blue_terracotta", xp: 0.1 },
    "minecraft:yellow_glazed_terracotta": { output: "minecraft:yellow_terracotta", xp: 0.1 },
    "minecraft:lime_glazed_terracotta": { output: "minecraft:lime_terracotta", xp: 0.1 },
    "minecraft:pink_glazed_terracotta": { output: "minecraft:pink_terracotta", xp: 0.1 },
    "minecraft:gray_glazed_terracotta": { output: "minecraft:gray_terracotta", xp: 0.1 },
    "minecraft:light_gray_glazed_terracotta": { output: "minecraft:light_gray_terracotta", xp: 0.1 },
    "minecraft:cyan_glazed_terracotta": { output: "minecraft:cyan_terracotta", xp: 0.1 },
    "minecraft:purple_glazed_terracotta": { output: "minecraft:purple_terracotta", xp: 0.1 },
    "minecraft:blue_glazed_terracotta": { output: "minecraft:blue_terracotta", xp: 0.1 },
    "minecraft:brown_glazed_terracotta": { output: "minecraft:brown_terracotta", xp: 0.1 },
    "minecraft:green_glazed_terracotta": { output: "minecraft:green_terracotta", xp: 0.1 },
    "minecraft:red_glazed_terracotta": { output: "minecraft:red_terracotta", xp: 0.1 },
    "minecraft:black_glazed_terracotta": { output: "minecraft:black_terracotta", xp: 0.1 },
};

let activeTests = JSON.parse(world.getDynamicProperty('vtng_fn:recipe_tests') || '{}');
let withoutRecipe = JSON.parse(world.getDynamicProperty('vtng_fn:without_recipes') || '[]');

world.afterEvents.worldInitialize.subscribe(xZ => {
    system.waitTicks(15).then(() => updateRecipes());
});

updateRecipes();
function updateRecipes() {
    activeTests = JSON.parse(world.getDynamicProperty('vtng_fn:recipe_tests') || '{}');
    withoutRecipe = JSON.parse(world.getDynamicProperty('vtng_fn:without_recipes') || '[]');

    const customRecipes = JSON.parse(world.getDynamicProperty('vtng_fn:custom_recipes') || '[]');
    for (const recipe of customRecipes) {
        furnace[recipe.input] = { output: recipe.output, xp: 0.1 };
        if (recipe.blastRecipe) blastFurnace[recipe.input] = { output: recipe.output, xp: 0.1 };
        if (recipe.smokerRecipe) smoker[recipe.input] = { output: recipe.output, xp: 0.1 };
    };
};

system.waitTicks(50).then(() => {
    for (const test of Object.keys(activeTests)) {
        const testData = activeTests[test];
        checkRecipe(test, testData.location, world.getDimension(testData.dimId), true);
    };
});


export async function checkRecipe(inputId, location, dimension, force) {
    if ([...Object.keys(furnace), ...Object.keys(blastFurnace), ...Object.keys(smoker), ...withoutRecipe].includes(inputId)) return;
    if (Object.keys(activeTests).includes(inputId) && !force) return;
    activeTests[inputId] = { location, dimId: dimension.id };
    world.setDynamicProperty('vtng_fn:recipe_tests', JSON.stringify(activeTests));

    const furnaceTypes = ['furnace', 'blast_furnace', 'smoker'];
    const test_loc =  { x: location.x, y: dimension.heightRange.min, z: location.z + Object.keys(activeTests).indexOf(inputId) };
    const recipeEntity = dimension.spawnEntity('vtng_fn:recipe_check', test_loc);
    recipeEntity.nameTag = inputId;

    for (let index = 0; index < furnaceTypes.length; index++) {
        const furnaceType = furnaceTypes[index];
        const furnaceBlock = dimension.getBlock({ x: test_loc.x + index, y: test_loc.y, z: test_loc.z });
        if (!furnaceBlock?.typeId.includes('lit')) furnaceBlock.setType(`minecraft:${furnaceType}`);
        
        const container = furnaceBlock.getComponent('minecraft:inventory')?.container;
        container.setItem(0, new ItemStack(inputId, 1));
        container.setItem(1, new ItemStack('minecraft:oak_planks', 1));
        container.setItem(2);
    };

    await system.waitTicks(2);

    let awaitTime = 0, resultBlock, resultInv;

    for (let index = 0; index < furnaceTypes.length; index++) {
        const furnaceBlock = dimension.getBlock({ x: test_loc.x + index, y: test_loc.y, z: test_loc.z });
        const container = furnaceBlock.getComponent('minecraft:inventory')?.container;
        
        if (index == 0 && !furnaceBlock?.typeId.includes('lit')) {
            withoutRecipe.push(inputId);
            world.setDynamicProperty('vtng_fn:without_recipes', JSON.stringify(withoutRecipe));
            clearRecipeTest(recipeEntity, inputId);
            return;
        };
        
        if (furnaceBlock?.typeId.includes('lit')) {
            if (index == 0) {
                awaitTime = 202;
                resultBlock = furnaceBlock;
                resultInv = container;
            } else {
                awaitTime = 102;
                resultBlock = furnaceBlock;
                resultInv = container;
            };
        };
    };

    await system.waitTicks(awaitTime || 1);
    const customRecipes = JSON.parse(world.getDynamicProperty('vtng_fn:custom_recipes') || '[]');

    const resultItem = resultInv?.getItem(2);
    if (!resultItem) {
        withoutRecipe.push(inputId);
        world.setDynamicProperty('vtng_fn:without_recipes', JSON.stringify(withoutRecipe));
        clearRecipeTest(recipeEntity, inputId);
        return;
    };

    customRecipes.push({ 
        input: inputId, 
        output: resultItem?.typeId,
        blastRecipe: resultBlock?.typeId.includes('blast_furnace'),
        smokerRecipe: resultBlock?.typeId.includes('smoker')
    });

    world.setDynamicProperty('vtng_fn:custom_recipes', JSON.stringify(customRecipes));
    system.run(() => { updateRecipes(), clearRecipeTest(recipeEntity, inputId) });
};

world.afterEvents.entityLoad.subscribe(xZ => {
    if (xZ.entity.typeId !== 'vtng_fn:recipe_check') return;
    if (xZ.entity?.hasTag('vtng:check')) clearRecipeTest(xZ.entity, xZ.entity.nameTag, true);
    try { xZ.entity?.addTag('vtng:check'); } catch {};
});



function clearRecipeTest(entity, inputId, onLoad) {
    const testData = activeTests[inputId];
    if (onLoad && testData) {
        checkRecipe(inputId, testData.location, world.getDimension(testData.dimId), true);
        return
    };

    const entityLoc = entity.location;
    
    delete activeTests[inputId];
    world.setDynamicProperty('vtng_fn:recipe_tests', JSON.stringify(activeTests));
    for (let x = 0; x < 3; x++) {
        const furnaceBlock = entity.dimension.getBlock({ x: entityLoc.x + x, y: entityLoc.y, z: entityLoc.z });
        furnaceBlock.setType('minecraft:bedrock');
        entity.dimension.getEntities({location: furnaceBlock.center(), maxDistance: 2, type: 'minecraft:item'}).forEach(entityItem => {
            entityItem.remove();
        });
    };
    entity.remove();
};