import {
    DimensionType,
    DimensionTypes,
    EntityComponentTypes,
    EntityRideableComponent,
    system,
    world,
} from "@minecraft/server";
import { Entities } from "./Entities";

system.runInterval(() => {
    const entities = world.getDimension("overworld").getEntities();

    for (let entity of entities) {
        if (entity.matches({ type: "minecraft:boat" })) {
            /**
             * @type {EntityRideableComponent}
             */
            const rideable = entity.getComponent(EntityComponentTypes.Rideable);

            if (rideable) {
                const riders = rideable.getRiders();

                if (riders.length > 0) {
                    riders.forEach((rider) => {
                        if (Object.values(Entities).includes(rider.typeId)) {
                            rideable.ejectRider(rider);
                        }
                    });
                }
            }
        }
    }
}, 0.1 * 20);
