package com.dairymoose.modernlife.renderer.tileentity;

import com.dairymoose.modernlife.blocks.CanvasBlock;
import com.dairymoose.modernlife.core.CustomBlocks;
import com.dairymoose.modernlife.core.ModernLifeClient;
import com.dairymoose.modernlife.tileentities.CCTVCameraBlockEntity;
import com.dairymoose.modernlife.tileentities.MirrorBlockEntity;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@OnlyIn(Dist.CLIENT)
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/renderer/tileentity/MirrorBlockEntityRenderer.class */
public class MirrorBlockEntityRenderer implements BlockEntityRenderer<MirrorBlockEntity> {
    private boolean ignoreRender = false;
    private boolean insetIntoMirror = true;
    private static final Logger LOGGER = LogManager.getLogger();
    public static RenderTarget mirrorFramebuffer = null;
    public static Map<BlockPos, MirrorBlockEntity> mirrorMap = new HashMap();

    private void renderTexture(float size, PoseStack matrixStack, int lightmap, boolean flipX) {
        renderTextureRect(size, size, matrixStack, lightmap, flipX);
    }

    public MirrorBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {
    }

    private void renderTextureRect(float width, float height, PoseStack matrixStack, int lightmap, boolean flipX) {
        BufferBuilder builder = Tesselator.getInstance().getBuilder();
        builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
        Matrix4f poseMatrix = matrixStack.last().pose();
        float uMin = 0.0f;
        float uMax = 1.0f;
        if (flipX) {
            uMin = 1.0f;
            uMax = 0.0f;
        }
        builder.m_85982_(poseMatrix, 0.0f, height, 0.0f).uv(uMin, 1.0f).uv2(lightmap).endVertex();
        builder.m_85982_(poseMatrix, width, height, 0.0f).uv(uMax, 1.0f).uv2(lightmap).endVertex();
        builder.m_85982_(poseMatrix, width, 0.0f, 0.0f).uv(uMax, 0.0f).uv2(lightmap).endVertex();
        builder.m_85982_(poseMatrix, 0.0f, 0.0f, 0.0f).uv(uMin, 0.0f).uv2(lightmap).endVertex();
        builder.end();
        RenderSystem.enableDepthTest();
        BufferUploader.end(builder);
    }

    public void render(MirrorBlockEntity tileEntity, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int lightmap, int overlayColor) {
        if (this.ignoreRender || mirrorFramebuffer == null) {
            return;
        }
        mirrorMap.put(tileEntity.getBlockPos(), tileEntity);
        if (ModernLifeClient.getChosenMirror() != tileEntity) {
            return;
        }
        matrixStack.pushPose();
        switch (C01551.$SwitchMap$net$minecraft$core$Direction[tileEntity.getBlockState().getValue(CanvasBlock.FACING).ordinal()]) {
            case 1:
                matrixStack.mulPose(Vector3f.YP.rotationDegrees(270.0f));
                break;
            case 2:
                matrixStack.mulPose(Vector3f.YP.rotationDegrees(90.0f));
                matrixStack.translate(-1.0d, 0.0d, 1.0d);
                break;
            case 3:
                matrixStack.mulPose(Vector3f.YP.rotationDegrees(0.0f));
                matrixStack.translate(0.0d, 0.0d, 1.0d);
                break;
            case 4:
                matrixStack.mulPose(Vector3f.YP.rotationDegrees(180.0f));
                matrixStack.translate(-1.0d, 0.0d, 0.0d);
                break;
        }
        matrixStack.translate(0.0d, 0.0d, -0.062300000339746475d);
        if (this.insetIntoMirror) {
            matrixStack.translate(0.05000000074505806d, 0.05000000074505806d, 0.0d);
        }
        Minecraft.getInstance().getWindow().getWidth();
        Minecraft.getInstance().getWindow().getHeight();
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem._setShaderTexture(0, mirrorFramebuffer.getColorTextureId());
        float size = 1.0f;
        if (this.insetIntoMirror) {
            size = 0.9f;
        }
        if (tileEntity.getBlockState().getBlock() == CustomBlocks.BLOCK_TALL_MIRROR.get()) {
            matrixStack.translate(0.0d, 0.05000000074505806d, 0.0d);
            renderTextureRect(0.9f, 1.85f, matrixStack, lightmap, false);
        } else if (tileEntity.getBlockState().getBlock() == CustomBlocks.BLOCK_LARGE_MIRROR.get()) {
            matrixStack.translate(-0.5d, 0.05000000074505806d, 0.0d);
            renderTexture(1.8f, matrixStack, lightmap, false);
        } else if (tileEntity.getBlockState().getBlock() == CustomBlocks.BLOCK_MASSIVE_MIRROR.get()) {
            matrixStack.translate(-0.8999999761581421d, 0.05000000074505806d, 0.0d);
            renderTextureRect(2.7f, 1.85f, matrixStack, lightmap, false);
        } else if (tileEntity.getBlockState().getBlock() == CustomBlocks.BLOCK_CCTV_SCREEN.get()) {
            if (ModernLifeClient.cctvCurrentCamera != null) {
                matrixStack.translate(0.0d, 0.0d, -0.0010000000474974513d);
                renderTexture(size, matrixStack, lightmap, true);
                if (CCTVCameraBlockEntity.cctvCameras.size() > 0) {
                    matrixStack.pushPose();
                    matrixStack.translate(0.8700000047683716d, 0.10000000149011612d, -0.009999999776482582d);
                    matrixStack.scale(-0.01f, -0.01f, -0.01f);
                    int camValue = tileEntity.cctvScreenCurrentCameraDisplayValue + 1;
                    String camText = "CAM" + String.valueOf(camValue);
                    Minecraft.getInstance().font.drawShadow(matrixStack, camText, 0.0f, 0.0f, 16777215);
                    matrixStack.popPose();
                }
            }
        } else {
            renderTexture(size, matrixStack, lightmap, false);
        }
        matrixStack.popPose();
    }

    /* renamed from: com.dairymoose.modernlife.renderer.tileentity.MirrorBlockEntityRenderer$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/renderer/tileentity/MirrorBlockEntityRenderer$1.class */
    public static /* synthetic */ class C01551 {
        static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];

        static {
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
        }
    }
}
