import { system } from '@minecraft/server';
import { FSItems, FSBlocks } from '../constants.js';
import { MinecraftItemTypes } from '../minecraft_vanilla_data.js';

system.afterEvents.scriptEventReceive.subscribe((event) => {
    if (event.id !== "ftb_sd:register_init") {
        return;
    }
    registerCompressedBlocks(FSBlocks.COMPRESSED_CLAY);
    registerCompressedBlocks(FSBlocks.COMPRESSED_COBBLESTONE);
    registerCompressedBlocks(FSBlocks.COMPRESSED_DIRT);
    registerCompressedBlocks(FSBlocks.COMPRESSED_DUST);
    registerCompressedBlocks(FSBlocks.COMPRESSED_END_STONE);
    registerCompressedBlocks(FSBlocks.COMPRESSED_GRAVEL);
    registerCompressedBlocks(FSBlocks.COMPRESSED_NETHERRACK);
    registerCompressedBlocks(FSBlocks.COMPRESSED_SAND);
    registerCompressedBlocks(FSBlocks.COMPRESSED_SOUL_SAND);
    registerCompressedBlocks(FSBlocks.COMPRESSED_SOUL_SOIL);
    registerCompressedBlocks(FSBlocks.COMPRESSED_STONE);
    registerCompressedBlocks(FSBlocks.COMPRESSED_CRUSHED_END_STONE);
    registerCompressedBlocks(FSBlocks.COMPRESSED_CRUSHED_NETHERRACK);
    registerScrap(FSItems.IRON_SCRAP, MinecraftItemTypes.IronIngot);
    registerScrap(FSItems.GOLD_SCRAP, MinecraftItemTypes.GoldIngot);
    registerScrap(FSItems.DIAMOND_SCRAP, MinecraftItemTypes.Diamond);
    registerScrap(FSItems.EMERALD_SCRAP, MinecraftItemTypes.Emerald);
    registerScrap(FSItems.COPPER_SCRAP, MinecraftItemTypes.CopperIngot);
});
function registerScrap(scrapId, output) {
    registerRecipe(output, scrapId, 4);
}
function registerCompressedBlocks(block) {
    registerRecipe(block.tripleCompressed, block.doubleCompressed, 9);
    registerRecipe(block.doubleCompressed, block.compressed, 9);
    registerRecipe(block.compressed, block.uncompressed, 9);
}
function registerRecipe(topSlot, bottomSlot, bottomSlotCount) {
    const recipe = {
        topSlot,
        bottomSlot,
        bottomSlotCount
    };
    system.sendScriptEvent("ftb_sd:register_compacting_recipe", JSON.stringify(recipe));
}
function addItemToDrawerV2(block, itemStack, feedBackId) {
    system.sendScriptEvent("ftb_sd:add_item_v2", JSON.stringify({
        dimId: block.dimension.id,
        blockLocation: block.location,
        itemTypeId: itemStack.typeId,
        itemAmount: itemStack.amount,
        feedbackId: feedBackId
    }));
}

export { addItemToDrawerV2 };
