package ru.dbotthepony.mc.otm.block.entity.blackhole

import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.Vec3
import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.math.times
import ru.dbotthepony.mc.otm.registry.MBlockEntities

class BlockEntityExplosionDebugger(p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(MBlockEntities.DEBUG_EXPLOSION_SMALL, p_155229_, p_155230_) {
	private var hive: ExplosionRayHive? = null

	fun tick() {
		if (hive == null) {
			val hive = ExplosionRayHive(level as ServerLevel)
			this.hive = hive
			
			val tx = blockPos.x.toDouble() + 0.5
			val ty = blockPos.y.toDouble() + 0.5
			val tz = blockPos.z.toDouble() + 0.5
			val tpos = Vec3(tx, ty, tz)

			for (normal in ExplosionRayHive.evenlyDistributedPoints(1000)) {
				hive.addRay(normal + tpos, normal, 200.0)
			}
		}

		hive!!.step()
	}
}

class BlockEntitySphereDebugger(p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(MBlockEntities.DEBUG_SPHERE_POINTS, p_155229_, p_155230_) {
	private var placed = false

	fun tick() {
		if (!placed) {
			placed = true

			for (normal in ExplosionRayHive.evenlyDistributedPoints(400)) {
				val multiplied = normal * 20.0
				level!!.setBlock(blockPos + BlockPos(multiplied.x.toInt(), multiplied.y.toInt(), multiplied.z.toInt()), Blocks.COAL_BLOCK.defaultBlockState(), Block.UPDATE_ALL)
			}
		}
	}
}
