import { world, Items, ItemStack, Location, Entity, ItemEnchantsComponent, ItemTypes, EntityInventoryComponent, Block, Enchantment, MinecraftEnchantmentTypes } from "@minecraft/server"
import { system } from "@minecraft/server";
import { MinecraftEntityTypes, DynamicPropertiesDefinition, EntityQueryOptions } from "@minecraft/server"
import { ActionFormData, MessageFormData, ModalFormData } from "@minecraft/server-ui"

world.events.beforeItemUse.subscribe(data => {
  let { source: player } = data

    let invi = player.getComponent("inventory").container;
    let items = invi.getItem(player.selectedSlot);
    //this spawns the entity with a tag with the player name when the player does not have tag 'backpack1'
    if (items?.typeId == "pog:uncommon_lootbag") {
        player.runCommandAsync("function lootbag_uncommon")
    }
    if (items?.typeId == "pog:common_lootbag") {
      player.runCommandAsync("function common_lootbag")
  }
})