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

import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.math.Axis
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.world.item.ItemDisplayContext
import ru.dbotthepony.mc.otm.block.entity.matter.MatterReconstructorBlockEntity
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource

class MatterReconstructorRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<MatterReconstructorBlockEntity> {
	override fun render(
		tile: MatterReconstructorBlockEntity,
		partialTick: Float,
		pose: PoseStack,
		bufferSource: MultiBufferSource,
		packedLight: Int,
		packedOverlay: Int
	) {
		val item = tile.visualItemStack

		if (item.isEmpty) {
			return
		}

		pose.pushPose()

		pose.translate(0.5, 0.6, 0.5)
		pose.scale(0.5f, 0.5f, 0.5f)

		pose.mulPose(Axis.XP.rotationDegrees(90f))
		pose.mulPose(Axis.ZP.rotationDegrees(tile.blockRotation.back.toYRot()))

		context.itemRenderer.renderStatic(item, ItemDisplayContext.FIXED, packedLight, packedOverlay, pose, DynamicBufferSource.WORLD, tile.level, tile.blockPos.asLong().toInt())

		pose.popPose()
	}
}
