import { world, system, Vector, BlockTypes } from "@minecraft/server"

system.runInterval(() => {
    world.getAllPlayers().forEach((player) => {

        world.getDimension(player.dimension.id).getEntities({ type: 'better_on_bedrock:legrang' }).forEach((pig) => {
            if(pig.getComponent('variant')?.value == 1 || Vector.distance(pig.location, player.location) >= 8){
                pig.applyImpulse(new Vector(player.location.x - pig.location.x, player.location.y - pig.location.y, player.location.z - pig.location.z))
            }
            
        })

    });
}, 40);