import { world } from '@minecraft/server';

//Ruby Tools
world.afterEvents.entityHitEntity.subscribe(event => {
    const { damagingEntity } = event;
    const equipment = damagingEntity.getComponent('equippable');
    const selectedItem = equipment.getEquipmentSlot('Mainhand');
    if (selectedItem?.typeId === 'old_nether:ruby_axe' || selectedItem?.typeId === 'old_nether:ruby_shovel' || selectedItem?.typeId === 'old_nether:ruby_battle_axe' || selectedItem?.typeId === 'old_nether:ruby_hoe' || selectedItem?.typeId === 'old_nether:ruby_pickaxe' || selectedItem?.typeId === 'old_nether:ruby_sword') {
        const chance = Math.random();
        if (chance <= 1 / 6) {
            damagingEntity.addEffect('speed', 40, { amplifier: 1, showParticles: true })
        }
    }
});

//Taaffeite Tools
world.afterEvents.entityHitEntity.subscribe(event => {
    const { damagingEntity } = event;
    const equipment = damagingEntity.getComponent('equippable');
    const selectedItem = equipment.getEquipmentSlot('Mainhand');
    if (selectedItem?.typeId === 'old_nether:taaffeite_axe' || selectedItem?.typeId === 'old_nether:taaffeite_shovel' || selectedItem?.typeId === 'old_nether:taaffeite_mace' || selectedItem?.typeId === 'old_nether:taaffeite_hoe' || selectedItem?.typeId === 'old_nether:taaffeite_pickaxe' || selectedItem?.typeId === 'old_nether:taaffeite_sword') {
        const chance = Math.random();
        if (chance <= 1 / 8) {
            damagingEntity.addEffect('absorption', 40, { amplifier: 1, showParticles: true })
        }
    }
});

//Unused
//Monochromatic Gold Tools
world.afterEvents.entityHitEntity.subscribe(event => {
    const { damagingEntity, hitEntity } = event;
    const equipment = damagingEntity.getComponent('equippable');
    const selectedItem = equipment.getEquipmentSlot('Mainhand');
    if (selectedItem?.typeId === 'old_nether:monochromatic_gold_axe' || selectedItem?.typeId === 'old_nether:monochromatic_gold_shovel' || selectedItem?.typeId === 'old_nether:monochromatic_gold_battle_axe' || selectedItem?.typeId === 'old_nether:monochromatic_gold_hoe' || selectedItem?.typeId === 'old_nether:monochromatic_gold_pickaxe' || selectedItem?.typeId === 'old_nether:monochromatic_gold_sword') {
        const chance = Math.random();
        if (chance <= 1 / 8) {
            hitEntity.addEffect('instant_damage', 20, { amplifier: 1, showParticles: true })
        }
    }
});