Code cleanup (#133)

* gradle updateBuildScript

* fix comments and commented-out code

Code deletion, converting comments into javadocs, and refactoring code to not
need comments.

* remove redundant suppressions

* replace C-style array declaration with Java-style

* make private field final

* remove unnecessary semicolon

* extract a common part from an if

* simplify boolean expression

* simplify ternary if

* remove unused imports

* convert escaped characters for clarity

* replace while with for

* replace explicit types with diamond operators

* replace anonymous type with lambda

* enable modern Java syntax

* migrate to enhanced switch

* migrate to pattern variables for instanceof

* remove empty javadoc

* add Nonnull annotation to overrides of Nonnull methods

* replace wailaStack with null

When wailaStack is not null, the flow breaks out of the loop,
so there's no need to confuse the reader with putting wailaStack
both as the result and the parameter of the call - there's no
recursion.

* int cannot be bigger than its max value

* suppress dataflow warning

* remove redundant initializer

The default value of int is 0.

* null check is covered by instanceof

* simplify some calls of addVertexWithUV

* fix typos and add TODOs

* make flipState more understandable
This commit is contained in:
chill authored and GitHub committed 2023-06-18 23:29:57 +02:00
1 parent f87b76347e
commit d5b8ef6ea9
89 files changed
+421 -633

No files matched your search

@@ -128,15 +128,12 @@ public class GuiDualInterface extends GuiUpgradeable {
@Override
protected String getBackground() {
if (!ModAndClassUtil.isBigInterface) return "guis/interface.png";
switch (((ContainerInterface) this.cvb).getPatternCapacityCardsInstalled()) {
case 1:
return "guis/interface2.png";
case 2:
return "guis/interface3.png";
case 3:
return "guis/interface4.png";
}
return "guis/interface.png";
return switch (((ContainerInterface) this.cvb).getPatternCapacityCardsInstalled()) {
case 1 -> "guis/interface2.png";
case 2 -> "guis/interface3.png";
case 3 -> "guis/interface4.png";
default -> "guis/interface.png";
};
}
@Override
@@ -244,9 +244,7 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
Math.round(uv_y * 16F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
} else {
GL11.glPushMatrix();
GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F);
@@ -280,9 +278,9 @@ public class GuiFCImgButton extends GuiButton implements ITooltip {
Math.round(uv_y * 16F * 16F / 3F),
Math.round(16F * 16F / 3F),
Math.round(16F * 16F / 3F));
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
}
this.mouseDragged(par1Minecraft, par2, par3);
GL11.glPopMatrix();
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
@@ -1,7 +1,5 @@
package com.glodblock.github.client.gui;
import java.util.*;
import net.minecraft.entity.player.InventoryPlayer;
import com.glodblock.github.FluidCraft;
@@ -164,7 +164,6 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable {
FluidCraft.proxy.netHandler.sendToServer(new CPacketValueConfig(result, 0));
} catch (final NumberFormatException e) {
// nope..
this.level.setText("0");
}
}
@@ -76,7 +76,6 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
protected static boolean onlyBrokenRecipes = false;
protected GuiTabButton craftingStatusBtn;
// private final IConfigManager configSrc;
private int rows = 3;
private static final String MOLECULAR_ASSEMBLER = "tile.appliedenergistics2.BlockMolecularAssembler";
@@ -210,8 +209,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
protected void repositionSlots() {
for (final Object obj : this.inventorySlots.inventorySlots) {
if (obj instanceof AppEngSlot) {
final AppEngSlot slot = (AppEngSlot) obj;
if (obj instanceof final AppEngSlot slot) {
slot.yDisplayPosition = this.ySize + slot.getY() - 78 - 7;
}
}
@@ -220,7 +218,9 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
protected int calculateRowsCount() {
final int maxRows = this.getMaxRows();
final boolean hasNEI = IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI);
final int NEIPadding = hasNEI ? 22 /* input */ + 18 /* top panel */ : 0;
final int input = 22;
final int topPanel = 18;
final int NEIPadding = hasNEI ? input + topPanel : 0;
final int extraSpace = this.height - MAGIC_HEIGHT_NUMBER - NEIPadding;
return Math.max(3, Math.min(maxRows, extraSpace / 18));
@@ -243,8 +243,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
final int ex = getScrollBar().getCurrentScroll();
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
if (lineObj instanceof final ClientDCInternalInv inv) {
for (int z = 0; z < inv.getInventory().getSizeInventory(); z++) {
if (this.matchedStacks.contains(inv.getInventory().getStackInSlot(z))) drawRect(
z * 18 + 22,
@@ -253,8 +252,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
1 + offset + 16,
GuiColors.InterfaceTerminalMatch.getColor());
}
} else if (lineObj instanceof String) {
String name = (String) lineObj;
} else if (lineObj instanceof String name) {
final int rows = this.byName.get(name).size();
String postfix = "";
@@ -309,8 +307,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
final int ex = this.getScrollBar().getCurrentScroll();
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
if (lineObj instanceof final ClientDCInternalInv inv) {
for (int z = 0; z < inv.getInventory().getSizeInventory(); z++) {
inventorySlots.inventorySlots.add(new SlotDisconnected(inv, z, z * 18 + 22, 1 + offset));
}
@@ -405,8 +402,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
} else if (btn == craftingStatusBtn) {
InventoryHandler.switchGui(GuiType.CRAFTING_STATUS);
} else if (btn instanceof GuiImgButton) {
final GuiImgButton iBtn = (GuiImgButton) btn;
} else if (btn instanceof final GuiImgButton iBtn) {
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum cv = iBtn.getCurrentValue();
final boolean backwards = Mouse.isButtonDown(1);
@@ -444,8 +440,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
for (int x = 0; x < this.rows && ex + x < this.lines.size(); x++) {
final Object lineObj = this.lines.get(ex + x);
if (lineObj instanceof ClientDCInternalInv) {
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
if (lineObj instanceof final ClientDCInternalInv inv) {
GL11.glColor4f(1, 1, 1, 1);
final int width = inv.getInventory().getSizeInventory() * 18;
@@ -539,7 +534,7 @@ public class GuiInterfaceTerminalWireless extends FCBaseMEGui implements IDropTo
if (this.refreshList) {
this.refreshList = false;
// invalid caches on refresh
// invalidate caches on refresh
this.cachedSearches.clear();
this.refreshList();
}
@@ -364,32 +364,33 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
public void draw() {
this.getQty().draw();
this.getBatch().draw();
ArrayList<String> message = new ArrayList<String>();
ArrayList<String> message = new ArrayList<>();
message.add(NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_TITLE) + "\n");
switch (this.state) {
case Idling:
case Idling -> {
this.line.setColor(0xFF55FF55);
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT)
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_IDLE));
break;
case Crafting:
}
case Crafting -> {
this.line.setColor(0xFFFFFF55);
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT)
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_LINK));
break;
case Exporting:
}
case Exporting -> {
this.line.setColor(0xFFAA00AA);
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT)
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_EXPORT));
break;
default:
}
default -> {
this.line.setColor(0);
message.add(
NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_CURRENT)
+ NameConst.i18n(NameConst.TT_LEVEL_MAINTAINER_NONE));
}
}
message.add("");
if (isShiftKeyDown()) {
@@ -430,7 +431,7 @@ public class GuiLevelMaintainer extends AEBaseGui implements INEIGuiHandler {
this.textField = textField;
this.textField.setEnableBackgroundDrawing(false);
this.textField.setText("0");
this.textField.setMaxStringLength(10); // it's enough to useful
this.textField.setMaxStringLength(10); // this length is enough to useful
this.idx = idx;
this.action = action;
this.tooltip = tooltip;
@@ -16,7 +16,7 @@ import appeng.core.localization.GuiText;
public class GuiRenamer extends AEBaseGui implements IDropToFillTextField {
private MEGuiTextField textField;
private final MEGuiTextField textField;
public GuiRenamer(InventoryPlayer ip, ITerminalHost monitorable) {
super(new ContainerRenamer(ip, monitorable));
@@ -122,9 +122,8 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
if (btn == this.craftingStatusBtn || btn == this.craftingStatusImgBtn) {
InventoryHandler.switchGui(GuiType.CRAFTING_STATUS);
}
if (btn instanceof GuiImgButton) {
if (btn instanceof final GuiImgButton iBtn) {
final boolean backwards = Mouse.isButtonDown(1);
final GuiImgButton iBtn = (GuiImgButton) btn;
if (iBtn.getSetting() != Settings.ACTIONS) {
final Enum<?> cv = iBtn.getCurrentValue();
final Enum<?> next = Platform.rotateEnum(cv, backwards, iBtn.getSetting().getPossibleValues());
@@ -273,6 +272,8 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
AEConfig.instance.settings.getSetting(Settings.TERMINAL_STYLE)));
this.offsetY += 20;
// Right now 80 > offsetX, but that can be changed later.
// noinspection DataFlowIssue
this.searchField = new FCGuiTextField(
this.fontRendererObj,
this.guiLeft + Math.max(80, this.offsetX),
@@ -433,7 +434,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
if (slot instanceof SlotPatternTerm) {
if (mouseButton == 6) {
return; // prevent weird double clicks..
return; // prevents weird double clicks
}
try {
NetworkHandler.instance.sendToServer(((SlotPatternTerm) slot).getRequest(isShiftKeyDown()));
@@ -442,13 +443,13 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
}
} else if (slot instanceof SlotCraftingTerm) {
if (mouseButton == 6) {
return; // prevent weird double clicks..
return; // prevents weird double clicks
}
InventoryAction action;
if (isShiftKeyDown()) {
action = InventoryAction.CRAFT_SHIFT;
} else {
// Craft stack on right-click, craft single on left-click
// Craft a stack on right-click, craft a single one on left-click
action = (mouseButton == 1) ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
}
final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
@@ -222,7 +222,7 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
}
/**
* The insert operation. For input, we have an filled container stack. For outputs, we have the following: 1.
* The insert operation. For input, we have a filled container stack. For outputs, we have the following: 1.
* Leftover filled container stack - primary output. 2. Empty containers 3. Partially filled container x1 In order
* above, the itemstack at `slotIndex` is transformed into the output.
*/
@@ -106,7 +106,10 @@ public class ContainerFluidPatternEncoder extends AEBaseContainer implements IPa
}
private static IAEItemStack[] collectAeInventory(AeStackInventory<IAEItemStack> inv) {
// see note at top of DensePatternDetails
/*
* AE2 API documentation says the input/output arrays can contain nulls, but their use of the API directly
* contradicts that, so we just go by behaviour and filter out nulls.
*/
List<IAEItemStack> acc = new ArrayList<>();
for (IAEItemStack stack : inv) {
if (stack != null) {
@@ -130,20 +133,20 @@ public class ContainerFluidPatternEncoder extends AEBaseContainer implements IPa
if (slot instanceof SlotFluidConvertingFake) {
final ItemStack stack = player.inventory.getItemStack();
switch (action) {
case PICKUP_OR_SET_DOWN:
case PICKUP_OR_SET_DOWN -> {
if (stack == null) {
slot.putStack(null);
} else {
((SlotFluidConvertingFake) slot).putConvertedStack(stack.copy());
}
break;
case PLACE_SINGLE:
}
case PLACE_SINGLE -> {
if (stack != null) {
((SlotFluidConvertingFake) slot)
.putConvertedStack(Objects.requireNonNull(Util.copyStackWithSize(stack, 1)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
}
case SPLIT_OR_PLACE_SINGLE -> {
ItemStack inSlot = slot.getStack();
if (inSlot != null) {
if (stack == null) {
@@ -161,7 +164,7 @@ public class ContainerFluidPatternEncoder extends AEBaseContainer implements IPa
((SlotFluidConvertingFake) slot)
.putConvertedStack(Objects.requireNonNull(Util.copyStackWithSize(stack, 1)));
}
break;
}
}
} else {
super.doAction(player, action, slotId, id);
@@ -42,13 +42,12 @@ import appeng.util.inv.WrapperInvSlot;
public class ContainerInterfaceWireless extends FCBaseContainer {
/**
* this stuff is all server side..
* this stuff is all server side
*/
private static long autoBase = Long.MIN_VALUE;
private final Multimap<IInterfaceHost, ContainerInterfaceWireless.InvTracker> diList = HashMultimap.create();
private final Map<Long, ContainerInterfaceWireless.InvTracker> byId = new HashMap<Long, ContainerInterfaceWireless.InvTracker>();
// private final Map<Long, InvTracker> byId = new HashMap<>();
private final Map<Long, ContainerInterfaceWireless.InvTracker> byId = new HashMap<>();
private IGrid grid;
private NBTTagCompound data = new NBTTagCompound();
@@ -114,9 +113,7 @@ public class ContainerInterfaceWireless extends FCBaseContainer {
try {
NetworkHandler.instance
.sendTo(new PacketCompressedNBT(this.data), (EntityPlayerMP) this.getPlayerInv().player);
} catch (final IOException e) {
// :P
}
} catch (final IOException ignored) {}
this.data = new NBTTagCompound();
}
@@ -140,7 +137,7 @@ public class ContainerInterfaceWireless extends FCBaseContainer {
boolean canInsert = true;
switch (action) {
case PICKUP_OR_SET_DOWN:
case PICKUP_OR_SET_DOWN -> {
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSizeInventory(); s++) {
if (Platform.isSameItemPrecise(
@@ -175,9 +172,8 @@ public class ContainerInterfaceWireless extends FCBaseContainer {
final IInventory mySlot = slotInv.getWrapper(slot + inv.offset);
mySlot.setInventorySlotContents(0, playerHand.addItems(mySlot.getStackInSlot(0)));
}
break;
case SPLIT_OR_PLACE_SINGLE:
}
case SPLIT_OR_PLACE_SINGLE -> {
if (hasItemInHand) {
for (int s = 0; s < interfaceHandler.getSizeInventory(); s++) {
if (Platform.isSameItemPrecise(
@@ -205,31 +201,28 @@ public class ContainerInterfaceWireless extends FCBaseContainer {
interfaceSlot.addItems(extra);
}
}
break;
case SHIFT_CLICK:
}
case SHIFT_CLICK -> {
final IInventory mySlot = slotInv.getWrapper(slot + inv.offset);
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
mySlot.setInventorySlotContents(0, mergeToPlayerInventory(playerInv, mySlot.getStackInSlot(0)));
break;
case MOVE_REGION:
}
case MOVE_REGION -> {
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN);
for (int x = 0; x < inv.client.getSizeInventory(); x++) {
inv.server.setInventorySlotContents(
x + inv.offset,
mergeToPlayerInventory(playerInvAd, inv.server.getStackInSlot(x + inv.offset)));
}
break;
case CREATIVE_DUPLICATE:
}
case CREATIVE_DUPLICATE -> {
if (player.capabilities.isCreativeMode && !hasItemInHand) {
player.inventory.setItemStack(is == null ? null : is.copy());
}
break;
default:
}
default -> {
return;
}
}
this.updateHeld(player);
@@ -132,11 +132,11 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
&& (stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack))) {
FluidStack fluid = null;
switch (action) {
case PICKUP_OR_SET_DOWN:
case PICKUP_OR_SET_DOWN -> {
fluid = Util.getFluidFromItem(stack);
slot.putStack(ItemFluidPacket.newStack(fluid));
break;
case SPLIT_OR_PLACE_SINGLE:
}
case SPLIT_OR_PLACE_SINGLE -> {
fluid = Util.getFluidFromItem(Util.copyStackWithSize(stack, 1));
FluidStack origin = ItemFluidPacket.getFluidStack(slot.getStack());
if (fluid != null && fluid.equals(origin)) {
@@ -144,7 +144,7 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
if (fluid.amount <= 0) fluid = null;
}
slot.putStack(ItemFluidPacket.newStack(fluid));
break;
}
}
if (fluid == null) {
super.doAction(player, action, slotId, id);
@@ -98,7 +98,7 @@ public abstract class FCContainerFluidConfigurable extends ContainerUpgradeable
@Override
protected void standardDetectAndSendChanges() {
if (Platform.isServer()) {
// clear out config items that are no longer valid (eg capacity upgrade removed)
// clear out config items that are no longer valid (for instance, capacity upgrade removed)
final AppEngInternalAEInventory inv = this.getFakeFluidInv();
final Map<Integer, IAEFluidStack> tmp = new HashMap<>();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
@@ -210,8 +210,7 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
@Override
public void onListUpdate() {
for (final Object c : this.crafters) {
if (c instanceof ICrafting) {
final ICrafting cr = (ICrafting) c;
if (c instanceof final ICrafting cr) {
this.queueInventory(cr);
}
}
@@ -37,15 +37,12 @@ public class ItemWalrusRender implements IItemRenderer {
Minecraft.getMinecraft().renderEngine.bindTexture(this.textureWalrus);
GL11.glPushMatrix();
switch (type) {
case EQUIPPED_FIRST_PERSON:
case EQUIPPED_FIRST_PERSON -> {
GL11.glRotated(180, 0, 1, 0);
GL11.glTranslatef(-1F, 0.5F, -0.5F);
break;
case INVENTORY:
GL11.glTranslatef(-0.5F, -0.5F, -0.1F);
break;
default:
break;
}
case INVENTORY -> GL11.glTranslatef(-0.5F, -0.5F, -0.1F);
default -> {}
}
this.modelWalrus.renderAll();
GL11.glPopMatrix();
@@ -97,7 +97,7 @@ public class FluidTankRenderer {
for (int s = 0; s < DISPLAY_STAGES; ++s) {
diplayLists[s] = GLAllocation.generateDisplayLists(1);
GL11.glNewList(diplayLists[s], 4864 /* GL_COMPILE */);
GL11.glNewList(diplayLists[s], GL11.GL_COMPILE);
liquidBlock.minX = 0.01f;
liquidBlock.minY = 0;