import { world, system } from "@minecraft/server";
import { ActionFormData, ModalFormData } from "@minecraft/server-ui";
import "./form";




system.runInterval(() => {
    const entityType = "rl_cr:car";

    const scorePropertyPairs = [
        { score: "paint", property: "rl_cr:paint" },
        { score: "wheel", property: "rl_cr:wheel" },
        { score: "bumper", property: "rl_cr:bumper" },
        { score: "hood", property: "rl_cr:hood" },
        { score: "roof", property: "rl_cr:roof" },
        { score: "spoiler", property: "rl_cr:spoiler" },
        { score: "exhaust", property: "rl_cr:exhaust" },
        { score: "vinyl", property: "rl_cr:vinyl" },
        { score: "glass", property: "rl_cr:glass" },
        { score: "horn", property: "rl_cr:horn" }
    ];

    let entities = world.getDimension("overworld").getEntities({
        type: entityType
    });

    for (let entity of entities) {
        for (let pair of scorePropertyPairs) {
            let entityScore = world.scoreboard.getObjective(pair.score)?.getScore(entity);

            if (entityScore !== undefined) {
                entity.setProperty(pair.property, entityScore);
            }
        }
    }
}, 1);

system.runInterval(() => {
    const entityType = "rl_cr:car2";

    const scorePropertyPairs = [
        { score: "paint", property: "rl_cr:paint" },
        { score: "wheel", property: "rl_cr:wheel" },
        { score: "bumper", property: "rl_cr:bumper" },
        { score: "hood", property: "rl_cr:hood" },
        { score: "roof", property: "rl_cr:roof" },
        { score: "spoiler", property: "rl_cr:spoiler" },
        { score: "exhaust", property: "rl_cr:exhaust" },
        { score: "vinyl", property: "rl_cr:vinyl" },
        { score: "glass", property: "rl_cr:glass" },
        { score: "horn", property: "rl_cr:horn" }
    ];

    let entities = world.getDimension("overworld").getEntities({
        type: entityType
    });

    for (let entity of entities) {
        for (let pair of scorePropertyPairs) {
            let entityScore = world.scoreboard.getObjective(pair.score)?.getScore(entity);

            if (entityScore !== undefined) {
                entity.setProperty(pair.property, entityScore);
            }
        }
    }
}, 1);

system.runInterval(() => {
    const entityType = "rl_cr:car_test";

    const scorePropertyPairs = [
        { score: "paint", property: "rl_cr:paint" },
        { score: "wheel", property: "rl_cr:wheel" },
        { score: "bumper", property: "rl_cr:bumper" },
        { score: "hood", property: "rl_cr:hood" },
        { score: "roof", property: "rl_cr:roof" },
        { score: "spoiler", property: "rl_cr:spoiler" },
        { score: "exhaust", property: "rl_cr:exhaust" },
        { score: "vinyl", property: "rl_cr:vinyl" },
        { score: "glass", property: "rl_cr:glass" },
        { score: "horn", property: "rl_cr:horn" }
    ];

    let entities = world.getDimension("overworld").getEntities({
        type: entityType
    });

    for (let entity of entities) {
        for (let pair of scorePropertyPairs) {
            let entityScore = world.scoreboard.getObjective(pair.score)?.getScore(entity);

            if (entityScore !== undefined) {
                entity.setProperty(pair.property, entityScore);
            }
        }
    }
}, 1);

system.runInterval(() => {
    const entityType = "rl_cr:car_bot";

    const scorePropertyPairs = [
        { score: "paint", property: "rl_cr:paint" },
        { score: "wheel", property: "rl_cr:wheel" },
        { score: "bumper", property: "rl_cr:bumper" },
        { score: "hood", property: "rl_cr:hood" },
        { score: "roof", property: "rl_cr:roof" },
        { score: "spoiler", property: "rl_cr:spoiler" },
        { score: "exhaust", property: "rl_cr:exhaust" },
        { score: "vinyl", property: "rl_cr:vinyl" },
        { score: "glass", property: "rl_cr:glass" },
        { score: "horn", property: "rl_cr:horn" }
    ];

    let entities = world.getDimension("overworld").getEntities({
        type: entityType
    });

    for (let entity of entities) {
        for (let pair of scorePropertyPairs) {
            let entityScore = world.scoreboard.getObjective(pair.score)?.getScore(entity);

            if (entityScore !== undefined) {
                entity.setProperty(pair.property, entityScore);
            }
        }
    }
}, 1); 