import { world } from "@minecraft/server";
import { CUSTOM_HEADS } from "./common/customHeads";
import { CUSTOM_SLABS } from "./common/customSlabs";
import { EntityComponents} from "../entities/utils/entityComponents";

world.beforeEvents.itemUseOn.subscribe(ev => {
    const {block, blockFace, cancel, faceLocation, itemStack, source} = ev;

    const itemStackId = itemStack.typeId
    const blockId = block.typeId
    const equippable = EntityComponents.getEquippable(source)

    // Custom Heads 
    if (CUSTOM_HEADS.isUsing(itemStackId)) CUSTOM_HEADS.useHead(block, source, blockFace, itemStack, equippable)
    // Custom Slabs
    if (CUSTOM_SLABS.isPlacing(itemStackId, source)) CUSTOM_SLABS.placeBlock(block, source, blockFace, itemStack, faceLocation, cancel)
    if (CUSTOM_SLABS.isWaterLogging(blockId, source, itemStackId)) CUSTOM_SLABS.waterLog(ev)
})
