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

system.runInterval(() => {
    const schierkeEntities = world.getDimension("overworld").getEntities({ type: 'nb:schierke' });

    for (const schierke of schierkeEntities) {

        const velocity = schierke.getVelocity();
        const horizontalVelocity = Math.sqrt(velocity.x ** 2 + velocity.z ** 2);

        if (horizontalVelocity > 0.08) {
            schierke.runCommandAsync("playanimation @s animation.schierke.idle");
        } else {
            schierke.runCommandAsync("playanimation @s animation.schierke.idle");
        }
    }
}, 10); 