import { system, world } from "@minecraft/server";
import { NAMESPACE } from "./anvilConstants";

try {
    system.runInterval(() => {
        const getVehicles = world.getDimension("overworld").getEntities({ families: [`${NAMESPACE}:air_vehicle`] });
        const getVehiclesN = world.getDimension("nether").getEntities({ families: [`${NAMESPACE}:air_vehicle`] });
        const getVehiclesE = world.getDimension("the_end").getEntities({ families: [`${NAMESPACE}:air_vehicle`] });

        getVehicles.push(...getVehiclesN, ...getVehiclesE);

        for (let vehicle of getVehicles) {
            const rideableComponent = vehicle.getComponent("minecraft:rideable");
            const rider = rideableComponent.getRiders()[0];
            if (rider) {
            	vehicle.runCommand(`/camera "${rider.name}" set minecraft:free ease 0.05 in_out_circ pos ^ ^15 ^-20 facing ^ ^ ^`);
                if (rider.isJumping) {
                    vehicle.addEffect("levitation", 2, { amplifier: 10, showParticles: false });
                } else {
                    vehicle.addEffect("slow_falling", 20, { amplifier: 10, showParticles: false });
                }
            }
        }
    })
} catch (e) { }