const chestVariants = [
    ["quark:ancient_chest",0xf9fffe,0x383127],
    ["quark:azalea_chest",0xc3cb6b,0x383127],
    ["quark:blossom_chest",0x693325,0x383127],
    ["quark:nether_brick_chest",0x37181e,0xbaa633],
    ["quark:purpur_chest",0xb88fb5,0x845c85],
    ["quark:prismarine_chest",0x8bc7bf,0x4d7a71],
    ["ars_nouveau:archwood_chest",0x8b808d,0xeae372],
    ["everycomp:q/thermal/rubberwood_chest",0x616c3b,0x383127],
    ['twilightforest:twilight_oak_chest',0xc49d68,0x383127],
    ['twilightforest:canopy_chest',0x5f442b,0x383127],
    ['twilightforest:dark_chest',0x935d38,0x383127],
    ['twilightforest:time_chest',0x604032,0x383127], 
    ['twilightforest:transformation_chest',0x7b8598,0x383127], 
    ['twilightforest:mining_chest',0xb0a088,0x383127],
    ['twilightforest:sorting_chest',0x4a2a18,0x383127], 
    ['everycomp:q/mynethersdelight/powdery_chest',0x4c4656,0x383127], 
    ['everycomp:q/minecraft/pale_oak_chest',0xf5f5f5,0x383127],
    ['everycomp:q/biomeswevegone/redwood_chest',0x873938,0x383127], 
    ['everycomp:q/biomeswevegone/sakura_chest',0x902c3f,0x383127], 
    ['everycomp:q/biomeswevegone/skyris_chest',0x7594a0,0xdd8a91],
    ['everycomp:q/biomeswevegone/white_mangrove_chest',0xc1c1c0,0x383127],
    ['everycomp:q/biomeswevegone/willow_chest',0x293b26,0x383127],
    ['everycomp:q/biomeswevegone/witch_hazel_chest',0x30774d,0xc1a01e],
    ['everycomp:q/biomeswevegone/zelkova_chest',0x95562e,0x383127],
    ['everycomp:q/wizards_reborn/arcane_wood_chest',0x725253,0x383127],
    ['everycomp:q/wizards_reborn/innocent_wood_chest',0xd6cec0,0x383127],
    ['everycomp:q/biomeswevegone/rainbow_eucalyptus_chest',0x785042,0x383127],
    ['everycomp:q/biomeswevegone/pine_chest',0xc2b698,0x383127],
    ['everycomp:q/biomeswevegone/palm_chest',0x998b6e,0x383127],
    ['everycomp:q/biomeswevegone/maple_chest',0x695f56,0x383127],
    ['everycomp:q/biomeswevegone/mahogany_chest',0x824d6d,0x383127],
    ['everycomp:q/biomeswevegone/jacaranda_chest',0xa99597,0x6b4344],
    ['everycomp:q/biomeswevegone/ironwood_chest',0x7c7a79,0x383127],
    ['everycomp:q/biomeswevegone/holly_chest',0xaf8e80,0x735f55],
    ['everycomp:q/biomeswevegone/green_enchanted_chest',0x448450,0x1f3f20],
    ['everycomp:q/ancient_aether/sakura_chest',0x3c2e2a,0x383127],
    ['everycomp:q/ancient_aether/highsproot_chest',0x5a5041,0x383127],
    ['everycomp:q/deep_aether/sunroot_chest',0xf1e6cc,0x383127],
    ['everycomp:q/deep_aether/conberry_chest',0xa57e62,0x383127],
    ['everycomp:q/deep_aether/cruderoot_chest',0x9587ba,0x383127],
    ['everycomp:q/deep_aether/yagroot_chest',0x71637d,0x383127],
    ['everycomp:q/deep_aether/roseroot_chest',0xc79494,0x383127],
    ['everycomp:q/biomeswevegone/florus_chest',0x5e7642,0x383127],
    ['everycomp:q/naturesaura/ancient_chest',0x9a5f80,0x383127],
    ['everycomp:q/aether/skyroot_chest',0x5a5d44,0x383127],
    ['everycomp:q/biomeswevegone/fir_chest',0x794c38,0x383127],
    ['everycomp:q/biomeswevegone/ebony_chest',0x202021,0x0d0d0d],
    ['everycomp:q/biomeswevegone/cypress_chest',0x6f6c4a,0x383127],
    ['everycomp:q/biomeswevegone/cika_chest',0x66362a,0x9a9b9a],
    ['everycomp:q/biomeswevegone/blue_enchanted_chest',0x435086,0x1f243e],
    ['everycomp:q/biomeswevegone/baobab_chest',0x60532d,0x383127],
    ['everycomp:q/biomeswevegone/aspen_chest',0xda9b7f,0x383127],
    ['everycomp:q/twilightforest/mangrove_chest',0xc8a67c,0x383127]
]

chestVariants.forEach(([variant,color,accentColor])=>{
    BlockEvents.rightClicked(variant,event=>{

        const {player,block} = event

        if(player.mainHandItem.id !== "sophisticatedstorage:basic_tier_upgrade")
            return;//Check if the player is holding an upgrade

        const pos = block.pos // Position of the block
        const oldNbt = block.entity.serializeNBT() // Get the Nbt of the block
        const savedInventory = oldNbt.Items

        
        block.setEntityData({Items:[],x:pos.x,y:pos.y,z:pos.z})//Clear Inventory to prevent duping
        block.set("sophisticatedstorage:chest",block.properties)// Replace old chest with a new one
        block.setEntityData({
            "x": pos.x,
            "y": pos.y,
            "z": pos.z,
            "id": "sophisticatedstorage:chest",
            "storageWrapper": {
                "contents": {
                "inventory": {
                    "Size": 36,
                    "Items": savedInventory
                }
                },
            "mainColor": color,
            "accentColor": accentColor
            },
            "packed": 0
        })//Set the inventory and color
        player.mainHandItem.count--
    })
    
})
