import { world } from "@minecraft/server";
import { VENOMITE_TOOLS } from "../items/common/venomiteTools";
import { CUSTOM_DURABILITY } from "../items/common/customDurability";
import { CUSTOM_TORCHES } from "./common/customTorches";
import { CUSTOM_SLABS } from "./common/customSlabs";
import { CUSTOM_BRICKS } from "./common/customBricks";
import { CUSTOM_PILLARS } from "./common/customPillars";
import { CACTUS_SPIKE_TRAPS } from "./common/cactusSpikeTraps";
import { CUSTOM_ORES } from "./common/customOres";

world.beforeEvents.playerBreakBlock.subscribe(ev => {
    const {block, dimension, itemStack, player} = ev

    const gameMode = player.getGameMode()
    const itemStackId = itemStack?.typeId
    const blockId = block.typeId
    const location = block.location

    if (VENOMITE_TOOLS.isVenomiteTool(itemStackId)) VENOMITE_TOOLS.applyVenomBreak(block, itemStack)
    if (CUSTOM_DURABILITY.shouldDamageItem(gameMode, block, itemStack)) CUSTOM_DURABILITY.damageItem(player)
    if (CUSTOM_TORCHES.isCustomTorch(block)) CUSTOM_TORCHES.wasDestroyed(dimension, location)
    if (CACTUS_SPIKE_TRAPS.isCactusSpikeTrap(block)) CACTUS_SPIKE_TRAPS.wasDestroyed(dimension, location)
    if (CUSTOM_SLABS.isCustomSlab(blockId)) CUSTOM_SLABS.dropDoubleLoot(block, dimension, itemStack, player)
    if (CUSTOM_BRICKS.isCustomBrick(block)) CUSTOM_BRICKS.dropLoot(block, dimension, itemStack, player)
    if (CUSTOM_PILLARS.isCustomPillar(block)) CUSTOM_PILLARS.dropLoot(block, dimension, itemStack, player)
    if (CUSTOM_ORES.shouldDropXp(block, player, itemStack)) CUSTOM_ORES.dropXpOrb(block)
})