import { world } from "@minecraft/server";

world.afterEvents.entityDie.subscribe((data) => {
	try {
		const celestial = ["minecraft:phantom"];
		const cosmic = ["minecraft:enderman"];
		const fire = ["minecraft:blaze"];
		const ice = ["minecraft:stray"];
		const kyro = ["minecraft:husk"];
		const laser = ["minecraft:guardian"];
		const poison = ["minecraft:cave_spider"];
		const skull = ["minecraft:skeleton"];
		const vampire = ["minecraft:bat"];
		const water = ["minecraft:drowned"];
		const shadow = ["minecraft:vex", "minecraft:evocation_illager"];
		const titan = ["minecraft:iron_golem", "minecraft:ravager"];
		const entity = data.deadEntity;
		const entityLocation = entity.location;
		const location = {
			x: entityLocation.x,
			y: entityLocation.y,
			z: entityLocation.z,
		};
		//Celestial
		if (celestial.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_celestial"`,
			);
		}
		//Cosmic
		if (cosmic.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_cosmic"`,
			);
		}
		//Fire
		if (fire.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_fire"`,
			);
		}
		//Ice
		if (ice.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_ice"`,
			);
		}
		//Kyro
		if (kyro.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_kyro"`,
			);
		}
		//Laser
		if (laser.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_laser"`,
			);
		}
		//Poison
		if (poison.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_poison"`,
			);
		}
		//Skull
		if (skull.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_skull"`,
			);
		}
		//Vampire
		if (vampire.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_vampire"`,
			);
		}
		//Water
		if (water.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_water"`,
			);
		}
		//Shadow
		if (shadow.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_shadow"`,
			);
		}
		//Titan
		if (titan.includes(entity.typeId)) {
			entity.dimension.runCommand(
				`loot spawn ${location.x} ${location.y} ${location.z} loot "manalabs/opw/essence_titan"`,
			);
		}
	} catch (error) {}
});
