import { world, system } from "@minecraft/server";
import * as utils from "./utils";


export async function ItemUse(event)
{
	const cooldown = event.itemStack.getComponent("minecraft:cooldown");
	const nearbyEntities = event.source.dimension.getEntities({ location: event.source.location,maxDistance: 10})
	const nearbyMonsters = [];
	for(const entity2 of nearbyEntities){
		if(entity2.isValid()) {
			if (entity2.matches({families: ['monster'] }))
				nearbyMonsters.push(entity2);
		}
	}
	if(nearbyMonsters.length>0) {
		utils.runPlayerCommand(event.source, `execute rotated as @e[family=monster,c=1,r=10] positioned as @e[family=monster,c=1,r=10] at @e[family=monster,c=1,r=10] run tp @s ^ ^1 ^-4 ~ ~`);
		cooldown.startCooldown(event.source)
	}
}