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_warden`);
}

export async function onProjectileHitEntity(event)
{
	const hitEntity = event.getEntityHit().entity;
	const nearbyEntities = hitEntity.dimension.getEntities({ location: hitEntity.location,maxDistance: 3,excludeTypes: ["minecraft:falling_block", "minecraft:player", "pu_se:dragon_projectile", "pu_se:ice_projectile", "pu_se:magma_projectile", "pu_se:tnt_projectile", "pu_se:warden_projectile", "minecraft:boat", "minecraft:chest_boat", "minecraft:minecart", "minecraft:chest_minecart", "minecraft:command_block_minecart", "minecraft:hopper_minecart", "minecraft:tnt_minecart", "minecraft:leash_knot", "minecraft:xp_orb", "minecraft:item", "minecraft:armor_stand", "minecraft:ender_crystal", "minecraft:minecart"]})
	for(const entity2 of nearbyEntities){
		if(entity2.isValid()){
			entity2.applyDamage(6);
			if(typeof entity2.applyKnockback === 'function') entity2.applyKnockback(event.location.x, event.location.z, 3, 0.75);
		}
	}
}