import { BlockPermutation, GameMode, Player, world } from "@minecraft/server";

const DetectTreadersBlockComponent = {
    onStepOn({ entity, block }) {
        if (entity instanceof Player && entity.getGameMode() === GameMode.creative) return;

        block.setPermutation(
            BlockPermutation.resolve(block.typeId, {
                "bumble:stood_on": true,
            })
        );
    },
    onStepOff({ entity, block }) {
        if (entity instanceof Player && entity.getGameMode() === GameMode.creative) return;

        block.setPermutation(
            BlockPermutation.resolve(block.typeId, {
                "bumble:stood_on": false,
            })
        );
    },
};

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "bumble:detect_treaders",
        DetectTreadersBlockComponent
    );
});