#include "LongJump.h"
#include "Client.h"

#include "Utils/MoveUtils.h"

auto LongJump::onWorldTick(Player* _this) -> void {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto minecraft = clientinstance->getMinecraft();
	if (!minecraft) return;

	auto actorrotationcomponent = _this->getActorRotationComponent();
	if (!actorrotationcomponent) return;

	if (Client::screenName != _("hud_screen")) return;

	static float angle;
	float yaw = Utils::Move::getMoveYaw() + actorrotationcomponent->mRotationDegree.y;

	glm::vec3 velocity = Utils::Move::getVelocity(_this);
	glm::vec3 position = Utils::Move::getPosition(_this);



	minecraft->getTimer()->mTicksPerSecond = 20.f * timermultiplier;
	switch (mode) {
	case 0: {
		if (doJump) {
			if (!Utils::Move::isOnGround(_this)) {
				return;
			}
			velocity.y = height;
			angle = (actorrotationcomponent->mRotationDegree.y + 90) * (3.1415927f / 180);

			doJump = false;
		}
		else {
			if (Utils::Move::isOnGround(_this)) {
				enabled = false;
				onDisabled();

				for (Mod* mod : Client::modlist) {
					if (!mod->enabled && mod->onlyenabled) continue;

					mod->onAnyDisabled();
				}
			}
		}


		if (Utils::Move::isForwarding()) {
			velocity.x = cos(angle);
			velocity.z = sin(angle);
		}

		Utils::Move::setVelocity(_this, velocity);
		break;
	}
	}
}

auto LongJump::onEnabled() -> void {
	doJump = true;
}

auto LongJump::onDisabled() -> void {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto minecraft = clientinstance->getMinecraft();
	if (!minecraft) return;

	minecraft->getTimer()->mTicksPerSecond = 20.f;
}
