import { world, Player, Entity, ItemStack, Block, BlockPermutation, MolangVariableMap, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
import { applySelfKnockback, applyVarious, damageItemDurability, decrementStack, getEntitiesInRange, giveCommand, shiftLocation, shootProjectile, spawnRideEntity, clearAllSkill } from "./function";
import { setScoreUtility, operationScoreUtility, getScoreUtility } from "./scoreboard";
import { operationStatus } from "./status";


/**
 * @param {ItemStack} itemStack 
 * @param {Player} player
 */
export function hotbar_0(itemStack,player){
    const itemId = itemStack.typeId;

    if(itemId.startsWith("hxc:hotbar_0_status")){
        operationStatus(player);
    }
}
/**
 * @param {ItemStack} itemStack 
 * @param {Player} player 
 */
export function random_hatsu(itemStack,player){
    if(player.hasTag("nen_control")){
        const random = getScoreUtility(player,"random_hatsu");
        player.runCommand("scoreboard players random @s random_hatsu 1 6");
        if(random == 1){
            player.setProperty("hxc:hatsu",1);
            player.runCommand("function advancement/hatsu/gon");
        }
        else if(random == 2){
            player.setProperty("hxc:hatsu",2);
            player.runCommand("function advancement/hatsu/killua");
        }
        else if(random == 3){
            player.setProperty("hxc:hatsu",3);
            player.runCommand("function advancement/hatsu/uvogin");
        }
        else if(random == 4){
            player.setProperty("hxc:hatsu",4);
            player.runCommand("function advancement/hatsu/meruem");
        }
        else if(random == 5){
            player.setProperty("hxc:hatsu",5);
            player.runCommand("function advancement/hatsu/feitan");
        }
        else if(random == 6){
            player.setProperty("hxc:hatsu",6);
            player.runCommand("function advancement/hatsu/netero");
        }
        else if(true){
            player.setProperty("hxc:hatsu",0);
        }
        decrementStack(player,1);
        clearAllSkill(player);
    }
    else{
        player.sendMessage({rawtext:[{translate:"form.status.nenControl.error"}]});
    }
}
/**
 * @param {Player} player 
 * @param {ItemStack} itemStack 
 * @param {Block} block 
 */
export function structure_load(player,itemStack,block){
    const itemId = itemStack.typeId;
    const blockLoc = block.location;
    world.structureManager.place(itemId.split("hxc:structure_")[1],player.dimension,blockLoc);
    decrementStack(player,1);
}