package net.geforcemods.securitycraft.renderers;

import com.mojang.blaze3d.matrix.MatrixStack;

import net.geforcemods.securitycraft.SCContent;
import net.geforcemods.securitycraft.blocks.SecurityCameraBlock;
import net.geforcemods.securitycraft.models.SecurityCameraModel;
import net.geforcemods.securitycraft.tileentity.SecurityCameraTileEntity;
import net.geforcemods.securitycraft.util.BlockUtils;
import net.geforcemods.securitycraft.util.PlayerUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.Quaternion;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class SecurityCameraTileEntityRenderer extends TileEntityRenderer<SecurityCameraTileEntity> {

	private static final Quaternion POSITIVE_Y_180 = Vector3f.YP.rotationDegrees(180.0F);
	private static final Quaternion POSITIVE_Y_90 = Vector3f.YP.rotationDegrees(90.0F);
	private static final Quaternion POSITIVE_Y_NEGATIVE_90 = Vector3f.YP.rotationDegrees(-90.0F);
	private static final Quaternion POSITIVE_X_180 = Vector3f.YP.rotationDegrees(180.0F);

	public SecurityCameraTileEntityRenderer(TileEntityRendererDispatcher terd)
	{
		super(terd);
	}

	private static final SecurityCameraModel modelSecurityCamera = new SecurityCameraModel();
	private static final ResourceLocation cameraTexture = new ResourceLocation("securitycraft:textures/block/security_camera1.png");

	@Override
	public void render(SecurityCameraTileEntity te, float partialTicks, MatrixStack matrix, IRenderTypeBuffer buffer, int p_225616_5_, int p_225616_6_)
	{
		if(te.down || PlayerUtils.isPlayerMountedOnCamera(Minecraft.getInstance().player) && Minecraft.getInstance().player.getRidingEntity().getPosition().equals(te.getPos()))
			return;

		matrix.translate(0.5D, 1.5D, 0.5D);

		if(te.hasWorld() && BlockUtils.getBlock(te.getWorld(), te.getPos()) == SCContent.securityCamera)
		{
			Direction side = te.getWorld().getBlockState(te.getPos()).get(SecurityCameraBlock.FACING);

			if(side == Direction.NORTH)
				matrix.rotate(POSITIVE_Y_180);
			else if(side == Direction.EAST)
				matrix.rotate(POSITIVE_Y_90);
			else if(side == Direction.WEST)
				matrix.rotate(POSITIVE_Y_NEGATIVE_90);
		}

		matrix.rotate(POSITIVE_X_180);
		modelSecurityCamera.cameraRotationPoint.rotateAngleY = te.cameraRotation;
		modelSecurityCamera.render(matrix, buffer.getBuffer(RenderType.entitySolid(cameraTexture)), p_225616_5_, OverlayTexture.DEFAULT_LIGHT, 1.0F, 1.0F, 1.0F, 1.0F);
	}
}

@@ -1404,27 +1404,16 @@
 ternion 
-POSITIVE_Y_
 NEGATIVE
@@ -1413,16 +1413,18 @@
 EGATIVE_
+Y_
 90 = Vec
@@ -1422,33 +1422,33 @@
 _90 = Vector3f.Y
-P
+N
 .rotationDegrees
@@ -1452,9 +1452,8 @@
 ees(
--
 90.0
@@ -1507,33 +1507,33 @@
 _180 = Vector3f.
-Y
+X
 P.rotationDegree
@@ -2635,27 +2635,16 @@
 .rotate(
-POSITIVE_Y_
 NEGATIVE
@@ -2644,16 +2644,18 @@
 EGATIVE_
+Y_
 90);%0A%09%09%7D

fix camera renderer