import { world, ItemStack, system } from "@minecraft/server";
import { flowers } from "./flower_pot_additions";

world.beforeEvents.playerInteractWithBlock.subscribe(eventData => {
    if (!eventData.isFirstEvent) return;
    const player = eventData.player;
    const block = eventData.block;
    const item = eventData.itemStack;
    if (block.typeId != "rustic:flower_pot") return;
    const variant = block.permutation.getState("r:variants");
    if ( variant === 0 ) return;
    const flowerData = Object.entries(flowers).find(([key, value]) => value.permutation === variant);
    if (!flowerData) return;
    const [key, value] = flowerData;
    system.run( () => {
        player.getComponent('inventory').container.addItem(new ItemStack(key, 1));
        block.setType("minecraft:flower_pot")
    })
});