import { Entity } from "@minecraft/server"

export const COBALTIUM_SWORD = {
    _itemTypeId: "piki_beyondsurvival:cobaltium_sword",
    _knockbackStrengthHorizontal: 3,
    _knockbackStregnthVertical: 0.5,

    isCobaltiumSword(itemId) {
        return itemId == this._itemTypeId
    },
    /**
     * @param {Entity} source
     * @param {Entity} hitEntity 
     */
    applyAttackEffect(source, hitEntity) {
        const sourceX = source.location.x;
        const sourceZ = source.location.z;
        const hitX = hitEntity.location.x;
        const hitZ = hitEntity.location.z;
    
        const directionX = hitX - sourceX;
        const directionZ = hitZ - sourceZ;
    
        const magnitude = Math.sqrt(directionX * directionX + directionZ * directionZ);
        const normalizedDirectionX = directionX / magnitude;
        const normalizedDirectionZ = directionZ / magnitude;
    
        hitEntity.applyKnockback(normalizedDirectionX, normalizedDirectionZ, this._knockbackStrengthHorizontal, this._knockbackStregnthVertical);
    }
    
}