import { SuppTags } from "../reg/suppTags";
import { SuppStates } from "../reg/suppStates";
import { randomInt } from "../util/mthUtils";
import { suppEvents } from "../suppEventHandler";
import { breakBlock, getItemInHand } from "../util/miscUtils";
export const ChalkItemComponent = {
    onUseOn(event) {
        //GG, cant use this because we cant use the beforeOnPlaeyrPlace and thus the block is always placed...
    }
};
export const ChalkBlockComponent = {
    beforeOnPlayerPlace: (event) => {
        event.permutationToPlace = event.permutationToPlace.withState(SuppStates.Design, randomInt(0, 3));
    },
    onPlayerInteract: (event) => {
        //todo: remove when the above event starts to be called
        const block = event.block;
        const item = getItemInHand(event.player);
        if (item && block.typeId == item.typeId) {
            const drawing = block.permutation.getState(SuppStates.Design);
            // console.log("Chalk block found"+drawing);
            block.setPermutation(block.permutation.withState(SuppStates.Design, (drawing + 1) % 4));
            //TODO: sound
        }
    },
    onPlace: (event) => {
        //TODO: remove when beforeOnPlayerPlace starts to be called
        event.block.setPermutation(event.block.permutation.withState(SuppStates.Design, randomInt(0, 3)));
    }
};
suppEvents.subscribeOnPistonPushed((event) => {
    for (const block of event.attachedBlocks) {
        if (block.hasTag(SuppTags.Chalks)) {
            breakBlock(block);
        }
    }
});
