package ru.dbotthepony.mc.otm.client.render.blockentity

import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.world.phys.AABB
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleGeneratorBlockEntity
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
import ru.dbotthepony.mc.otm.client.render.render

class BlackHoleGeneratorRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<BlackHoleGeneratorBlockEntity> {
	override fun render(
		tile: BlackHoleGeneratorBlockEntity,
		partialtick: Float,
		poseStack: PoseStack,
		buffers: MultiBufferSource,
		packedLight: Int,
		packedOverlay: Int
	) {
		if (tile.drawBuildingGuide) {
			tile.multiblock?.render(poseStack, DynamicBufferSource.WORLD, tile.blockPos)
		}
	}

	override fun getRenderBoundingBox(blockEntity: BlackHoleGeneratorBlockEntity): AABB {
		if (blockEntity.drawBuildingGuide) {
			return blockEntity.multiblock?.boundingBox ?: super.getRenderBoundingBox(blockEntity)
		}

		return super.getRenderBoundingBox(blockEntity)
	}
}
