//This all goes in startup_scripts

let $Attributes = Java.loadClass('net.minecraft.world.entity.ai.attributes.Attributes')
let $AttributeModifier = Java.loadClass('net.minecraft.world.entity.ai.attributes.AttributeModifier')
let $ISSAttributeRegistry = Java.loadClass('io.redspace.ironsspellbooks.api.registry.AttributeRegistry')

ForgeEvents.onEvent('net.minecraftforge.event.ItemAttributeModifierEvent', event => {

    let sparringweapons = [
        'minecraft:wooden_sword',
        'spartanweaponry:wooden_parrying_dagger',
        'spartanweaponry:wooden_longsword',
        'spartanweaponry:wooden_katana',
        'spartanweaponry:wooden_saber',
        'spartanweaponry:wooden_rapier',
        'spartanweaponry:wooden_greatsword',
        'spartanweaponry:wooden_battle_hammer',
        'spartanweaponry:wooden_warhammer',
        'spartanweaponry:wooden_spear',
        'spartanweaponry:wooden_halberd',
        'spartanweaponry:wooden_pike',
        'spartanweaponry:wooden_lance',
        'spartanweaponry:wooden_battleaxe',
        'spartanweaponry:wooden_glaive',
        'spartanweaponry:wooden_flanged_mace',
        'spartanweaponry:wooden_scythe'
    ];

    let halberds = [
        'spartanweaponry:iron_halberd',
        'spartanweaponry:steel_halberd',
        'spartanweaponry:netherite_halberd'
    ];

    let hammersya = [
        "simplest_hammers:stone_hammer",
        "simplest_hammers:iron_hammer"
    ];

    let rapiers = [
        'spartanweaponry:iron_rapier',
        'spartanweaponry:steel_rapier',
        'spartanweaponry:netherite_rapier'
    ];

    let heldItem = event.itemStack;
    let slot = event.slotType;

    if ((slot === 'mainhand' || slot === 'offhand') && sparringweapons.includes(heldItem.id)) {
        event.addModifier(
            $Attributes.ATTACK_DAMAGE,
            new $AttributeModifier(
                UUID.fromString('197cd1ee-8a5b-40a7-95ed-4047f926f066'),
                'Weapon modifier',
                -0.99,
                'multiply_total'
            )
        );
    }

    if ((slot === 'mainhand') && halberds.includes(heldItem.id)) {
        event.addModifier(
            $Attributes.ATTACK_SPEED,
            new $AttributeModifier(
                UUID.fromString('0eca8801-82e1-4ce7-a6e2-af4f7fe71f37'),
                'Weapon modifier',
                -0.25,
                'multiply_total'
            )
        );
    }

    if ((slot === 'mainhand') && hammersya.includes(heldItem.id)) {
        event.addModifier(
            "attributeslib:mining_speed",
            new $AttributeModifier(
                UUID.fromString('f0f8a62d-4393-4799-a15c-d565b9f68045'),
                'Weapon modifier',
                -0.5,
                'multiply_total'
            )
        );
    }

    if ((slot === 'offhand') && rapiers.includes(heldItem.id)) {
        event.addModifier(
            $Attributes.ATTACK_DAMAGE,
            new $AttributeModifier(
                UUID.fromString('bc644ffa-a672-469a-8287-c4f0c35199a5'),
                'Weapon modifier',
                -0.5,
                'multiply_total'
            )
        );
    }
});