// main script file for Horses! Add-On
// made by InnerTri





// Imports
// Important Global Variables
import {
    world,
    system
} from "@minecraft/server";

// Utility functions
import { getRandomFloat, getRandomInt } from "./utility.js";

// Functions and Event Subscriptions
// TODO: Should probably change these to import ONLY the necessary functions,
// instead of the ENTIRE file.
// currently doing the whole file since I'm not 100% sure how to import
// JUST the event subscriptions. But I know if I import the whole file,
// they work - probably just need to encapsulate them in another function,
// and then run that function once here in main.
// Always learning!

import "./guideBook.js";
import "./horseReplacement.js";
import "./horseProperties.js";
import "./horseEquipment.js";
import "./bucketRefund.js";
import "./horseInheritance.js";
import "./horseAbilities.js";
import "./breathAttack.js";
import { whistleHorse } from "./horse_whistle.js";
import { flyerFlight } from "./flyer_flight.js";
import "./seahorse_bucket.js"





// ScriptEvents are done in their respective scripts
// it might not be ideal to have multiple scripts with their own ScriptEvent subscriptions,
// as compared to one mega-scriptevent-manager subscription here in main,
// but it's much more clean and understandable
// if I learn that this is indeed bad practice,
// I will most likely have to consolidate them all here
// but until then, I prefer it this way





// Subscriptions for item usage events
// This will later be updated to custom item components,
// as I don't like the idea of checking if the player is holding a whistle
// EVERY time ANY player EVER right clicks with ANY item
// doesn't seem very performant! especially since potentially
// every other add-on on the player's world could be using this same subscription
// if they have even 5 add-ons active, right clicking with ANY item *could* result
// in lag! hopefully I think it's a bigger deal than it really is
world.afterEvents.itemUse.subscribe( 
	event => {
		// save the event parameters for convenience
		const {source: player, itemStack: item } = event;

		// check what item is being used
		switch (item.typeId) {

			// Horse Whistling
			// This is done here since it seems unneccessary to import the ENTIRE horse whistle file
			// I do admit, however, that having the main whistle function here, instead of there, is
			// a little less clear
			case "cyn_hao:horse_whistle":
				whistleHorse(player);
			return;
		}
	}
);



function runOnce() {
	
}
runOnce();



// Define what is to happen every tick
function runEveryTick() {

	// make all flyers who should fly, fly
	// defining "should" is done in the function
	flyerFlight();

	

	// call self to run this function every tick
	system.run(runEveryTick);
}

// Start Ticking!
system.run(runEveryTick);

