From 9a2007a3ba23e010c2a0b7142b77d7252b25272a Mon Sep 17 00:00:00 2001 From: zy <854865755@163.com> Date: Thu, 4 Jan 2024 19:41:42 +0800 Subject: [PATCH] update code style --- .../github/client/gui/GuiMagnet.java | 24 +++---- .../github/client/gui/base/FCBaseMEGui.java | 68 ++++++++++--------- .../gui/container/base/FCBaseContainer.java | 20 +++--- .../container/base/FCContainerMonitor.java | 1 - 4 files changed, 59 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/glodblock/github/client/gui/GuiMagnet.java b/src/main/java/com/glodblock/github/client/gui/GuiMagnet.java index 05b02d103..8897770e3 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiMagnet.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiMagnet.java @@ -45,12 +45,12 @@ private class Component { private GuiFCImgButton disable; private String action; - private boolean var; + private boolean value; - public Component(int x, int y, boolean var, String action) { + public Component(int x, int y, boolean value, String action) { this.enable = new GuiFCImgButton(x, y, "ENABLE_12x", "ENABLE", false); this.disable = new GuiFCImgButton(x, y, "DISABLE_12x", "DISABLE", false); - this.var = var; + this.value = value; this.action = action; buttonList.add(this.enable); buttonList.add(this.disable); @@ -60,20 +60,20 @@ public boolean sameBtn(GuiButton btn) { return btn == this.enable || btn == this.disable; } - public boolean getVar() { - return this.var; + public boolean getValue() { + return this.value; } - public void setVar(boolean var) { - this.var = var; + public void setValue(boolean value) { + this.value = value; } public void send() { - FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidTerminalBtns(this.action, !this.getVar())); + FluidCraft.proxy.netHandler.sendToServer(new CPacketFluidTerminalBtns(this.action, !this.getValue())); } public void draw() { - if (var) { + if (value) { this.enable.visible = true; this.disable.visible = false; } else { @@ -138,9 +138,9 @@ public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { .drawString(getGuiDisplayName(NameConst.i18n(NameConst.GUI_MAGNET_CARD_META)), 61, 34, 0x404040); this.fontRendererObj .drawString(getGuiDisplayName(NameConst.i18n(NameConst.GUI_MAGNET_CARD_ORE)), 61, 46, 0x404040); - this.components[0].setVar(this.cont.nbt); - this.components[1].setVar(this.cont.meta); - this.components[2].setVar(this.cont.ore); + this.components[0].setValue(this.cont.nbt); + this.components[1].setValue(this.cont.meta); + this.components[2].setValue(this.cont.ore); for (Component c : components) { c.draw(); } diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java index dbdb63ffb..f54997dba 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCBaseMEGui.java @@ -63,17 +63,17 @@ public abstract class FCBaseMEGui extends AEBaseMEGui { protected boolean drawSwitchGuiBtn; private boolean hasMagnetCard = false; private StorageChannel channel = null; + private final FCBaseContainer container; + protected final int buttonOffset = 18; public FCBaseMEGui(final InventoryPlayer inventoryPlayer, Container container) { super(container); - if (container instanceof FCBaseContainer) { - Object target = ((FCBaseContainer) container).getTarget(); - if (target instanceof IWirelessTerminal - && ((IWirelessTerminal) target).getItemStack().getItem() instanceof ItemWirelessUltraTerminal) { - this.drawSwitchGuiBtn = true; - this.hasMagnetCard = Util.Wireless.hasMagnetCard(((IWirelessTerminal) target).getItemStack()); - this.channel = ((IWirelessTerminal) target).getChannel(); - } + this.container = (FCBaseContainer) container; + if (this.container.getTarget() instanceof IWirelessTerminal iwt + && iwt.getItemStack().getItem() instanceof ItemWirelessUltraTerminal) { + this.drawSwitchGuiBtn = true; + this.hasMagnetCard = Util.Wireless.hasMagnetCard(iwt.getItemStack()); + this.channel = iwt.getChannel(); } } @@ -112,17 +112,17 @@ public List handleItemTooltip(final ItemStack stack, final int mouseX, f protected ItemMagnetCard.Mode getMagnetMode() { if (this.hasMagnetCard) { - return ((FCBaseContainer) this.inventorySlots).mode; + return this.container.mode; } return null; } protected boolean isRestock() { - return ((FCBaseContainer) this.inventorySlots).restock; + return this.container.restock; } protected boolean isSyncData() { - return ((FCBaseContainer) this.inventorySlots).sync; + return this.container.sync; } @Override @@ -131,16 +131,16 @@ public void onGuiClosed() { } protected void setSyncState() { - if (this.inventorySlots instanceof FCContainerMonitor && !isPortableCell()) { + if (this.container instanceof FCContainerMonitor && !isPortableCell()) { this.buttonList.add( this.dataSyncEnableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 44, "DATA_SYNC", "ENABLE")); this.buttonList.add( this.dataSyncDisableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 44, "DATA_SYNC", "DISABLE")); @@ -167,25 +167,25 @@ protected void drawSwitchGuiBtns() { if (this.getMagnetMode() != null && this.channel == StorageChannel.ITEMS) { this.buttonList.add( this.magnetOff = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 124, "MAGNET_CARD", "OFF")); this.buttonList.add( this.magnetInv = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 124, "MAGNET_CARD", "INV")); this.buttonList.add( this.magnetME = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 124, "MAGNET_CARD", "ME")); this.buttonList.add( this.magnetFilter = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 104, "MAGNET_CARD", "FILTER")); @@ -193,13 +193,13 @@ protected void drawSwitchGuiBtns() { if (this.channel == StorageChannel.ITEMS) { this.buttonList.add( this.restockEnableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 84, "RESTOCK", "ENABLE")); this.buttonList.add( this.restockDisableBtn = new GuiFCImgButton( - this.guiLeft + this.xSize - 18, + this.guiLeft + this.xSize - buttonOffset, this.guiTop + this.ySize - 84, "RESTOCK", "DISABLE")); @@ -207,7 +207,7 @@ protected void drawSwitchGuiBtns() { if (!(this instanceof GuiFluidCraftingWireless)) { this.buttonList.add( this.CraftingTerminal = new GuiFCImgButton( - this.guiLeft - 18, + this.guiLeft - buttonOffset, this.getOffsetY(), "CRAFT_TEM", "YES")); @@ -217,7 +217,7 @@ protected void drawSwitchGuiBtns() { if (!(this instanceof GuiFluidPatternWireless)) { this.buttonList.add( this.PatternTerminal = new GuiFCImgButton( - this.guiLeft - 18, + this.guiLeft - buttonOffset, this.getOffsetY(), "PATTERN_TEM", "YES")); @@ -227,7 +227,7 @@ protected void drawSwitchGuiBtns() { if (!(this instanceof GuiFluidPatternExWireless)) { this.buttonList.add( this.PatternTerminalEx = new GuiFCImgButton( - this.guiLeft - 18, + this.guiLeft - buttonOffset, this.getOffsetY(), "PATTERN_EX_TEM", "YES")); @@ -236,14 +236,18 @@ protected void drawSwitchGuiBtns() { } if (!(this instanceof GuiFluidPortableCell)) { this.buttonList.add( - this.FluidTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "FLUID_TEM", "YES")); + this.FluidTerminal = new GuiFCImgButton( + this.guiLeft - buttonOffset, + this.getOffsetY(), + "FLUID_TEM", + "YES")); this.setOffsetY(this.getOffsetY() + 20); termBtns.add(this.FluidTerminal); } if (!(this instanceof GuiInterfaceWireless)) { this.buttonList.add( this.InterfaceTerminal = new GuiFCImgButton( - this.guiLeft - 18, + this.guiLeft - buttonOffset, this.getOffsetY(), "INTERFACE_TEM", "YES")); @@ -252,14 +256,18 @@ protected void drawSwitchGuiBtns() { } if (!(this instanceof GuiLevelWireless)) { this.buttonList.add( - this.LevelTerminal = new GuiFCImgButton(this.guiLeft - 18, this.getOffsetY(), "LEVEL_TEM", "YES")); + this.LevelTerminal = new GuiFCImgButton( + this.guiLeft - buttonOffset, + this.getOffsetY(), + "LEVEL_TEM", + "YES")); this.setOffsetY(this.getOffsetY() + 20); termBtns.add(this.LevelTerminal); } if (ModAndClassUtil.ThE && !(this instanceof GuiEssentiaTerminal)) { this.buttonList.add( this.EssentiaTerminal = new GuiFCImgButton( - this.guiLeft - 18, + this.guiLeft - buttonOffset, this.getOffsetY(), "ESSENTIA_TEM", "YES")); @@ -283,10 +291,8 @@ public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { magnetButtons[i].visible = getMagnetMode().ordinal() == i; } } - if (this.inventorySlots instanceof FCBaseContainer) { - this.dataSyncDisableBtn.visible = !isSyncData(); - this.dataSyncEnableBtn.visible = isSyncData(); - } + this.dataSyncDisableBtn.visible = !isSyncData(); + this.dataSyncEnableBtn.visible = isSyncData(); if (this.drawSwitchGuiBtn && this.channel == StorageChannel.ITEMS) { // Only ultra terminal this.restockDisableBtn.visible = !this.isRestock(); this.restockEnableBtn.visible = this.isRestock(); diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java index 9be67fea8..d468272d5 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java +++ b/src/main/java/com/glodblock/github/client/gui/container/base/FCBaseContainer.java @@ -17,7 +17,7 @@ public abstract class FCBaseContainer extends AEBaseContainer { private int ticks; private final double powerMultiplier = 0.5; - private ITerminalHost host; + protected ITerminalHost host; private int slot = -1; private final InventoryPlayer ip; @GuiSync(105) @@ -40,8 +40,8 @@ public FCBaseContainer(InventoryPlayer ip, ITerminalHost monitorable) { private int lockSlot() { if (isWirelessTerminal()) { - if (this.host instanceof IFluidPortableCell) { - final int slotIndex = ((IFluidPortableCell) this.host).getInventorySlot(); + if (this.host instanceof IFluidPortableCell ifpc) { + final int slotIndex = ifpc.getInventorySlot(); if (Util.GuiHelper.decodeInvType(slotIndex).getLeft() == Util.GuiHelper.InvType.PLAYER_INV) { this.lockPlayerInventorySlot(slotIndex); } @@ -66,12 +66,12 @@ public void detectAndSendChanges() { ((IFluidPortableCell) this.host)); } if (Platform.isServer()) { - if (this.host instanceof IWirelessExtendCard) { - this.mode = ((IWirelessExtendCard) this.host).getMagnetCardMode(); - this.restock = ((IWirelessExtendCard) this.host).isRestock(); + if (this.host instanceof IWirelessExtendCard iwec) { + this.mode = iwec.getMagnetCardMode(); + this.restock = iwec.isRestock(); } - if (this.host != null && this.host instanceof IItemTerminal) { - this.sync = ((IItemTerminal) this.host).getSyncData(); + if (this.host != null && this.host instanceof IItemTerminal iwt) { + this.sync = iwt.getSyncData(); } } super.detectAndSendChanges(); @@ -86,8 +86,8 @@ public ITerminalHost getHost() { } public IFluidPortableCell getPortableCell() { - if (this.host instanceof IFluidPortableCell) { - return (IFluidPortableCell) this.host; + if (this.host instanceof IFluidPortableCell ifpc) { + return ifpc; } else { return null; } diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java index 3b2d05e55..ed836f69f 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java +++ b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerMonitor.java @@ -43,7 +43,6 @@ public abstract class FCContainerMonitor> extends FCBaseCo protected final SlotRestrictedInput[] cellView = new SlotRestrictedInput[5]; protected final IConfigManager clientCM; - protected final ITerminalHost host; @GuiSync(99) public boolean canAccessViewCells = false;