import { system, world, Entity, Player } from '@minecraft/server'

world.afterEvents.entityHitEntity.subscribe((event) => {
	let damagingEntity = event.damagingEntity;
	const player = event.damagingEntity
	if (player.getDynamicProperty('mte_cog_axe') == undefined) {
		player.setDynamicProperty('mte_cog_axe', 0)
	}
	if ((damagingEntity.typeId == 'minecraft:player' && damagingEntity.getComponent('inventory').container.getItem(player.selectedSlot).typeId == 'redstone:cog_axe') == true) {
		const entity = event.hitEntity;
		player.runCommandAsync('playsound redstone.cog_axe')
		if (player.getEffect('strength') == false) {
			player.setDynamicProperty('mte_cog_axe', 0)
		}
		player.setDynamicProperty('mte_cog_axe', player.getDynamicProperty('mte_cog_axe') + 1)
		player.runCommandAsync('effect @s strength 2 ' + player.getDynamicProperty('mte_cog_axe') + ' true')
	}
})