function onlyFromIngredient(ingredient, regex) {
    return ingredient.itemIds.filter(a => !regex.test(a))
}

const obliterateItems = [
    'bits_n_bobs:nixie_board',
    'bits_n_bobs:large_nixie_tube',
    "kitchenkarrot:ice_cubes",
    "kitchenkarrot:acorn",
    "kitchenkarrot:sweet_roll",
    "kitchenkarrot:pillager_pie",
    'minecraft:enchanting_table',
    // /refinedstorage:\\d+k_(fluid_)?storage_(part|disk)"/,
    // "refinedstorage:storage_housing",
    // "refinedstorage:creative_fluid_storage_disk",
    'createdieselgenerators:sheet_metal_panel',
    // /create:[\\w_]*_calcite_[\\w_]*/,
    // "!(another_furniture:|everycomp:af)[\\w_/]*_(shelf|sofa|tall_stool|lamp|bench)",
    // /(another_furniture:|everycomp:af)[\\w_/]*_(?!curtain|stool|table|service_bell)/,
    
    // /copycats:[\w_]*$(?<!byte|byte_panel|door|trapdoor|copycat_block|slab|copycat_stairs)/,

    // /effortlessbuilding:/,
    // /(dramaticdoors:|everycomp:dd\/)short_[\w_]*/,
    
    // /additionaladditions:[\w_]*$(?<!amethyst_lamp|patina|patina_block|rose_gold_alloy|rose_gold_helmet|rose_gold_chestplate|rose_gold_leggings|rose_gold_boots|rose_gold_upgrade|jukebox|bundle|can|disc_\d+)/,
    
    'naturalist:deer_spawn_egg',

    // /^supplementaries:candle_holder/,
    // "supplementaries:item_shelf",
    "createrailwaysnavigator:navigator",
    'vs_clockwork:clock',
    /^bits_n_bobs:[\w_]*girder_strut/,
    "@citadel",

    'supplementaries:botania/sign_post_livingwood',
    'supplementaries:botania/sign_post_dreamwood',
    /^additionaladditions:rose_gold_(sword|axe|pickaxe|shovel|hoe)/,
    '@moreburners', // This is in the pack just for the exoflame interaction
    'redstonepen:basic_lever',
    'redstonepen:basic_button',
    'etched:radio',
    'etched:boombox',
    'minecraft:stonecutter', // Sawmill has all the recipes
    'playercollars:clicker',

    /^yttr:(.*?)_pinch_glom$/ // messes with create balancing

    // 'yttr:shifter' // I love this item but it isn't compatible with inventorio :(
                   // Also you can use the rod of shifting crusts which is worse but
]
    // .concat(
    //     onlyFromIngredient(Ingredient.of('@copycats'), /(byte|byte_panel|door|trapdoor|copycat_block|slab|copycat_stairs|vertical_half_layer|stacked_half_layer|slope)$/)
    // )
    // .concat(
    //     // onlyFromIngredient(Ingredient.of('@additionaladditions'), /(amethyst_lamp|patina|patina_block|rose_gold_alloy|rose_gold_helmet|rose_gold_chestplate|rose_gold_leggings|rose_gold_boots|rose_gold_upgrade|jukebox|bundle|can|disc_\d+)$/)
    //     onlyFromIngredient(Ingredient.of('@additionaladditions'), /(amethyst_lamp|patina|patina_block|rose_gold_alloy|rose_gold_helmet|rose_gold_chestplate|rose_gold_leggings|rose_gold_boots|rose_gold_upgrade|jukebox|bundle|can|disc_\d+)$/)
    // )
    // .concat(
    //     Ingredient.of('#bits_n_bobs:chairs').itemIds
    // )

const swapItems = [
    [ "crossroads:nugget_copper", "create:copper_nugget", '#forge:nuggets/copper' ]
]

console.log(onlyFromIngredient(Ingredient.of('@additionaladditions'), /(amethyst_lamp|patina|patina_block|rose_gold_alloy|rose_gold_helmet|rose_gold_chestplate|rose_gold_leggings|rose_gold_boots|rose_gold_upgrade|jukebox|bundle|can|disc_\d+)$/))

// Check if itemID exists within obliterateItems
function ObliterateCheck(itemID) {
    let check = false
    for (let i = 0; i < obliterateItems.length; i++) {
        let id = obliterateItems[i]
        let reg = new RegExp(id)
        if (typeof id == "string") { reg = new RegExp(`^${id}$`) }
        if (reg.test(itemID)) {
            check = true
            break
        }
    }
    return check
}

// Remove recipes
ServerEvents.recipes(event => {
    event.remove({ input: obliterateItems })
    event.remove({ output: obliterateItems })
    for(let [ target, item, ingredient ] of swapItems) {
        event.replaceInput({ input: obliterateItems }, target, ingredient ?? item)
        event.replaceOutput({ output: obliterateItems }, target, item)
    }
})

// Remove tags
ServerEvents.tags('item', event => {
    event.removeAllTagsFrom(obliterateItems)
    event.add('c:hidden_from_recipe_viewers', obliterateItems)
    event.add('c:hidden_from_recipe_viewers', swapItems.map(a => a[0]))

    event.remove('yttr:not_indexable', 'minecraft:bundle')
})

// // Append disabled tooltip
// ItemEvents.modifyTooltips(event => {
//     event.add(obliterateItems, Text.red('Disabled'))
// })

// Remove from recipe viewer
// RecipeViewerEvents.removeEntriesCompletely('item', event => {
//     event.remove(obliterateItems)
// })

// Remove from loot pools
// LootJS.lootTables(event => {
//     event.modifyLootTables(/.*/).removeItem(obliterateItems)
// })
LootJS.modifiers(event => {
    // event.removeLoot(event.modifyLootTables(/.*/).removeItem(obliterateItems))
    event.addLootTypeModifier(LootType.ENTITY).removeLoot(obliterateItems)
    event.addLootTypeModifier(LootType.BLOCK).removeLoot(obliterateItems)
    event.addLootTypeModifier(LootType.CHEST).removeLoot(obliterateItems)
    // event.addLootTypeModifier(LootType.CHEST).removeLoot(obliterateItems.concat([
    //     'additionaladditions:rose_gold_upgrade'
    // ]))
    event.addLootTypeModifier(LootType.FISHING).removeLoot(obliterateItems)
    event.addLootTypeModifier(LootType.GIFT).removeLoot(obliterateItems)
})

// Destroy on interaction
BlockEvents.rightClicked(event => {
    let { block } = event
    if (ObliterateCheck(block.id)) { block.set('minecraft:air') }
})

// Destroy on block placement
BlockEvents.placed(event => {
    let { block } = event
    if (ObliterateCheck(block.id)) {
        block.set('minecraft:air')
    }
})

// Destroy on pickup
ItemEvents.canPickUp(event => {
    let { item, itemEntity } = event
    if(itemEntity.hasPickUpDelay()) return
    if (ObliterateCheck(item.id)) { item.setCount(0) }
})

// Destroy on drop
ItemEvents.dropped(event => {
    let { item } = event
    if (ObliterateCheck(item.id)) { item.setCount(0) }
})

// Destroy on inventory changed
PlayerEvents.inventoryChanged(event => {
    let { item, player } = event
    if (ObliterateCheck(item.id)) {
        player.inventory.clear(item);
    }
})