package ru.dbotthepony.mc.otm.core.multiblock

import net.minecraft.world.level.block.entity.BlockEntity
import java.util.function.Predicate
import kotlin.reflect.KClass

inline fun <reified T : BlockEntity> multiblockEntity(): BlockEntityTag<T> {
	return BlockEntityTag(T::class)
}

/**
 * Tags specific [T] block (or any subclassed one) entities to be exposed through [ShapedMultiblock.blockEntities] when specific [Part]s are tagged using [Part.tag]
 *
 * Optionally, can have [predicate] specified, which narrows which block entities can be accepted by this tag
 */
class BlockEntityTag<T : Any>(val clazz: KClass<T>, val predicate: Predicate<in T> = Predicate { true }) : Predicate<Any?> {
	override fun test(t: Any?): Boolean {
		return clazz.isInstance(t) && predicate.test(t as T)
	}
}
