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


export async function ItemUse(event)
{
	utils.runPlayerCommand(event.source, `execute rotated as @s run summon pu_se:tnt_shooter_utility ^ ^1 ^1 ~ ~ pu_se:shoot_ice`);
	utils.runPlayerCommand(event.source, "playsound pu_se:ice_shield_use @s ~ ~ ~");
}

export async function onProjectileHitEntity(event)
{
	const hitEntity = event.getEntityHit().entity;
	const nearbyEntities = hitEntity.dimension.getEntities({ location: hitEntity.location,maxDistance: 5,excludeTypes: ["minecraft:player", "pu_se:ice_projectile"]})
	for(const entity2 of nearbyEntities){
		if(entity2.isValid()){
			utils.runPlayerCommand(entity2, `execute if entity @s[type=!player,type=!pu_se:ice_projectile] run effect @s slowness 10 255 false`);
			utils.runPlayerCommand(entity2, `execute if entity @s[type=!player,type=!pu_se:ice_projectile] run summon pu_se:ice_utility ~ ~ ~ ~ ~`);
		}
	}
}