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

export async function onTick()
{
	for (const entity of utils.overworld.getEntities())
	{
		if (entity == undefined)
			continue;
		if (entity.typeId !== "pu_se:dragon_projectile")
			continue;

		else {
			const nearbyEntities = entity.dimension.getEntities({ location: entity.location,maxDistance: 4,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.setOnFire(8);
					if(typeof entity2.applyKnockback === 'function') entity2.applyKnockback(entity2.location.x, entity2.location.z, 1, 0.5);
				}
			}
		}
	}
}