// File containing the eclipse narcotics items and processes

console.info("Making drugs available for all the family!")

// Custom foods
let custom_foods = [
    {
        "key": "cocaine",
        "name": "Cocaine",
        "effects": [
            {
                "key": 'minecraft:speed',
                "duration": 3600,
                "amplification": 4
            },
            {
                "key": 'minecraft:nausea',
                "duration": 600
            }
        ]
    },
    {
        "key": "meth",
        "name": "Crystal Meth",
        "effects": [
            {
                "key": 'minecraft:hunger',
                "duration": 2400,
                "amplification": 1
            },
            {
                "key": 'minecraft:speed',
                "duration": 2400,
                "amplification": 2
            },
            {
                "key": 'minecraft:strength',
                "duration": 2400,
                "amplification": 3
            }
        ]
    },
    {
        "key": "lsd",
        "name": "LSD",
        "effects": [
            {
                "key": 'minecraft:slowness',
                "duration": 600,
                "amplification": 3
            },
            {
                "key": 'minecraft:nausea',
                "duration": 1200,
            }
        ]
    },
    {
        "key": "marijuana_brownies",
        "name": "Spicy Brownies",
        "effects": [
            {
                "key": 'minecraft:hunger',
                "duration": 2400,
                "amplification": 1
            },
            {
                "key": 'minecraft:slowness',
                "duration": 1200,
                "amplification": 1
            }
        ]
    },
    {
        "key": "marijuana_blunt",
        "name": "Blunt",
        "effects": [
            {
                "key": 'minecraft:hunger',
                "duration": 2400,
                "amplification": 1
            },
            {
                "key": 'minecraft:slowness',
                "duration": 1200,
                "amplification": 1
            }
        ]
    }
]

// Create custom items
events.listen('item.registry', function(event){
    // Textures in "kubejs/assets/kubejs/textures/item/{Item name/food.key}.png"
    
    // Creates the custom foods from the array
    custom_foods.forEach(food => {
        event.create(food.key)
            .displayName(food.name)
            .food(foodItem => {
                foodItem.alwaysEdible()
                if (food.effects) {
                    food.effects.forEach(effect => {
                        foodItem.effect(effect.key, effect.duration || 1, effect.amplification -1 || 0, 1.0)
                    })
                }
            })
    })

    event.create('normal_brownies').displayName('Brownies').food(foodItem=>{foodItem.hunger(3).saturation(2)})

    // Cocaine Items
    event.create('coca_leaves').displayName('Coca Leaves')
    event.create('cocaine_hydrochloride').displayName('Cocaine Hydrochloride')

    // Weed Items
    event.create('bud').displayName('Marijuana Bud')
    event.create('marijuana').displayName('Marijuana')

    event.create('marijuana_bong').displayName('Marijuana Bong')
    .maxStackSize(1)
    .containerItem('minecraft:glass_bottle')
    .food(function(foodItem){
        foodItem.effect('minecraft:slowness', 1200, 1, 1.0)
        foodItem.effect('minecraft:hunger', 2400, 1, 1.0)
        foodItem.eaten(function(event){
            if(event.item.id == 'kubejs:marijuana_bong'){
                if(!event.player.isCreativeMode()){
                    event.player.give('minecraft:glass_bottle')
                }
            }
        })
    })

    // LSD Items
    event.create('bottled_lsd').displayName('Bottled LSD')
    .maxStackSize(16)
    .containerItem('minecraft:glass_bottle')
    .food(function(foodItem){
        foodItem.hunger(10).saturation(10)
        foodItem.effect('minecraft:slowness', 1200, 5, 1.0)
        foodItem.effect('minecraft:nausea', 2400, 2, 1.0)
        foodItem.effect('minecraft:instant_damage', 20, 100, 0.1)
        foodItem.effect('minecraft:poison', 1200, 5, 0.5)
        foodItem.eaten(function(event){
            if(event.item.id == 'kubejs:bottled_lsd'){
                if(!event.player.isCreativeMode()){
                    event.player.give('minecraft:glass_bottle')
                }
            }
        })
        
    })

})

// Create custom blocks
events.listen('block.registry', event => {
    event.create('sack_o_meth').displayName("Sack o'Meth").material('wool').hardness(0.5)
})

// Create custom liquids
events.listen('fluid.registry', event =>{
    
    // Cocaine Fluids
    event.create('coca_base_paste').textureThick(0x6b4307).displayName('Coca Base Paste').bucketColor(0x6b4307)
    event.create('cocaine_base').textureThick(0xb47c60).displayName('Cocaine Base').bucketColor(0xb47c60)

    // Meth Fluids
    event.create('meth_base').textureThin(0xb7e5f1).displayName('Meth Base').bucketColor(0xb7e5f1)
    event.create('liquid_meth').textureThin(0x22b7df).displayName('Liquid Meth').bucketColor(0x22b7df)

    // LSD Fluids
    event.create('isolysergic_acid').textureThin(0xccbba0).displayName('iso-Lysergic Acid').bucketColor(0xccbba0)
    event.create('lysergic_acid').textureThin(0xfaf9da).displayName('Lysergic Acid').bucketColor(0xfaf9da)
    event.create('isolysergic_diethylamide').textureThin(0xfffef3).displayName('iso-Lysergic Diethylamide').bucketColor(0xfffef3)

})