import { world, system, EquipmentSlot } from "@minecraft/server";
import * as book from "./book";
import * as load_base from "./load_base";
import * as game from "./game";

export async function onLoadFirstTime() {
	
}

export async function onLoad() {
}

export async function onTick() {
	load_base.onTick();
}

export async function onPlayerSpawn(event) {

}


export async function onItemUse(event) {
	if (event.itemStack === undefined)
		return;

	let itemTypeId = event.itemStack.typeId;

	if (itemTypeId === "tcs_cba:starter_kit"){
		let player = event.source;
		game.runPlayerCommand(player, `clear @s tcs_cba:starter_kit 0 1`);
		game.runPlayerCommand(player, `playsound tcs_cba:reward @s ~ ~ ~ 100 1 1`);
		game.runPlayerCommand(player, `particle tcs_cba:open_starter_kit ~ ~ ~`);
		game.runPlayerCommand(player, `particle tcs_cba:open_starter_kit_2 ~ ~ ~`);
		game.runPlayerCommand(player, `structure load tcs_cba:starter_kit_loot ~ ~ ~`);
		game.actionbar(player, "@s", `§aCongratulations - you got the starter kit!`);
	}

	await load_base.onItemUse(event);
	
}

export async function onScriptEventReceive(event) {
	if (event.id === "tcs_cba:build_base")
		load_base.onScriptEventReceive(event);

	if (event.id === "tcs_cba:hit_book" || event.id === "tcs_cba:open_book")
		book.onScriptEventReceive(event);
}