package ru.dbotthepony.mc.otm.block.tech

import net.minecraft.core.BlockPos
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.EntityBlock
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.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.addSimpleDescription
import ru.dbotthepony.mc.otm.block.entity.tech.FlywheelBatteryBlockEntity

class FlywheelBatteryBlock : RotatableMatteryBlock(), EntityBlock {
	init {
		addSimpleDescription()

		for (i in 2 .. 7)
			addSimpleDescription(i.toString())
	}

	override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity {
		return FlywheelBatteryBlockEntity(pos, state)
	}

	override fun <T : BlockEntity?> getTicker(
		level: Level,
		p_153213_: BlockState,
		p_153214_: BlockEntityType<T>
	): BlockEntityTicker<T>? {
		if (level.isClientSide)
			return null

		return BlockEntityTicker { _, _, _, t -> if (t is FlywheelBatteryBlockEntity) t.tick() }
	}
}
