import { EntityDamageCause, Player, system, world } from "@minecraft/server"
import { Vector3 } from "../../../vector/vector3"
import { namespace } from "../../../namespace"

const filter = [
    "minecraft:item",
    "minecraft:xp_orb",
    `${namespace}:hacker_table`,
    `${namespace}:item_duper`,
    `${namespace}:block_outline`,
    `${namespace}:door`,
    `${namespace}:button`,
    `${namespace}:hacker_desk`,
    `${namespace}:sign`,
    `${namespace}:target_block`,
    `${namespace}:hacker_tnt`,
    `minecraft:armor_stand`,
    `minecraft:arrow`,
]

/**
 * 
 * @param {Player} player 
 */
export function infinityChestplate(player) {
    const loc = new Vector3().toVector(player.location)
    player.dimension.getEntities().filter(ent => !filter.includes(ent.typeId) && ent.id != player.id).forEach((ent) => {
        const entLoc = new Vector3().toVector(ent.location)
        const deltaLoc = entLoc.subtract(loc)
        const dist = Math.sqrt(Math.pow(deltaLoc.x, 2) + Math.pow(deltaLoc.y, 2) + Math.pow(deltaLoc.z, 2))
        if (dist < 5) {
            try {
                ent.applyKnockback(deltaLoc.x, deltaLoc.z, 0.5, 0.5)
                ent.applyDamage(7, { cause: EntityDamageCause.entityAttack, damagingEntity: player })
            }
            catch (e) {

            }
        }
    })
}