import { world } from '@minecraft/server';
import { getEntityHeldItem } from '../../utils/players.js';
import { FSTags } from '../../constants.js';
import { spawnLootAtBlock } from '../../utils/utils.js';
import { PLAYER_SNEAK_GRASS_ROCKS } from '../../settings/settings.js';
import { Keys as x } from '../../ftb_bedrock_bedrock_utils_dist_bedrock_utils.js';

world.afterEvents.entityHitBlock.subscribe(event => {
    const block = event.hitBlock;
    const entity = event.damagingEntity;
    if (!entity.isSneaking) {
        return;
    }
    if (!PLAYER_SNEAK_GRASS_ROCKS.getValue(entity)) {
        return;
    }
    const playerHeldItem = getEntityHeldItem(entity);
    if (playerHeldItem) {
        return;
    }
    if (!FSTags.DirtLikeBlocks.includes(block?.typeId)) {
        return;
    }
    spawnLootAtBlock(block, x.SIEVES + "/world/rocks");
});
