aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui/widgets
diff options
context:
space:
mode:
authorchill <chill.gtnh@outlook.com>2023-06-05 06:51:28 +0200
committerGitHub <noreply@github.com>2023-06-05 06:51:28 +0200
commitdb089891a20e5696096907864578e39586035e6e (patch)
treee56d68eb64c3b8025193930b68e731b23d0f60d9 /src/main/java/gregtech/api/gui/widgets
parentdd9bbe334a00a0435502ac502d4155bfa12d123d (diff)
downloadGT5-Unofficial-db089891a20e5696096907864578e39586035e6e.tar.gz
GT5-Unofficial-db089891a20e5696096907864578e39586035e6e.tar.bz2
GT5-Unofficial-db089891a20e5696096907864578e39586035e6e.zip
Code cleanup (#2040)
* remove redundant suppressions * prettify commented code * improve comments The integer comment contradicted the code, so I deleted it. * delete commented-out code * update bitwise int flip from XOR to the dedicated tilda operator The flip was a 32-bit XOR, which is an int-flip. That XOR was replaced with an equivalent tilda operator. * convert a field to inline This field was used only once, so put it straight to where it is used. * remove fluid fix since no-one uses Forge version 1355 or earlier * unwrap switches where fitting In some places, we suppress IntelliJ's inspection RedundantLabeledSwitchRuleCodeBlock - we don't want to unwrap some of the suggested cases because we want to keep the consistency in a switch statement for the sake of readability. * fuse "collect" into Stream API * fix javadocs * remove unnecessary public modifiers from an interface Members of an interface are public by default. * move common parts outside of if * suppress OverrideOnly warning in a javadoc * remove unused lock * suppress warnings about unchecked casts These warnings require non-trivial fixes that are yet to arrive. For now, let's suppress them to reduce the warning-bloat. * remove outdated comment * remove final modifier from private methods Because they are private, it is hard to accidentally overwrite them. Therefore, the final modifier is redundant in this case. * refactor getIcon The first 'if' doesn't cover only tMeta == 9 && mConnectedMachineTextures, therefore the second if can be unrolled. The last switch is redundant because all tMeta values are covered by switches, but let's keep SOLID_STEEL as a fallback just in case. * explain what the casings are and why block casings are split * suppress switch-to-if suggestion * remove unnecessary null check The null is handled in doGenerateItem() * address redundant local variables * rename variables in onTick * suppress warning about accessing static member via instance * rephrase exception * rephrase javadoc * address field-can-be-final warnings * remove empty methods * enum cannot inherit, so protected is redundant * remove redundant throws * update imports to be not wildcard * remove unnecessary try-catch * update for loop * remove redundant code in order to use the diamond operator * update instanceof to use pattern variables * replace blank lines with <p> in javadocs * fix dangling javadocs * suppress warning about unreachable methods in javadocs * remove redundant operation * add the descriptions of parameters in javadocs Also fix javadocs along the way. * relax returned type in javadoc That was done in order to make the docs reflect the code more often. Otherwise, people may forget to change the returned type again with another change. * make long conversion explicit Integer multiplication can give a wrong result if one of the parts is not explicitly cast to long. Let's cast one of the parts where applicable. * remove unary plus * simplify unary minus * use addAll instead of forEach,add It was suggested by IntelliJ to replace the iteration with a bulk operation to improve performance. * replace .asList with .singletonList for consistency * simplify toArray calls Explanation from IntelliJ: There are two styles to convert a collection to an array: * A pre-sized array, for example, c.toArray(new String[c.size()]) * An empty array, for example, c.toArray(new String[0]) In older Java versions, using a pre-sized array was recommended, as the reflection call necessary to create an array of proper size was quite slow. However, since late updates of OpenJDK 6, this call was intrinsified, making the performance of the empty array version the same, and sometimes even better, compared to the pre-sized version. Also, passing a pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray calls. This may result in extra nulls at the end of the array if the collection was concurrently shrunk during the operation. * split StringBuilder append Explanation by IntelliJ: Reports String concatenation used as the argument to appends. Such calls may profitably be turned into chained append calls on the existing StringBuilder saving the cost of an extra StringBuilder allocation. This inspection ignores compile-time evaluated String concatenations, in which case the conversion would only worsen performance. * annotate overriding methods with @Nonnull where needed The method that was overridden has @Nonnull so the method that is overriding should also have @Nonnull. * remove set adding itself to itself * remove null check because findField either works or blows up cpw.mods.fml.relauncher.ReflectionHelper::findField either returns a non-null value or throws a RuntimeException, so no need to check of null. * remove slot comparison with tInventory.length slot max value is 127 when tInventory.length is set to 256, which results in that the condition is always true and unnecessary. * remove aOutput2 null check As GT_Values.NI is null, there is no need to check aOutput2 for null again * suppress the suggestion to delete tMeta < 13 mConnectedMachineTextures can change, so tMeta range is not guaranteed * remove aCoverVariable % 3 < 2 the if above already limits the result of % 3 to "2", so the condition "less than 2" is always false. * unwrap "if" because bonus is unchanged Unwrap if because even if the bonus is a variable, it hasn't been changed for the past 8 years and is unlikely to be changed in the future. * reformat javadoc * improve ignoring an exception Make them either more clear or concise * fixup fix typo * update deprecated calls of newInstance() * remove testing BaseMetaTileEntity GregTech_API.constructBaseMetaTileEntity() checks the creation by itself, logging and throwing a runtime error if failed. * unwrap hatch-fill for do_SolarSalt To reach this branch, do_coolant needs to be false and we need to still be in the function, which means that do_SolarSalt was set to true in the previous top-tier "if". * remove always-false input-bus checks of MTE PlasmaForge size() is non-negative, and the values it is compared to are final and 0. * length and size are non-negative Therefore, there's no need to check their negativity * aOutput is guaranteed to be positive * tThereWasARecipe is always false when reached in its first occurrence * convert an assert into if Only tStack 2 is checked for null because if it isn't null then tStack1 also isn't null based on the "if" above. Also IntelliJ was sure that tStack is not null for some reason. On a side note, assertions work only either with a specified flag or in debug runs. Therefore, it is dangerous to rely on them. * simplify stone-gravel-cobble if tBlock != Blocks.stone because of the if at the start of the method. for the last else-if, tBlock == Blocks.gravel because of the check slightly above the change. * interDimensional is always true because of the first if * convert an example to javadoc * remove always-false statements * replace referential string equality with equals If we compare strings by "==", we compare references to them, which is not what we usually want. I wasn't sure if String Pool works here, so I played it save with equals(). * use Automatic Resource Management for AutoCloseable ByteBufOutputStream * add todo to swap from sleep to event bus * null is checked by instanceof * merge switch branches * add a TODO to use clamp() * new String declaration is redundant * use getOrDefault for a map * replace StringBuilder with concatenation where fitting Using a StringBuilder to concatenate two string will not make the program faster or more understandable, so I swapped it to concatenation. * remove unnecessary continue * flip if * remove redundant returns * unwrap ifs It's checked at the top "if" that aType == IItemRenderer.ItemRenderType.INVENTORY, so all aType.equals(IItemRenderer.ItemRenderType.INVENTORY below are always true. * remove checking all GT VERSIONs except the API one * remove version check from GT_Mod and delete respective VERSION fields Aside from GregTech_API.VERSION, these fields are not used anywhere in the project, so only GregTech_API.VERSION was kept. The idea and the usage check were done by miozune.
Diffstat (limited to 'src/main/java/gregtech/api/gui/widgets')
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java12
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java2
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java6
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java2
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java2
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java20
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java55
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java16
8 files changed, 57 insertions, 58 deletions
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
index d52b09b9d5..6f4eb0e2c2 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java
@@ -103,8 +103,8 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
/**
* Add the cover on this side of the IGregTechTileEntity to the tabs
*
- * @param side
- * @param cover
+ * @param side side to apply the cover to
+ * @param cover cover to add
*/
private void addCoverToTabs(ForgeDirection side, ItemStack cover) {
final boolean enabled = this.tile.getCoverBehaviorAtSideNew(side)
@@ -117,9 +117,9 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
/**
* Decorate the cover's tooltips according to the side it's on and on whether the tab is enabled or not
*
- * @param side
- * @param cover
- * @param enabled
+ * @param side side
+ * @param cover cover which tooltip to decorate
+ * @param enabled if the tab is enabled
* @return This cover tab's tooltip
*/
private String[] getTooltipForCoverTab(ForgeDirection side, ItemStack cover, boolean enabled) {
@@ -135,7 +135,7 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine {
/**
* Get the translated name for a side of the IGregTechTileEntity
*
- * @param side
+ * @param side side of the entity
* @return translated name for a side of the IGregTechTileEntity
*/
private String getSideDescription(ForgeDirection side) {
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java
index b534359cac..9f4287a65b 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiFakeItemButton.java
@@ -1,6 +1,6 @@
package gregtech.api.gui.widgets;
-import java.awt.*;
+import java.awt.Rectangle;
import java.util.List;
import net.minecraft.client.Minecraft;
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
index 46d213f0f6..66ab27356e 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
@@ -113,16 +113,16 @@ public enum GT_GuiIcon implements IGuiIcon {
/**
* This is intended to enable addon mods to register additional textures. They can then add to this enum using
- * EnumHelper.addEnum or by creating your their enum that implements IGuiIcon (still requires adding a texture here)
+ * EnumHelper.addEnum or by creating their enum that implements IGuiIcon (still requires adding a texture here)
*
- * @param location
+ * @param location location of the texture to add
*/
public static void addTextures(ResourceLocation... location) {
if (location == null || location.length == 0) return;
int startIndex = TEXTURES.length;
TEXTURES = Arrays.copyOf(TEXTURES, location.length);
- System.arraycopy(location, 0, TEXTURES, startIndex + 0, location.length);
+ System.arraycopy(location, 0, TEXTURES, startIndex, location.length);
}
@Override
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
index 62d6648e73..d4bfe31404 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
@@ -17,7 +17,7 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen
protected GT_GuiIcon icon;
private final int x0;
private final int y0;
- protected IGuiScreen gui;
+ protected final IGuiScreen gui;
private GT_GuiTooltip tooltip;
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java
index ef5348cf77..2d3c7374bd 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java
@@ -1,6 +1,6 @@
package gregtech.api.gui.widgets;
-import java.awt.*;
+import java.awt.Rectangle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java
index 151eba2936..d06c2bd2eb 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTab.java
@@ -34,7 +34,7 @@ public class GT_GuiTab {
* A tab to be attached to a tab line
*
* @param gui IGregTechTileEntity the tab line this tab belongs to is attached to
- * @param id both the ID and position in the tab line of this tab
+ * @param id both the ID and position in the tab line of this tab. Not used, kept for compatibility.
* @param bounds bounds of this tab
* @param tabBackground set of background textures
* @param item item to draw atop the background texture, not colored
@@ -62,7 +62,7 @@ public class GT_GuiTab {
/**
* Set this tab's tooltip text
*
- * @param text
+ * @param text text to set
* @return This tab for chaining
*/
public GT_GuiTab setTooltipText(String... text) {
@@ -85,9 +85,9 @@ public class GT_GuiTab {
/**
* Draw the background texture for this tab
*
- * @param mouseX
- * @param mouseY
- * @param parTicks
+ * @param mouseX not used, likely kept for backward compatibility
+ * @param mouseY not used, likely kept for backward compatibility
+ * @param parTicks not used, likely kept for backward compatibility
*/
public void drawBackground(int mouseX, int mouseY, float parTicks) {
if (this.visible) {
@@ -106,9 +106,9 @@ public class GT_GuiTab {
/**
* Draw overlay textures and items atop the background texture
*
- * @param mouseX
- * @param mouseY
- * @param parTicks
+ * @param mouseX X mouse coordinate
+ * @param mouseY Y mouse coordinate
+ * @param parTicks not used, likely kept for backward compatibility
*/
public void drawOverlays(int mouseX, int mouseY, float parTicks) {
this.mousedOver = bounds.contains(mouseX, mouseY);
@@ -165,8 +165,8 @@ public class GT_GuiTab {
/**
* Reposition this tab on the screen
*
- * @param xPos
- * @param yPos
+ * @param xPos X tab coordinate
+ * @param yPos Y tab coordinate
*/
public void setPosition(int xPos, int yPos) {
this.bounds = new Rectangle(xPos, yPos, bounds.width, bounds.height);
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java
index 74145463b3..950478cdfa 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTabLine.java
@@ -86,7 +86,8 @@ public class GT_GuiTabLine {
private final DisplayStyle yDir;
// Whether to display on the right side of the GT_ITabRenderer instead of left
- protected boolean flipHorizontally, visible;
+ protected final boolean flipHorizontally;
+ protected final boolean visible;
private final GT_GuiTabIconSet tabBackground;
private final GT_ITabRenderer gui;
@@ -128,10 +129,10 @@ public class GT_GuiTabLine {
/**
* Creates a new tab at the specified position with the given parameters. This class handles the positioning.
*
- * @param tabId
- * @param item
- * @param overlay
- * @param text
+ * @param tabId tab ID
+ * @param item item to draw atop the background texture, not colored
+ * @param overlay texture to draw atop the background texture, not colored
+ * @param text tooltip of this tab
*/
public void setTab(int tabId, ItemStack item, IGuiIcon overlay, String[] text) {
mTabs[tabId] = new GT_GuiTab(
@@ -148,8 +149,8 @@ public class GT_GuiTabLine {
/**
* Get the bounds a given tab should occupy
*
- * @param tabId
- * @return
+ * @param tabId tab ID
+ * @return tab bounds
*/
protected Rectangle getBoundsForTab(int tabId) {
return new Rectangle(getTabX(tabId), getTabY(tabId), this.tabWidth, this.tabHeight);
@@ -158,12 +159,12 @@ public class GT_GuiTabLine {
/**
* Enable or disable a tab. Disabled tabs have a dark background.
*
- * @param tabId
- * @param value
+ * @param tabId tab ID
+ * @param enable true to enable, false to disable
*/
- public void setTabEnabled(int tabId, boolean value) {
+ public void setTabEnabled(int tabId, boolean enable) {
if (mTabs[tabId] != null) {
- mTabs[tabId].enabled = value;
+ mTabs[tabId].enabled = enable;
}
}
@@ -172,8 +173,6 @@ public class GT_GuiTabLine {
* drawScreen.
*
* @param parTicks
- * @param mouseX
- * @param mouseY
*/
public void drawTabs(float parTicks, int mouseX, int mouseY) {
if (this.visible) {
@@ -189,9 +188,9 @@ public class GT_GuiTabLine {
/**
* Draw the tab's backgrounds first
*
- * @param parTicks
- * @param mouseX
- * @param mouseY
+ * @param parTicks not used, likely kept for compatibility
+ * @param mouseX mouse X position
+ * @param mouseY mouse Y position
*/
protected void drawOverlays(float parTicks, int mouseX, int mouseY) {
for (GT_GuiTab mTab : mTabs) {
@@ -204,9 +203,9 @@ public class GT_GuiTabLine {
/**
* Draw anything that overlays the tab's background texture
*
- * @param parTicks
- * @param mouseX
- * @param mouseY
+ * @param parTicks not used, likely kept for compatibility
+ * @param mouseX mouse X position
+ * @param mouseY mouse Y position
*/
protected void drawBackground(float parTicks, int mouseX, int mouseY) {
for (GT_GuiTab mTab : mTabs) {
@@ -219,9 +218,9 @@ public class GT_GuiTabLine {
/**
* Call tabClick for every tab that was clicked. GT_ITabRenderer must call this method on mouseClicked.
*
- * @param mouseX
- * @param mouseY
- * @param mouseButton
+ * @param mouseX mouse X position
+ * @param mouseY mouse Y position
+ * @param mouseButton which mouse button was used to click
*/
public void onMouseClicked(int mouseX, int mouseY, int mouseButton) {
for (int tabId = 0; tabId < mTabs.length; tabId++) {
@@ -236,8 +235,8 @@ public class GT_GuiTabLine {
/**
* Act on a tab being clicked.
*
- * @param tabId
- * @param mouseButton
+ * @param tabId tab ID
+ * @param mouseButton which mouse button was used to click
*/
protected void tabClicked(int tabId, int mouseButton) {}
@@ -255,8 +254,8 @@ public class GT_GuiTabLine {
/**
* Get the proper X position for a given tab
*
- * @param tabId
- * @return
+ * @param tabId tab ID
+ * @return X position of the tab
*/
private int getTabX(int tabId) {
return this.gui.getGuiLeft() + (flipHorizontally ? (gui.getXSize() - tabLineLeft - tabWidth) : tabLineLeft)
@@ -266,8 +265,8 @@ public class GT_GuiTabLine {
/**
* Get the proper Y position for a given tab
*
- * @param tabId
- * @return
+ * @param tabId tab ID
+ * @return Y position of the tab
*/
private int getTabY(int tabId) {
return this.gui.getGuiTop() + tabLineTop + (tabId * (tabHeight + tabSpacing) * yDir.getValue());
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java
index 326e744382..fe20b2b57a 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiTooltip.java
@@ -11,7 +11,7 @@ import gregtech.api.util.GT_TooltipDataCache.TooltipData;
public class GT_GuiTooltip {
- protected Rectangle bounds;
+ protected final Rectangle bounds;
protected TooltipData data;
private List<String> displayedText;
public boolean enabled = true;
@@ -20,8 +20,8 @@ public class GT_GuiTooltip {
* Used to create a tooltip that will appear over the specified bounds. This will initially be a "static" tooltip
* that doesn't respect verbosity levels or respond to the shift key.
*
- * @param bounds
- * @param text
+ * @param bounds tooltip bounds
+ * @param text tooltip text
*/
public GT_GuiTooltip(Rectangle bounds, String... text) {
this.bounds = bounds;
@@ -32,8 +32,8 @@ public class GT_GuiTooltip {
* Used to create a tooltip that will appear over the specified bounds. This will initially be a "dynamic" tooltip
* that respects verbosity levels and responds to the shift key.
*
- * @param bounds
- * @param data
+ * @param bounds tooltip bounds
+ * @param data tooltip data
*/
public GT_GuiTooltip(Rectangle bounds, TooltipData data) {
this.bounds = bounds;
@@ -69,7 +69,7 @@ public class GT_GuiTooltip {
/**
* Used to set a "static" tooltip that doesn't respect verbosity levels or respond to the shift key
*
- * @param text
+ * @param text tooltip text
*/
public void setToolTipText(String... text) {
this.data = formatTooltip(text);
@@ -79,7 +79,7 @@ public class GT_GuiTooltip {
/**
* Used to set a "dynamic" tooltip that respects verbosity levels and responds to the shift key
*
- * @param data
+ * @param data tooltip data
*/
public void setToolTipText(TooltipData data) {
// Trust that the tooltips have already been formatted and colored, just make sure it has no nulls
@@ -89,7 +89,7 @@ public class GT_GuiTooltip {
/**
* Apply tooltip colors in case the text doesn't contain them and return as tooltip data
*
- * @param text
+ * @param text text to apply the colors to
* @return colored tooltip lines as list
*/
protected TooltipData formatTooltip(String[] text) {