import { world } from "@minecraft/server";
import { CUSTOM_BARKS } from "./common/customBarks";
import { GOLEM } from "../entities/specific/golem";
import { CUSTOM_CROPS } from "../blocks/common/customCrops";
import { CACTUS_SPIKE_TRAPS } from "../blocks/common/cactusSpikeTraps";
import { ItemTags } from "./utils/itemConstants";

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

    const itemTypeId = itemStack.typeId
    const blockTypeId = block.typeId

    if (CUSTOM_BARKS.shouldDropBark(itemStack, block, source)) CUSTOM_BARKS.dropBark(block, source, itemStack)
    if (GOLEM.isGolemSpawnEgg(itemTypeId)) GOLEM.spawnGolem(ev)
    if (CUSTOM_CROPS.shouldGrow(itemTypeId, blockTypeId, source)) CUSTOM_CROPS.growCrop(block, source)
    if (CACTUS_SPIKE_TRAPS.isRepairingTrap(itemTypeId, block, source)) CACTUS_SPIKE_TRAPS.repairTrap(block, itemStack, source)
})