
import { world, ItemStack, system } from "@minecraft/server";
import * as utils from "../utils.js";
const dimensions = [
    world.getDimension("overworld"),
    world.getDimension("nether"),
    world.getDimension("the_end")
];

export async function onTick() {
    for (const dimension of dimensions) {
        const ninja_stars = dimension.getEntities();
        for (const ninja_star of ninja_stars) {
            if (ninja_star.typeId === "pu_sg:ninja_star_projectile" && ninja_star.hasTag("pu_sg_on_ground")) {
                system.runTimeout(() => {
                    const ninjaStarItem = new ItemStack("pu_sg:ninja_star");
                    try {
                        if (!ninja_star || !ninja_star.isValid()) return;
                        const ninjaStarLoc = ninja_star?.location;
                        dimension.spawnItem(ninjaStarItem, ninjaStarLoc);
                    } catch (error) {
                    }
                    ninja_star?.remove();
                    return;
                }, 20);
            }
        }
    }
}


export async function onEntitySpawn(event) {
    const entity = event.entity;
    if (entity.typeId === "pu_sg:ninja_star_projectile") {
        entity.dimension.playSound("pu_sg:ninja_star_throw", entity.location);
    }
}