package ru.dbotthepony.mc.otm.block

import net.minecraft.core.BlockPos
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.SoundType
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityExplosionDebugger
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger
import ru.dbotthepony.mc.otm.registry.MBlockEntities

class BlockExplosionDebugger : Block(Properties.of().sound(SoundType.STONE)), EntityBlock {
	override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
		return BlockEntityExplosionDebugger(p_153215_, p_153216_)
	}

	override fun <T : BlockEntity?> getTicker(
		p_153212_: Level,
		p_153213_: BlockState,
		p_153214_: BlockEntityType<T>
	): BlockEntityTicker<T>? {
		if (!p_153212_.isClientSide && p_153214_ === MBlockEntities.DEBUG_EXPLOSION_SMALL) {
			return BlockEntityTicker {_, _, _, t -> if (t is BlockEntityExplosionDebugger) t.tick()}
		}

		return null
	}
}

class BlockSphereDebugger : Block(Properties.of()), EntityBlock {
	override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
		return BlockEntitySphereDebugger(p_153215_, p_153216_)
	}

	override fun <T : BlockEntity?> getTicker(
		p_153212_: Level,
		p_153213_: BlockState,
		p_153214_: BlockEntityType<T>
	): BlockEntityTicker<T>? {
		if (!p_153212_.isClientSide && p_153214_ === MBlockEntities.DEBUG_SPHERE_POINTS) {
			return BlockEntityTicker {_, _, _, t -> if (t is BlockEntitySphereDebugger) t.tick()}
		}

		return null
	}
}
