
//this js used by cae modpacks , thx for shared.
BlockEvents.rightClicked('backpack', event =>{
    let {block, item} = event
    if (block.entityId != "sophisticatedbackpacks:backpack") {return}

    let data = block.getEntityData()
    let bpTag = block.entityData.backpackData.tag
    let slots = 0
    let upgradeSlots = 0
    if (bpTag.leather == undefined) {
        data.backpackData.tag.leather = Math.floor(0)
        data.backpackData.tag.steel = Math.floor(0)
        data.backpackData.tag.brass_sheet = Math.floor(0)
        data.backpackData.tag.sky_ingot = Math.floor(0)
        data.backpackData.tag.circuit = Math.floor(0)
        data.backpackData.tag.runes_ingot = Math.floor(0)
        data.backpackData.tag.medal = Math.floor(0)
        block.mergeEntityData(data)
        bpTag = block.entityData.backpackData.tag
    }

    if (item == Item.of("minecraft:leather").id && bpTag.leather < 24) {slots = 1; data.backpackData.tag.leather++}
    else if (item == Item.of("immersiveengineering:ingot_steel").id && bpTag.steel < 16) {slots = 1; data.backpackData.tag.steel++}
    else if (item == Item.of("create:brass_sheet").id && bpTag.brass_sheet < 25) {slots = 1; data.backpackData.tag.brass_sheet++}
    else if (item == Item.of("naturesaura:sky_ingot").id && bpTag.sky_ingot < 16) {slots = 2; data.backpackData.tag.sky_ingot++}
    else if (item == Item.of("immersiveengineering:circuit_board").id && bpTag.circuit < 12) {slots = 2; data.backpackData.tag.circuit++}
    else if (item == Item.of("nwtc:runes_ingot").id && bpTag.runes_ingot < 2) {upgradeSlots = 1; data.backpackData.tag.runes_ingot++}
    else if (item == Item.of("nwtc:medal").id && bpTag.medal < 4) {upgradeSlots = 1; data.backpackData.tag.medal++}
    else {return}
    
    data.backpackData.tag.inventorySlots += slots
    data.backpackData.tag.upgradeSlots += upgradeSlots
    block.mergeEntityData(data)
    if (!event.player.creativeMode) 
	{item.count--}
    event.cancel()
})
ServerEvents.recipes(event=> {

    event.remove({output:"sophisticatedbackpacks:upgrade_base"})
    event.remove({output:'sophisticatedstorage:upgrade_base'})
    event.shaped("sophisticatedbackpacks:upgrade_base", [" D ", "DTD", " D "], {T:"nwtc:gelatum", D:"farmersdelight:safety_net"})
    event.shapeless('sophisticatedstorage:upgrade_base', 
    [ 
        'sophisticatedbackpacks:upgrade_base',
    ])

    event.remove({output: /sophisticatedbackpacks\:stack_upgrade_tier/})
    event.remove({output: /sophisticatedstorage\:stack_upgrade_tier/})
    event.shapeless('sophisticatedbackpacks:stack_upgrade_tier_1', 
    [ 
        'sophisticatedbackpacks:upgrade_base',
        '4x #forge:storage_blocks/steel',
    ])
    event.shapeless('sophisticatedbackpacks:stack_upgrade_tier_2', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_1',
        '8x naturesaura:sky_ingot',
    ])
    event.shapeless('sophisticatedbackpacks:stack_upgrade_tier_3', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_2',
        '4x forbidden_arcanus:deorum_ingot',
    ])
    event.shapeless('sophisticatedbackpacks:stack_upgrade_tier_4', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_3',
        '4x nwtc:energy_superconductivity_ingot',
    ])
    event.shapeless('sophisticatedstorage:stack_upgrade_tier_1', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_1',
    ])
    event.shapeless('sophisticatedstorage:stack_upgrade_tier_2', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_2',
    ])
    event.shapeless('sophisticatedstorage:stack_upgrade_tier_3', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_3',
    ])
    event.shapeless('sophisticatedstorage:stack_upgrade_tier_4', 
    [ 
        'sophisticatedbackpacks:stack_upgrade_tier_4',
    ])
    event.remove({id: "sophisticatedbackpacks:xp_pump_upgrade"})
    event.smithing('sophisticatedbackpacks:xp_pump_upgrade', 'sophisticatedbackpacks:upgrade_base', 'naturesaura:sky_ingot')

    event.remove({output:/sophisticatedbackpacks\:.*_backpack/})
    event.shapeless("sophisticatedbackpacks:iron_backpack", ["sophisticatedbackpacks:backpack", "4x immersiveengineering:ingot_steel"]).modifyResult((inventory, itemstack) =>{
        let backpack = inventory.find(Item.of('sophisticatedbackpacks:backpack'))
        if (backpack.nbt == null) return itemstack
        let nbt = backpack.nbt
        nbt.inventorySlots += 9
    return itemstack.withNBT(nbt)
    })

    event.shapeless("sophisticatedbackpacks:gold_backpack", ["sophisticatedbackpacks:iron_backpack", "4x #forge:ingots/gold"]).modifyResult((inventory, itemstack) =>{
        let backpack = inventory.find(Item.of('sophisticatedbackpacks:iron_backpack'))
        if (backpack.nbt == null) return itemstack
        let nbt = backpack.nbt
        nbt.inventorySlots += 9
    return itemstack.withNBT(nbt)
    })

    event.shapeless("sophisticatedbackpacks:diamond_backpack", ["sophisticatedbackpacks:gold_backpack", "4x create_new_age:overcharged_diamond"]).modifyResult((inventory, itemstack) =>{
        let backpack = inventory.find(Item.of('sophisticatedbackpacks:gold_backpack'))
        if (backpack.nbt == null) return itemstack
        let nbt = backpack.nbt
        nbt.inventorySlots += 9
    return itemstack.withNBT(nbt)
    })
    event.shapeless("sophisticatedbackpacks:netherite_backpack", ["sophisticatedbackpacks:diamond_backpack", "4x minecraft:netherite_ingot"]).modifyResult((inventory, itemstack) =>{
        let backpack = inventory.find(Item.of('sophisticatedbackpacks:diamond_backpack'))
        if (backpack.nbt == null) return itemstack
        let nbt = backpack.nbt
        nbt.inventorySlots += 9
    return itemstack.withNBT(nbt)
    })
  
   
  
  
      
      
  
  
  
  
  })
  