import { world, system, BlockComponent } from '@minecraft/server';
import { ActionFormData, ModalFormData } from '@minecraft/server-ui';

world.afterEvents.itemUse.subscribe(eventData => {
	let playername = eventData.source
	let itemUsed = eventData.itemStack
	let itemOffhand = playername.getComponent("equippable").getEquipment('Offhand')?.typeId
	let rawMessage = {
		rawtext: [
			{ translate: "its_ew.tutorial.intro"  , with: ["\n"] },
			{ translate: "its_ew.tutorial.shards" , with: ["\n"] },
			{ translate: "its_ew.tutorial.craft"  , with: ["\n"] },
			{ text: "§6"}, { translate: "item.its_ew:weapon.01.01" }, { text: "§r = §7"}, { translate: "item.wooden_sword.name"   }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.01.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.02.01" }, { text: "§r = §7"}, { translate: "item.stone_sword.name"    }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.02.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.03.01" }, { text: "§r = §7"}, { translate: "item.iron_sword.name"     }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.03.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.04.01" }, { text: "§r = §7"}, { translate: "item.golden_sword.name"   }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.04.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.05.01" }, { text: "§r = §7"}, { translate: "item.stone_axe.name"      }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.05.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.06.01" }, { text: "§r = §7"}, { translate: "item.stone_hoe.name"      }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.06.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.07.01" }, { text: "§r = §7"}, { translate: "item.wooden_shovel.name"  }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.07.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.08.01" }, { text: "§r = §7"}, { translate: "item.arrow.name"          }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.08.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.09.01" }, { text: "§r = §7"}, { translate: "item.trident.name"        }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.09.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.10.01" }, { text: "§r = §7"}, { translate: "item.wooden_axe.name"     }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.10.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.11.01" }, { text: "§r = §7"}, { translate: "item.diamond_sword.name"  }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.11.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.12.01" }, { text: "§r = §7"}, { translate: "item.brush.name"          }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.12.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.13.01" }, { text: "§r = §7"}, { translate: "item.wooden_hoe.name"     }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.13.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.14.01" }, { text: "§r = §7"}, { translate: "item.stick.name"          }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.14.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.15.01" }, { text: "§r = §7"}, { translate: "item.golden_shovel.name"  }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.15.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.16.01" }, { text: "§r = §7"}, { translate: "item.shears.name"         }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.16.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.17.01" }, { text: "§r = §7"}, { translate: "item.stone_pickaxe.name"  }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.17.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.18.01" }, { text: "§r = §7"}, { translate: "item.fishing_rod.name"    }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.18.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.19.01" }, { text: "§r = §7"}, { translate: "item.bone.name"           }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.19.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§6"}, { translate: "item.its_ew:weapon.20.01" }, { text: "§r = §7"}, { translate: "item.wooden_pickaxe.name" }, { text: "\n" },
			{ text: "§f"}, { translate: "its_ew.weapon.20.description" }, { text: "\n" }, { text: "\n" },
			{ text: "§r\n" },
			{ translate: "its_ew.tutorial.use"    , with: ["\n"] },
			{ translate: "its_ew.tutorial.upgrade", with: ["\n"] }
		]
	};
	if (itemUsed.typeId == 'its_ew:tutorial') {
		//world.sendMessage(rawMessage);
		let form = new ActionFormData();
		form.title("Evolving Weapons");
		form.body(rawMessage);
		form.button("Ok");

		form.show(playername)
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.01.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/effect @s strength 2 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/effect @s strength 3 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/effect @s strength 4 1")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_yellow ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.02.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/effect @s fire_resistance 2 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/effect @s fire_resistance 3 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/effect @s fire_resistance 4 2")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_red ~~1~-0.2")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_red ~~1~0.2")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.03.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] levitation 1 3")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] levitation 2 3")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] levitation 3 3")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_blue ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.04.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/effect @s speed 2 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/effect @s speed 3 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/effect @s speed 4 2")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_blue ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.05.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.axe.2")
			else playername.playAnimation("animation.its_ew.axe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				playername.runCommand("/execute positioned ^^^4 run scoreboard players set @e[r=4,name=!\"" + playername.name + "\",type=!item] its_ew.weapon5Countdown "+(70-damage*3))
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_black ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_black ~~1~-0.1")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_black ~~1~0.1")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.06.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.scythe.2")
			else playername.playAnimation("animation.its_ew.scythe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] weakness 1 3")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] weakness 2 3")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] weakness 3 3")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_black ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_black ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_black ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.07.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.axe.2")
			else playername.playAnimation("animation.its_ew.axe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				playername.runCommand("/execute positioned ^^^4 run tag @e[r=4,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon5.knocked")
				world.getDimension("Overworld").getEntities({
					tags:["its_ew.weapon5.knocked"]
				}).forEach((knocked)=>{
					if (knocked.hasComponent("health")){
						knocked.applyKnockback(0,0,0,0.5+damage/20)
						knocked.removeTag("its_ew.weapon5.knocked")
					}
				})
				playername.runCommand("/playsound its_ew.punch @a[r=20] ~~~ 1 1")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/playsound its_ew.punch @a[r=20] ~~~ 1 1")
			}, 12)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~2~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.08.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_yellow ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 4+damage/5, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.09.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run tag @e[r=4,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon9.knocked")
				world.getDimension("Overworld").getEntities({
					tags:["its_ew.weapon9.knocked"]
				}).forEach((infested)=>{
					if (infested.hasComponent("health")){
						infested.runCommand("/scoreboard players set @s its_ew.weapon9Countdown "+(80+damage*4))
						infested.removeTag("its_ew.weapon9.knocked")
					}
				})
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_blue ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 3, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.10.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.axe.2")
			else playername.playAnimation("animation.its_ew.axe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] slowness 1 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] slowness 2 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] slowness 3 3")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_yellow ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.11.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] poison 2 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] poison 3 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] poison 4 1")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_green ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_green ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_green ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.12.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				let explosionx = playername.location.x
				let explosiony = playername.location.y
				let explosionz = playername.location.z
				let rotx = playername.getRotation().x
				let roty = playername.getRotation().y
				for (let k =0; k<=Number(itemUsed.typeId.slice(-2))+2; k++){
					system.runTimeout(() => {playername.runCommand("/execute rotated "+roty+" "+0+" positioned "+explosionx+" "+explosiony+" "+explosionz+" positioned ^^^"+k*4+" run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + Math.max(Math.floor(damage/2),1) + " entity_attack entity @s")}, k*5)
					system.runTimeout(() => {playername.runCommand("/execute rotated "+roty+" "+0+" positioned "+explosionx+" "+explosiony+" "+explosionz+" positioned ^^^"+k*4+" run particle its_ew:weapon12_explosion")}, k*5)
					system.runTimeout(() => {playername.runCommand("/execute rotated "+roty+" "+0+" positioned "+explosionx+" "+explosiony+" "+explosionz+" positioned ^^^"+k*4+" run playsound break.large_amethyst_bud @a[r=20]")}, k*5)
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_red ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.13.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.scythe.2")
			else playername.playAnimation("animation.its_ew.scythe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				if (Number(itemUsed.typeId.slice(-2)) <= 5) { 
					playername.runCommand("/damage @e[r=7,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) { 
					playername.runCommand("/damage @e[r=9,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) { 
					playername.runCommand("/damage @e[r=13,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				}
				playername.runCommand("/execute positioned ~~~ run particle its_ew:weapon13_slash")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ~~-1~ run particle its_ew:weapon13_slash2")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_blue ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_blue ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.14.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.cast.2")
			else playername.playAnimation("animation.its_ew.cast.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.getComponent("health").setCurrentValue(
				playername.getComponent("health").currentValue + damage)
			}, 10
			)
			if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing1 ~~1~")
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing1 ~~1~")
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing1 ~~0~")
			system.runTimeout(() => {

				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.healing1 @a[r=20] ~~~ 1 " + pitch)
			}, 8)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.15.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.axe.2")
			else playername.playAnimation("animation.its_ew.axe.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] nausea 4 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] nausea 5 2")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] nausea 6 3")
				}
				playername.runCommand("/playsound its_ew.punch @a[r=20] ~~~ 1 1")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/playsound its_ew.punch @a[r=20] ~~~ 1 1")
			}, 12)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.16.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/effect @s invisibility 2 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/effect @s invisibility 3 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/effect @s invisibility 4 1")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_purple ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_purple ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_purple ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 3, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.17.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] hunger 5 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] hunger 10 1")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run effect @e[r=4,name=!\"" + playername.name + "\",type=!item] hunger 15 1")
				}
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_red ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_red ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.18.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.pierce.2")
			else playername.playAnimation("animation.its_ew.pierce.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=5,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
				if (Number(itemUsed.typeId.slice(-2)) <= 5) {
					playername.runCommand("/execute positioned ^^^4 run tag @e[r=5,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon18.hit")
				}
				else if (Number(itemUsed.typeId.slice(-2)) <= 9) {
					playername.runCommand("/execute positioned ^^^4 run tag @e[r=7,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon18.hit")
				}
				else if (Number(itemUsed.typeId.slice(-2)) >= 10) {
					playername.runCommand("/execute positioned ^^^4 run tag @e[r=9,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon18.hit")
				}
				
				playername.runCommand("/execute rotated ~ 0 positioned ^^^8 run tp @e[tag=its_ew.weapon18.hit] ~~~ true")
				playername.runCommand("/execute rotated ~ 0 positioned ^^^8 run particle its_ew:weapon19_explosion")
				playername.runCommand("/execute positioned ^^^4 run tag @e remove its_ew.weapon18.hit")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_yellow ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_yellow ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 3, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.19.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.sword.2")
			else playername.playAnimation("animation.its_ew.sword.1")
			let damage = Number(itemUsed.typeId.slice(-2))
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 2)
			system.runTimeout(() => {
				playername.runCommand("/execute positioned ^^^4 run tag @e[r=4,name=!\"" + playername.name + "\",type=!item] add its_ew.weapon19.knocked")
				world.getDimension("Overworld").getEntities({
					tags:["its_ew.weapon19.knocked"]
				}).forEach((infested)=>{
					if (infested.hasComponent("health")){
						infested.runCommand("/scoreboard players set @s its_ew.weapon19Countdown 100")
						system.runTimeout(() => {
							infested.runCommand("execute if score @s its_ew.weapon19Countdown matches ..1 run tp @e[r="+(damage+5)+",name=!\"" + playername.name + "\",type=!item,family=mob] @s")
							infested.runCommand("execute if score @s its_ew.weapon19Countdown matches ..1 run tp @e[r="+(damage+5)+",name=!\"" + playername.name + "\",type=!item,family=monster] @s")
							infested.runCommand("execute if score @s its_ew.weapon19Countdown matches ..1 run tp @e[r="+(damage+5)+",name=!\"" + playername.name + "\",type=!item,type=item] @s")
						},100)
						infested.removeTag("its_ew.weapon19.knocked")
					}
				})
				playername.runCommand("/execute positioned ^^^4 run damage @e[r=4,name=!\"" + playername.name + "\",type=!item] " + damage + " entity_attack entity @s")
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-vertical_black ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash_black ~~1~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute positioned ^^^4 as @e[r=4,name=!\"" + playername.name + "\",type=!item] at @s run particle its_ew:slash-mirror_black ~~1~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.slash @a[r=20] ~~~ 1 " + pitch)
			}, 8)
			playername.applyKnockback(playername.getViewDirection().x, playername.getViewDirection().z, 2, 0.5)
		}
	}
	else if (itemUsed.typeId.match('^its_ew:weapon.20.')) {
		if (itemUsed.getComponent("cooldown").getCooldownTicksRemaining(playername) == itemUsed.getComponent("cooldown").cooldownTicks - 1) {
			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.playAnimation("animation.its_ew.cast.2")
			else playername.playAnimation("animation.its_ew.cast.1")
			let damage = Math.floor(Number(itemUsed.typeId.slice(-2))/2)
			let targets = world.getDimension("Overworld").getEntities({
				location: playername.location,
				maxDistance: 15
			})

			if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) damage += Math.floor(Number(itemOffhand?.slice(-2)) / 4)
			system.runTimeout(() => {
				targets.forEach((target) => (
					target.getComponent("health")?.setCurrentValue(playername.getComponent("health").currentValue + damage)
				)
				)
			}, 10)
			system.runTimeout(() => {
				if (itemOffhand?.slice(0, 16) != itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing2 ~~0~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing2 ~~0~")
				if (itemOffhand?.slice(0, 16) == itemUsed.typeId.slice(0, 16)) playername.runCommand("/execute at @s run particle its_ew:healing2 ~~0~")
				let pitch = 1 + (Math.random(0, 1) - 0.5) / 2
				playername.runCommand("/playsound its_ew.healing2 @a[r=20] ~~~ 10 " + pitch)
			}, 8)
		}
	}
}),

	world.beforeEvents.entityRemove.subscribe(event => {
		let target = event.removedEntity;
		let x = event.removedEntity.location.x;
		let y = event.removedEntity.location.y;
		let z = event.removedEntity.location.z;

		if (target.typeId == "minecraft:wither" || target.typeId == "minecraft:ender_dragon" || target.typeId == "minecraft:warden" || target.typeId == "minecraft:elder_guardian" || target.hasTag == "its_ew.boss") {
			var command = 'loot spawn ' + x + ' ' + y + ' ' + z + ' loot "its/ew/soul_shard/epic"';
			system.run(() => {
				world.getDimension("overworld").runCommand(command)
			});
			var spawn_loot = true;
		}

	}),




	world.afterEvents.entityRemove.subscribe(event => {
		if (spawn_loot == true) {
			world.getDimension("overworld").sendMessage(command);
			var spawn_loot = false;
		}

	}),

	world.afterEvents.entityDie.subscribe(event => {
		const target = event.deadEntity.typeId;
		const killer = event.damageSource.damagingEntity ?? target;
		if (event.damageSource.cause != "entityAttack") return;
		if (target == "undefined") return;

		if (killer.typeId == "minecraft:player") {
			if (event.deadEntity.hasTag("its_ew.boss")) event.deadEntity.runCommand('loot spawn ~~~ loot "its/ew/soul_shard/epic"');
			else if (event.deadEntity.hasTag("its_ew.monster")) event.deadEntity.runCommand('loot spawn ~~~ loot "its/ew/soul_shard/rare"');
			else if (event.deadEntity.hasTag("its_ew.mob")) event.deadEntity.runCommand('loot spawn ~~~ loot "its/ew/soul_shard/common"');
		}
		event.deadEntity.runCommand('execute if score @s its_ew.weapon9Countdown matches 0.. run loot spawn ~~~ loot "its/ew/weapon9_drops"');
		event.deadEntity.runCommand('execute if score @s its_ew.weapon9Countdown matches 0.. run particle its_ew:weapon9_explosion');

	});