package net.touhoudiscord.hexucasting.common.casting.actions.spells

import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.phys.Vec3
import net.touhoudiscord.hexucasting.api.config.HexucastingConfig
import net.touhoudiscord.hexucasting.common.casting.actions.OpExampleConstMediaAction.argc

object OpStarlightAction : SpellAction {
	/**
	 * The number of arguments from the stack that this action requires.
	 */
	override val argc = 0

	/**
	 * The method called when this Action is actually executed. Accepts the [args]
	 * that were on the stack (there will be [argc] of them), and the [ctx],
	 * which contains things like references to the caster, the ServerLevel,
	 * methods to determine whether locations and entities are in ambit, etc.
	 * Returns a triple of things. The [RenderedSpell] is responsible for the spell actually
	 * doing things in the world, the [Int] is how much media the spell should cost,
	 * and the [List] of [ParticleSpray] renders particle effects for the result of the SpellAction.
	 *
	 * The [execute] method should only contain code to find the targets of the spell and validate
	 * them. All the code that actually makes changes to the world (breaking blocks, teleporting things,
	 * etc.) should be in the private [Spell] data class below.
	 */
	override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
		return Triple(
			Spell(),
			MediaConstants.CRYSTAL_UNIT,
			listOf()
		)
	}

	/**
	 * This class is responsible for actually making changes to the world. It accepts parameters to
	 * define where/what it should affect (for this example the parameter is [vec]), and the
	 * [cast] method within is responsible for using that data to alter the world.
	 */
	private data class Spell(val thisisgivingmeanerrorifidontputsomethinghere: Int = 0) : RenderedSpell {
		override fun cast(ctx: CastingContext) {
			val w = ctx.world
			val relativeTime = w.dayTime%24000
			if (relativeTime > 12542) {
				w.dayTime += 24000
			}
			w.dayTime = w.dayTime-relativeTime+12542
		}
	}
}