ModernLifePatch/src-source/main/java/com/dairymoose/modernlife/blocks/gui/WirelessPowerScreen.java
2024-10-26 09:40:21 +08:00

230 lines
9.5 KiB
Java

package com.dairymoose.modernlife.blocks.gui;
import com.dairymoose.modernlife.core.ModernLifeCommon;
import com.dairymoose.modernlife.core.ModernLifeNetwork;
import com.dairymoose.modernlife.network.play.client.ServerboundWirelessChannelPacket;
import com.dairymoose.modernlife.tileentities.IChannelHolder;
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.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/WirelessPowerScreen.class */
public class WirelessPowerScreen extends Screen {
private static final Logger LOGGER = LogManager.getLogger();
private static final ResourceLocation WIRELESS_POWER_UI = new ResourceLocation("modernlife", "textures/gui/wireless_power_ui.png");
final int GUI_WIDTH = 80;
final int GUI_HEIGHT = 68;
private BlockPos wirelessBlock;
private int currentChannel;
private ImageButton accept;
public WirelessPowerScreen(BlockPos wirelessBlock, int currentChannel) {
super(new TextComponent("Wireless Power").m_6270_(Style.EMPTY.withColor(TextColor.fromRgb(4210752))));
this.GUI_WIDTH = 80;
this.GUI_HEIGHT = 68;
this.wirelessBlock = wirelessBlock;
this.currentChannel = currentChannel;
}
protected void init() {
ModernLifeCommon.LOGGER.debug("in init!");
int startX = (this.width - 80) / 2;
int startY = (this.height - 68) / 2;
addRenderableWidget(new ImageButton(startX + 42, startY + 34, 14, 13, 81, 0, 14, WIRELESS_POWER_UI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen.1
final /* synthetic */ WirelessPowerScreen val$wps;
C01051(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
this.currentChannel--;
this.sanitizeCurrentChannel();
}
}));
addRenderableWidget(new ImageButton(startX + 42, startY + 20, 14, 13, 96, 0, 14, WIRELESS_POWER_UI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen.2
final /* synthetic */ WirelessPowerScreen val$wps;
C01062(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
this.currentChannel++;
this.sanitizeCurrentChannel();
}
}));
addRenderableWidget(new ImageButton(startX + 20, startY + 50, 14, 13, 111, 0, 14, WIRELESS_POWER_UI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen.3
C01073() {
}
public void onPress(Button arg0) {
Minecraft.getInstance().setScreen((Screen) null);
}
}));
this.accept = addRenderableWidget(new ImageButton(startX + 47, startY + 50, 14, 13, 126, 0, 14, WIRELESS_POWER_UI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen.4
final /* synthetic */ WirelessPowerScreen val$wps;
C01084(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
IChannelHolder blockEntity = Minecraft.getInstance().level.getBlockEntity(this.wirelessBlock);
if (blockEntity instanceof IChannelHolder) {
IChannelHolder channelHolder = blockEntity;
channelHolder.setCurrentChannel(this.currentChannel);
}
ServerboundWirelessChannelPacket packet = new ServerboundWirelessChannelPacket(this.currentChannel, this.wirelessBlock);
ModernLifeNetwork.INSTANCE.sendToServer(packet);
Minecraft.getInstance().setScreen((Screen) null);
}
}));
}
/* renamed from: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen$1 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/WirelessPowerScreen$1.class */
class C01051 implements Button.OnPress {
final /* synthetic */ WirelessPowerScreen val$wps;
C01051(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
this.currentChannel--;
this.sanitizeCurrentChannel();
}
}
/* renamed from: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen$2 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/WirelessPowerScreen$2.class */
class C01062 implements Button.OnPress {
final /* synthetic */ WirelessPowerScreen val$wps;
C01062(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
this.currentChannel++;
this.sanitizeCurrentChannel();
}
}
/* renamed from: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen$3 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/WirelessPowerScreen$3.class */
class C01073 implements Button.OnPress {
C01073() {
}
public void onPress(Button arg0) {
Minecraft.getInstance().setScreen((Screen) null);
}
}
/* renamed from: com.dairymoose.modernlife.blocks.gui.WirelessPowerScreen$4 */
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/WirelessPowerScreen$4.class */
class C01084 implements Button.OnPress {
final /* synthetic */ WirelessPowerScreen val$wps;
C01084(WirelessPowerScreen this) {
this = this;
}
public void onPress(Button arg0) {
IChannelHolder blockEntity = Minecraft.getInstance().level.getBlockEntity(this.wirelessBlock);
if (blockEntity instanceof IChannelHolder) {
IChannelHolder channelHolder = blockEntity;
channelHolder.setCurrentChannel(this.currentChannel);
}
ServerboundWirelessChannelPacket packet = new ServerboundWirelessChannelPacket(this.currentChannel, this.wirelessBlock);
ModernLifeNetwork.INSTANCE.sendToServer(packet);
Minecraft.getInstance().setScreen((Screen) null);
}
}
public boolean isPauseScreen() {
return false;
}
public void sanitizeCurrentChannel() {
if (this.currentChannel < 0) {
this.currentChannel = 0;
}
if (this.currentChannel > 9999) {
this.currentChannel = 9999;
}
}
public boolean m_6050_(double a, double b, double c) {
if (c > 0.0d) {
this.currentChannel++;
sanitizeCurrentChannel();
} else {
this.currentChannel--;
sanitizeCurrentChannel();
}
return super.m_6050_(a, b, c);
}
public boolean keyPressed(int key, int p_231046_2_, int p_231046_3_) {
ModernLifeCommon.LOGGER.debug("key press: " + key);
if (key == 264) {
this.currentChannel--;
} else if (key == 265) {
this.currentChannel++;
} else if (key == 267) {
this.currentChannel -= 10;
} else if (key == 266) {
this.currentChannel += 10;
} else if (key == 261) {
this.currentChannel = 0;
} else if (key == 259) {
this.currentChannel /= 10;
} else if (key == 48 || (key >= 49 && key <= 57)) {
this.currentChannel *= 10;
int digit = Character.digit(key, 10);
this.currentChannel += digit;
} else if (key == 257) {
this.accept.onPress();
return true;
}
sanitizeCurrentChannel();
return super.keyPressed(key, p_231046_2_, p_231046_3_);
}
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.setShaderTexture(0, WIRELESS_POWER_UI);
int lvt_5_1_ = (this.width - 80) / 2;
int lvt_6_1_ = (this.height - 68) / 2;
m_93228_(p_230430_1_, lvt_5_1_, lvt_6_1_, 0, 0, 80, 68);
drawCenteredStringNoShadow(p_230430_1_, this.minecraft.font, new TextComponent(String.valueOf(this.currentChannel)).m_6270_(Style.EMPTY.withColor(TextColor.fromRgb(0))), lvt_5_1_ + 22, lvt_6_1_ + 28, 0);
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
}
}