From d28de77017fc810cd253021470bc7de6f9a96f12 Mon Sep 17 00:00:00 2001
From: Juuxel <6596629+Juuxel@users.noreply.github.com>
Date: Sat, 24 Oct 2020 14:20:09 +0300
Subject: Add checkstyle to check code format
---
.editorconfig | 1 +
build.gradle | 6 +
checkstyle.xml | 46 +++
.../github/cottonmc/cotton/gui/ValidatedSlot.java | 9 +-
.../cotton/gui/client/CottonInventoryScreen.java | 4 +-
.../cottonmc/cotton/gui/client/LibGuiClient.java | 9 +-
.../cottonmc/cotton/gui/client/NinePatch.java | 386 ++++++++++-----------
.../cottonmc/cotton/gui/client/Scissors.java | 1 +
.../cottonmc/cotton/gui/client/ScreenDrawing.java | 4 +-
.../cotton/gui/client/modmenu/ModMenuSupport.java | 5 +-
.../cotton/gui/impl/access/SlotAccessor.java | 1 +
.../cotton/gui/impl/access/package-info.java | 4 +
.../cotton/gui/widget/WAbstractSlider.java | 3 +-
.../io/github/cottonmc/cotton/gui/widget/WBar.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WButton.java | 7 +-
.../cottonmc/cotton/gui/widget/WCardPanel.java | 3 +-
.../cottonmc/cotton/gui/widget/WClippedPanel.java | 3 +-
.../cottonmc/cotton/gui/widget/WGridPanel.java | 2 +-
.../github/cottonmc/cotton/gui/widget/WItem.java | 4 +-
.../github/cottonmc/cotton/gui/widget/WLabel.java | 2 +-
.../cottonmc/cotton/gui/widget/WPlainPanel.java | 2 +-
.../cottonmc/cotton/gui/widget/WScrollBar.java | 7 +-
.../github/cottonmc/cotton/gui/widget/WSprite.java | 2 +-
.../cottonmc/cotton/gui/widget/WTiledSprite.java | 5 +-
.../github/cottonmc/cotton/gui/widget/WWidget.java | 3 +-
.../cotton/gui/widget/icon/TextureIcon.java | 5 +-
26 files changed, 296 insertions(+), 230 deletions(-)
create mode 100644 checkstyle.xml
create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java
diff --git a/.editorconfig b/.editorconfig
index 51ff9ad..e8cdad1 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -4,6 +4,7 @@ root = true
charset = utf-8
indent_style = tab
end_of_line = lf
+insert_final_newline = true
[*.java]
ij_java_imports_layout = com.mojang.**,net.fabricmc.**,net.minecraft.**,|,*,|,javax.**,java.**,|,$*
diff --git a/build.gradle b/build.gradle
index fbb61fa..074acc2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,6 +2,7 @@ plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
id "com.jfrog.artifactory" version "4.9.0"
+ id 'checkstyle'
}
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -69,6 +70,11 @@ jar {
from "LICENSE"
}
+checkstyle {
+ configFile = file('checkstyle.xml')
+ toolVersion = '8.36.2'
+}
+
// configure the maven publication
publishing {
publications {
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100644
index 0000000..ba8120f
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,46 @@
+
+
+
If the {@code mode} is not null, it will override the one specified in the texture metadata. - * A null mode uses the texture metadata. - */ - public NinePatch setMode(@Nullable Mode mode) { - this.mode = mode; - return this; - } - - @Override - public void paintBackground(int left, int top, WWidget panel) { - int width = panel.getWidth() + leftPadding + rightPadding; - int height = panel.getHeight() + topPadding + bottomPadding; - left = left - leftPadding; - top = top - topPadding; - int x1 = left + cornerSize; - int x2 = left + width - cornerSize; - int y1 = top + cornerSize; - int y2 = top + height - cornerSize; - float uv1 = cornerUv; - float uv2 = 1.0f - cornerUv; - Mode mode = this.mode != null ? this.mode : MetadataLoader.INSTANCE.getProperties(texture).getMode(); - - ScreenDrawing.texturedRect(left, top, cornerSize, cornerSize, texture, 0, 0, uv1, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, top, cornerSize, cornerSize, texture, uv2, 0, 1, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(left, y2, cornerSize, cornerSize, texture, 0, uv2, uv1, 1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y2, cornerSize, cornerSize, texture, uv2, uv2, 1, 1, 0xFF_FFFFFF); - - if (mode == Mode.TILING) { - int tileSize = (int) (cornerSize / cornerUv - 2 * cornerSize); - int widthLeft = width - 2 * cornerSize; - int heightLeft = height - 2 * cornerSize; - int tileCountX = MathHelper.ceil((float) widthLeft / tileSize); - int tileCountY = MathHelper.ceil((float) heightLeft / tileSize); - for (int i = 0; i < tileCountX; i++) { - float px = 1 / 16f; - int tileWidth = Math.min(widthLeft, tileSize); - float uo = (tileSize - tileWidth) * px; // Used to remove unnecessary pixels on the X axis - - ScreenDrawing.texturedRect(x1 + i * tileSize, top, tileWidth, cornerSize, texture, uv1, 0, uv2 - uo, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1 + i * tileSize, y2, tileWidth, cornerSize, texture, uv1, uv2, uv2 - uo, 1, 0xFF_FFFFFF); - - // Reset the height left each time the Y is looped - heightLeft = height - 2 * cornerSize; - - for (int j = 0; j < tileCountY; j++) { - int tileHeight = Math.min(heightLeft, tileSize); - float vo = (tileSize - tileHeight) * px; // Used to remove unnecessary pixels on the Y axis - - ScreenDrawing.texturedRect(left, y1 + j * tileSize, cornerSize, tileHeight, texture, 0, uv1, uv1, uv2 - vo, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y1 + j * tileSize, cornerSize, tileHeight, texture, uv2, uv1, 1, uv2 - vo, 0xFF_FFFFFF); - - ScreenDrawing.texturedRect(x1 + i * tileSize, y1 + j * tileSize, tileWidth, tileHeight, texture, uv1, uv1, uv2 - uo, uv2 - vo, 0xFF_FFFFFF); - heightLeft -= tileSize; - } - widthLeft -= tileSize; - } - } else { - ScreenDrawing.texturedRect(x1, top, width - 2 * cornerSize, cornerSize, texture, uv1, 0, uv2, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(left, y1, cornerSize, height - 2 * cornerSize, texture, 0, uv1, uv1, uv2, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1, y2, width - 2 * cornerSize, cornerSize, texture, uv1, uv2, uv2, 1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y1, cornerSize, height - 2 * cornerSize, texture, uv2, uv1, 1, uv2, 0xFF_FFFFFF); - - ScreenDrawing.texturedRect(x1, y1, width - 2 * cornerSize, height - 2 * cornerSize, texture, uv1, uv1, uv2, uv2, 0xFF_FFFFFF); - } - } - - /** - * The mode of a nine-patch painter defines how it fills the area between the corners. - */ - public enum Mode { - /** - * The texture is stretched to fill the edges and the center. - * This is the default mode. - */ - STRETCHING, - - /** - * The texture is tiled to fill the edges and the center. - */ - TILING; - - @Nullable - static Mode fromString(String str) { - if (str == null) return null; - - if (str.equalsIgnoreCase("stretching")) return STRETCHING; - if (str.equalsIgnoreCase("tiling")) return TILING; - - return null; - } - } + private final Identifier texture; + private final int cornerSize; + private final float cornerUv; + private int topPadding = 0; + private int leftPadding = 0; + private int bottomPadding = 0; + private int rightPadding = 0; + private Mode mode = null; + + /** + * Creates a nine-patch background painter with 4 px corners and a 0.25 corner UV. + * + * @param texture the texture ID + */ + public NinePatch(Identifier texture) { + this(texture, 4, 0.25f); + } + + /** + * Creates a nine-patch background painter. + * + * @param texture the texture ID + * @param cornerSize the size of the corners on the screen + * @param cornerUv the fraction of the corners from the whole texture + */ + public NinePatch(Identifier texture, int cornerSize, float cornerUv) { + this.texture = texture; + this.cornerSize = cornerSize; + this.cornerUv = cornerUv; + } + + public int getTopPadding() { + return topPadding; + } + + public NinePatch setTopPadding(int topPadding) { + this.topPadding = topPadding; + return this; + } + + public int getLeftPadding() { + return leftPadding; + } + + public NinePatch setLeftPadding(int leftPadding) { + this.leftPadding = leftPadding; + return this; + } + + public int getBottomPadding() { + return bottomPadding; + } + + public NinePatch setBottomPadding(int bottomPadding) { + this.bottomPadding = bottomPadding; + return this; + } + + public int getRightPadding() { + return rightPadding; + } + + public NinePatch setRightPadding(int rightPadding) { + this.rightPadding = rightPadding; + return this; + } + + public NinePatch setPadding(int padding) { + this.topPadding = this.leftPadding = this.bottomPadding = this.rightPadding = padding; + return this; + } + + public NinePatch setPadding(int vertical, int horizontal) { + this.topPadding = this.bottomPadding = vertical; + this.leftPadding = this.rightPadding = horizontal; + return this; + } + + public NinePatch setPadding(int topPadding, int leftPadding, int bottomPadding, int rightPadding) { + this.topPadding = topPadding; + this.leftPadding = leftPadding; + this.bottomPadding = bottomPadding; + this.rightPadding = rightPadding; + + return this; + } + + public Identifier getTexture() { + return texture; + } + + public int getCornerSize() { + return cornerSize; + } + + @Nullable + public Mode getMode() { + return mode; + } + + /** + * Sets the {@linkplain Mode mode} of this painter to the specified mode. + *
If the {@code mode} is not null, it will override the one specified in the texture metadata.
+ * A null mode uses the texture metadata.
+ */
+ public NinePatch setMode(@Nullable Mode mode) {
+ this.mode = mode;
+ return this;
+ }
+
+ @Override
+ public void paintBackground(int left, int top, WWidget panel) {
+ int width = panel.getWidth() + leftPadding + rightPadding;
+ int height = panel.getHeight() + topPadding + bottomPadding;
+ left = left - leftPadding;
+ top = top - topPadding;
+ int x1 = left + cornerSize;
+ int x2 = left + width - cornerSize;
+ int y1 = top + cornerSize;
+ int y2 = top + height - cornerSize;
+ float uv1 = cornerUv;
+ float uv2 = 1.0f - cornerUv;
+ Mode mode = this.mode != null ? this.mode : MetadataLoader.INSTANCE.getProperties(texture).getMode();
+
+ ScreenDrawing.texturedRect(left, top, cornerSize, cornerSize, texture, 0, 0, uv1, uv1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x2, top, cornerSize, cornerSize, texture, uv2, 0, 1, uv1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(left, y2, cornerSize, cornerSize, texture, 0, uv2, uv1, 1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x2, y2, cornerSize, cornerSize, texture, uv2, uv2, 1, 1, 0xFF_FFFFFF);
+
+ if (mode == Mode.TILING) {
+ int tileSize = (int) (cornerSize / cornerUv - 2 * cornerSize);
+ int widthLeft = width - 2 * cornerSize;
+ int heightLeft = height - 2 * cornerSize;
+ int tileCountX = MathHelper.ceil((float) widthLeft / tileSize);
+ int tileCountY = MathHelper.ceil((float) heightLeft / tileSize);
+ for (int i = 0; i < tileCountX; i++) {
+ float px = 1 / 16f;
+ int tileWidth = Math.min(widthLeft, tileSize);
+ float uo = (tileSize - tileWidth) * px; // Used to remove unnecessary pixels on the X axis
+
+ ScreenDrawing.texturedRect(x1 + i * tileSize, top, tileWidth, cornerSize, texture, uv1, 0, uv2 - uo, uv1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x1 + i * tileSize, y2, tileWidth, cornerSize, texture, uv1, uv2, uv2 - uo, 1, 0xFF_FFFFFF);
+
+ // Reset the height left each time the Y is looped
+ heightLeft = height - 2 * cornerSize;
+
+ for (int j = 0; j < tileCountY; j++) {
+ int tileHeight = Math.min(heightLeft, tileSize);
+ float vo = (tileSize - tileHeight) * px; // Used to remove unnecessary pixels on the Y axis
+
+ ScreenDrawing.texturedRect(left, y1 + j * tileSize, cornerSize, tileHeight, texture, 0, uv1, uv1, uv2 - vo, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x2, y1 + j * tileSize, cornerSize, tileHeight, texture, uv2, uv1, 1, uv2 - vo, 0xFF_FFFFFF);
+
+ ScreenDrawing.texturedRect(x1 + i * tileSize, y1 + j * tileSize, tileWidth, tileHeight, texture, uv1, uv1, uv2 - uo, uv2 - vo, 0xFF_FFFFFF);
+ heightLeft -= tileSize;
+ }
+ widthLeft -= tileSize;
+ }
+ } else {
+ ScreenDrawing.texturedRect(x1, top, width - 2 * cornerSize, cornerSize, texture, uv1, 0, uv2, uv1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(left, y1, cornerSize, height - 2 * cornerSize, texture, 0, uv1, uv1, uv2, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x1, y2, width - 2 * cornerSize, cornerSize, texture, uv1, uv2, uv2, 1, 0xFF_FFFFFF);
+ ScreenDrawing.texturedRect(x2, y1, cornerSize, height - 2 * cornerSize, texture, uv2, uv1, 1, uv2, 0xFF_FFFFFF);
+
+ ScreenDrawing.texturedRect(x1, y1, width - 2 * cornerSize, height - 2 * cornerSize, texture, uv1, uv1, uv2, uv2, 0xFF_FFFFFF);
+ }
+ }
+
+ /**
+ * The mode of a nine-patch painter defines how it fills the area between the corners.
+ */
+ public enum Mode {
+ /**
+ * The texture is stretched to fill the edges and the center.
+ * This is the default mode.
+ */
+ STRETCHING,
+
+ /**
+ * The texture is tiled to fill the edges and the center.
+ */
+ TILING;
+
+ @Nullable
+ static Mode fromString(String str) {
+ if (str == null) return null;
+
+ if (str.equalsIgnoreCase("stretching")) return STRETCHING;
+ if (str.equalsIgnoreCase("tiling")) return TILING;
+
+ return null;
+ }
+ }
public static class TextureProperties {
public static final TextureProperties DEFAULT = new TextureProperties(Mode.STRETCHING);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/Scissors.java b/src/main/java/io/github/cottonmc/cotton/gui/client/Scissors.java
index 4998a05..e7c7e72 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/Scissors.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/Scissors.java
@@ -3,6 +3,7 @@ package io.github.cottonmc.cotton.gui.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
+
import org.lwjgl.opengl.GL11;
import java.util.ArrayDeque;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index f382911..f31a046 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -2,7 +2,6 @@ package io.github.cottonmc.cotton.gui.client;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
-import io.github.cottonmc.cotton.gui.widget.data.Texture;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
@@ -10,9 +9,10 @@ import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.util.Identifier;
-import org.lwjgl.opengl.GL11;
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
+import io.github.cottonmc.cotton.gui.widget.data.Texture;
+import org.lwjgl.opengl.GL11;
/**
* {@code ScreenDrawing} contains utility methods for drawing contents on a screen.
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java
index 29ea6bf..e7c7ece 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ModMenuSupport.java
@@ -1,12 +1,11 @@
package io.github.cottonmc.cotton.gui.client.modmenu;
-
-import io.github.prospector.modmenu.api.ConfigScreenFactory;
-import io.github.prospector.modmenu.api.ModMenuApi;
import net.minecraft.text.TranslatableText;
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
import io.github.cottonmc.cotton.gui.client.LibGuiClient;
+import io.github.prospector.modmenu.api.ConfigScreenFactory;
+import io.github.prospector.modmenu.api.ModMenuApi;
public class ModMenuSupport implements ModMenuApi {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java
index 954b4a8..4b4644c 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/SlotAccessor.java
@@ -1,6 +1,7 @@
package io.github.cottonmc.cotton.gui.impl.access;
import net.minecraft.screen.slot.Slot;
+
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java
new file mode 100644
index 0000000..8f391fd
--- /dev/null
+++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Internal implementation classes.
+ */
+package io.github.cottonmc.cotton.gui.impl.access;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
index 3b9179d..6c422bc 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java
@@ -65,8 +65,7 @@ public abstract class WAbstractSlider extends WWidget {
@Nullable private IntConsumer draggingFinishedListener = null;
protected WAbstractSlider(int min, int max, Axis axis) {
- if (max <= min)
- throw new IllegalArgumentException("Minimum value must be smaller than the maximum!");
+ if (max <= min) throw new IllegalArgumentException("Minimum value must be smaller than the maximum!");
this.min = min;
this.max = max;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
index 826950c..13cf16b 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
@@ -245,4 +245,4 @@ public class WBar extends WWidget {
DOWN,
LEFT;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index 6bf65ff..65dde6f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -77,8 +77,11 @@ public class WButton extends WWidget {
public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) {
boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX