package com.dairymoose.modernlife.blocks.gui;

import com.dairymoose.modernlife.blocks.RadiatorBlock;
import com.dairymoose.modernlife.core.ModernLifeCommon;
import com.dairymoose.modernlife.core.ModernLifeNetwork;
import com.dairymoose.modernlife.network.play.client.ServerboundRadiatorPacket;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
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/blocks/gui/RadiatorScreen.class */
public class RadiatorScreen extends Screen {
    private static final Logger LOGGER = LogManager.getLogger();
    private static final ResourceLocation RADIATOR_GUI = new ResourceLocation("modernlife", "textures/gui/gui_radiator_all.png");
    final int GUI_WIDTH = 126;
    final int GUI_HEIGHT = 42;
    private Level world;
    private BlockPos pos;

    public RadiatorScreen(Level world, BlockPos radiatorBlock) {
        super(new TextComponent("Radiator").m_6270_(Style.EMPTY.withColor(TextColor.fromRgb(4210752))));
        this.GUI_WIDTH = 126;
        this.GUI_HEIGHT = 42;
        this.world = null;
        this.pos = null;
        this.world = world;
        this.pos = radiatorBlock;
    }

    protected void init() {
        ModernLifeCommon.LOGGER.debug("in init!");
        int startX = ((this.width - 126) / 2) + 5;
        int startY = ((this.height - 42) / 2) + 11;
        addRenderableWidget(new ImageButton(startX, startY, 24, 24, 5, 11, 42, RADIATOR_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.RadiatorScreen.1
            C01011() {
            }

            public void onPress(Button arg0) {
                BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
                if (bs.getBlock().getClass() == RadiatorBlock.class) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.off, RadiatorScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
                ModernLifeCommon.LOGGER.debug("pressed button: off");
            }
        }));
        addRenderableWidget(new ImageButton(startX + 30, startY, 24, 24, 35, 11, 42, RADIATOR_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.RadiatorScreen.2
            C01022() {
            }

            public void onPress(Button arg0) {
                BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
                if (bs.getBlock().getClass() == RadiatorBlock.class) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.low, RadiatorScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
                ModernLifeCommon.LOGGER.debug("pressed button: low");
            }
        }));
        addRenderableWidget(new ImageButton(startX + 60, startY, 24, 24, 65, 11, 42, RADIATOR_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.RadiatorScreen.3
            C01033() {
            }

            public void onPress(Button arg0) {
                BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
                if (bs.getBlock().getClass() == RadiatorBlock.class) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.medium, RadiatorScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
                ModernLifeCommon.LOGGER.debug("pressed button: med");
            }
        }));
        addRenderableWidget(new ImageButton(startX + 90, startY, 24, 24, 95, 11, 42, RADIATOR_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.RadiatorScreen.4
            C01044() {
            }

            public void onPress(Button arg0) {
                BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
                if (bs.getBlock().getClass() == RadiatorBlock.class) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.high, RadiatorScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
                ModernLifeCommon.LOGGER.debug("pressed button: high");
            }
        }));
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.RadiatorScreen$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/RadiatorScreen$1.class */
    class C01011 implements Button.OnPress {
        C01011() {
        }

        public void onPress(Button arg0) {
            BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
            if (bs.getBlock().getClass() == RadiatorBlock.class) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.off, RadiatorScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
            ModernLifeCommon.LOGGER.debug("pressed button: off");
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.RadiatorScreen$2 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/RadiatorScreen$2.class */
    class C01022 implements Button.OnPress {
        C01022() {
        }

        public void onPress(Button arg0) {
            BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
            if (bs.getBlock().getClass() == RadiatorBlock.class) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.low, RadiatorScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
            ModernLifeCommon.LOGGER.debug("pressed button: low");
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.RadiatorScreen$3 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/RadiatorScreen$3.class */
    class C01033 implements Button.OnPress {
        C01033() {
        }

        public void onPress(Button arg0) {
            BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
            if (bs.getBlock().getClass() == RadiatorBlock.class) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.medium, RadiatorScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
            ModernLifeCommon.LOGGER.debug("pressed button: med");
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.RadiatorScreen$4 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/RadiatorScreen$4.class */
    class C01044 implements Button.OnPress {
        C01044() {
        }

        public void onPress(Button arg0) {
            BlockState bs = RadiatorScreen.this.world.getBlockState(RadiatorScreen.this.pos);
            if (bs.getBlock().getClass() == RadiatorBlock.class) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundRadiatorPacket(RadiatorBlock.HeatType.high, RadiatorScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
            ModernLifeCommon.LOGGER.debug("pressed button: high");
        }
    }

    public boolean isPauseScreen() {
        return false;
    }

    private void drawCenteredStringNoShadow(PoseStack p_238472_0_, Font p_238472_1_, Component p_238472_2_, int p_238472_3_, int p_238472_4_, int p_238472_5_) {
        FormattedCharSequence lvt_6_1_ = p_238472_2_.getVisualOrderText();
        p_238472_1_.draw(p_238472_0_, lvt_6_1_, p_238472_3_ - (p_238472_1_.width(lvt_6_1_) / 2), p_238472_4_, p_238472_5_);
    }

    public void render(PoseStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
        renderBackground(p_230430_1_);
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.setShaderTexture(0, RADIATOR_GUI);
        int lvt_5_1_ = (this.width - 126) / 2;
        int lvt_6_1_ = (this.height - 42) / 2;
        m_93228_(p_230430_1_, lvt_5_1_, lvt_6_1_, 0, 0, 126, 42);
        drawCenteredStringNoShadow(p_230430_1_, this.minecraft.font, this.title, lvt_5_1_ + 63, lvt_6_1_ + 2, 0);
        super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
    }
}
