import { world, BlockComponentPlayerDestroyEvent } from '@minecraft/server';

const itemAttackEvent = {
	onHitEntity(event) {
		let i = event.itemStack,
		    p = event.attackingEntity,
		    t = event.hitEntity;
	}
};

const BlockComponentPlayerDestroyEvent = {
	onPlayerDestroy(event) {
		let nb = event.block,
		    d = event.dimension,
		    lb = event.destroyedBlockPermutation;
		let l = nb.location;
		world.sendMessage(`${lb.type}`);
		switch (lb.type) {
		case 'zy:crazigold_ore':
		case 'zy:deepslate_crazigold_ore':
			//world.sendMessage('a');
			d.runCommandAsync(`loot spawn ${l.x} ${l.y} ${l.z} loot \"crazigold_ore\"`);
			break;
		case 'zy:healthsand_ore':
		case 'zy:deepslate_healthsand_ore':
			//world.sendMessgae('b');
			d.runCommandAsync(`loot spawn ${l.x} ${l.y} ${l.z} loot \"healthsand_ore\"`);
			break;
		}
	}
};

world.beforeEvents.worldInitialize.subscribe((component) => {
	let item = component.itemComponentRegistry,
	    block = component.blockComponentRegistry;
	//item.registerCustomComponent('zy:attackable', itemAttackEvent);
	block.registerCustomComponent('zy:maydestroy', BlockComponentPlayerDestroyEvent);
});