Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Replace checkstyle with spotless #837

Draft
wants to merge 3 commits into
base: dev/1.21.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/checkstyle.yml

This file was deleted.

27 changes: 25 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.net.URI
plugins {
id("maven-publish")
id("net.neoforged.moddev") version "1.0.19" apply false
id("checkstyle")
id("com.diffplug.spotless") version "6.25.0"
id("idea")
id("com.github.spotbugs") version "6.0.22"
}
Expand Down Expand Up @@ -33,9 +33,32 @@ subprojects {
if (project.name != "ensure_plugin") {
apply(plugin = "maven-publish")
apply(plugin = "net.neoforged.moddev")
apply(plugin = "checkstyle")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "com.github.spotbugs")

spotless {

if (project.name != "endercore") {
ratchetFrom = "origin/dev/1.21.1"
}

encoding("UTF-8")

java {
cleanthat()

eclipse().configFile("$rootDir/config/codeformat/codeformat.xml")

// Revert to spaces, thank you eclipse
indentWithSpaces(4)

importOrder()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}

spotbugs {
reportsDir = project.layout.buildDirectory.dir("reports/spotbugs/")
effort = Effort.MAX
Expand Down
36 changes: 0 additions & 36 deletions config/checkstyle/checkstyle.xml

This file was deleted.

404 changes: 404 additions & 0 deletions config/codeformat/codeformat.xml

Large diffs are not rendered by default.

88 changes: 56 additions & 32 deletions endercore/src/main/java/com/enderio/core/client/RenderUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.enderio.core.client;

import static net.neoforged.neoforge.client.model.IQuadTransformer.COLOR;
import static net.neoforged.neoforge.client.model.IQuadTransformer.STRIDE;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.LightTexture;
Expand All @@ -9,42 +12,70 @@
import net.neoforged.neoforge.client.model.IQuadTransformer;
import org.joml.Vector3f;

import static net.neoforged.neoforge.client.model.IQuadTransformer.COLOR;
import static net.neoforged.neoforge.client.model.IQuadTransformer.STRIDE;

public class RenderUtil {
/**
* Render a face with its texture with local face coordinates.
* Note: Up and Down UVs may not be accurate, please PR with a fix (and test all uses of this method) to modify it.
* todo; is this confusing?
*/
public static void renderFace(Direction face, PoseStack.Pose pose, VertexConsumer consumer, TextureAtlasSprite texture, float x, float y, float z, float w, float h, int color) {
public static void renderFace(Direction face, PoseStack.Pose pose, VertexConsumer consumer,
TextureAtlasSprite texture, float x, float y, float z, float w, float h, int color) {
renderFace(face, pose, consumer, texture, x, y, z, w, h, color, LightTexture.FULL_BRIGHT);
}

public static void renderFace(Direction face, PoseStack.Pose pose, VertexConsumer consumer, TextureAtlasSprite texture, float x, float y, float z, float w, float h, int color, int light) {
// Normals are taken from Direction enum. They are necessary for proper lighting and block breaking textures
public static void renderFace(Direction face, PoseStack.Pose pose, VertexConsumer consumer,
TextureAtlasSprite texture, float x, float y, float z, float w, float h, int color, int light) {
// Normals are taken from Direction enum. They are necessary for proper lighting
// and block breaking textures
switch (face) {
case DOWN -> renderFace(pose, consumer, texture, color, light, x, x + w, 1.0f - z, 1.0f - z, y, y, y + h, y + h, x, x + w, y, y + h, 0, -1, 0);
case UP -> renderFace(pose, consumer, texture, color, light, x, x + w, z, z, y + h, y + h, y, y, x, x + w, y, y + h, 0, 1, 0);
case NORTH -> renderFace(pose, consumer, texture, color, light, x, x + w, y + h, y, z, z, z, z, x, x + w, y, y + h, 0, 0, -1);
case SOUTH -> renderFace(pose, consumer, texture, color, light, x, x + w, y, y + h, 1.0f - z, 1.0f - z, 1.0f - z, 1.0f - z, x + w, x, y + h, y, 0, 0, 1);
case EAST -> renderFace(pose, consumer, texture, color, light, 1.0f - z, 1.0f - z, y + h, y, x, x + w, x + w, x, x, x + w, y, y + h, 1, 0, 0);
case WEST -> renderFace(pose, consumer, texture, color, light, z, z, y, y + h, x, x + w, x + w, x, x + w, x, y + h, y, -1, 0, 0);
default -> throw new IllegalStateException("Unexpected value: " + face);
case DOWN -> renderFace(pose, consumer, texture, color, light, x, x + w, 1.0f - z, 1.0f - z, y, y, y + h, y + h,
x, x + w, y, y + h, 0, -1, 0);
case UP -> renderFace(pose, consumer, texture, color, light, x, x + w, z, z, y + h, y + h, y, y, x, x + w, y,
y + h, 0, 1, 0);
case NORTH -> renderFace(pose, consumer, texture, color, light, x, x + w, y + h, y, z, z, z, z, x, x + w, y,
y + h, 0, 0, -1);
case SOUTH -> renderFace(pose, consumer, texture, color, light, x, x + w, y, y + h, 1.0f - z, 1.0f - z,
1.0f - z, 1.0f - z, x + w, x, y + h, y, 0, 0, 1);
case EAST -> renderFace(pose, consumer, texture, color, light, 1.0f - z, 1.0f - z, y + h, y, x, x + w, x + w, x,
x, x + w, y, y + h, 1, 0, 0);
case WEST -> renderFace(pose, consumer, texture, color, light, z, z, y, y + h, x, x + w, x + w, x, x + w, x,
y + h, y, -1, 0, 0);
default -> throw new IllegalStateException("Unexpected value: " + face);
}
}

private static void renderFace(PoseStack.Pose pose, VertexConsumer consumer, TextureAtlasSprite texture, int color, int light, float x0, float x1, float y0, float y1, float z0, float z1, float z2, float z3, float u0, float u1, float v0, float v1, float normalX, float normalY, float normalZ) {
private static void renderFace(PoseStack.Pose pose, VertexConsumer consumer, TextureAtlasSprite texture, int color,
int light, float x0, float x1, float y0, float y1, float z0, float z1, float z2, float z3, float u0,
float u1, float v0, float v1, float normalX, float normalY, float normalZ) {
float minU = u0 * texture.contents().width() / 16f;
float maxU = u1 * texture.contents().width() / 16f;
float minV = v0 * texture.contents().height() / 16f;
float maxV = v1 * texture.contents().height() / 16f;

consumer.addVertex(pose, x0, y0, z0).setColor(color).setUv(texture.getU(minU), texture.getV(minV)).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x1, y0, z1).setColor(color).setUv(texture.getU(maxU), texture.getV(minV)).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x1, y1, z2).setColor(color).setUv(texture.getU(maxU), texture.getV(maxV)).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x0, y1, z3).setColor(color).setUv(texture.getU(minU), texture.getV(maxV)).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x0, y0, z0)
.setColor(color)
.setUv(texture.getU(minU), texture.getV(minV))
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(light)
.setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x1, y0, z1)
.setColor(color)
.setUv(texture.getU(maxU), texture.getV(minV))
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(light)
.setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x1, y1, z2)
.setColor(color)
.setUv(texture.getU(maxU), texture.getV(maxV))
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(light)
.setNormal(pose, normalX, normalY, normalZ);
consumer.addVertex(pose, x0, y1, z3)
.setColor(color)
.setUv(texture.getU(minU), texture.getV(maxV))
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(light)
.setNormal(pose, normalX, normalY, normalZ);
}

public static float[] unpackVertices(int[] vertices, int vertexIndex, int position, int count) {
Expand All @@ -65,7 +96,7 @@ public static Vector3f getNormalData(int[] vertices, int vertexIndex) {
x = (vertexData & 0x000000FF) / 127f;
y = ((vertexData & 0x0000FF00) >> 8) / 127f;
z = ((vertexData & 0x00FF0000) >> 16) / 127f;
return new Vector3f(x,y,z);
return new Vector3f(x, y, z);
}

/**
Expand All @@ -90,11 +121,8 @@ private static int[] getColorABGR(int[] vertices, int vertexIndex) {
}

private static int[] multiplyColor(int[] abgr1, int[] abgr2) {
return new int[] {
abgr1[0]*abgr2[0]/255,
abgr1[1]*abgr2[1]/255,
abgr1[2]*abgr2[2]/255,
abgr1[3]*abgr2[3]/255};
return new int[] { abgr1[0] * abgr2[0] / 255, abgr1[1] * abgr2[1] / 255, abgr1[2] * abgr2[2] / 255,
abgr1[3] * abgr2[3] / 255 };
}

public static void multiplyColor(int[] vertices, int vertexIndex, int rgbBlockColor) {
Expand All @@ -110,11 +138,9 @@ public static void multiplyColor(int[] vertices, int vertexIndex, int rgbBlockCo

public static void putColorABGR(int[] vertices, int vertexIndex, int[] abgr) {
int offset = vertexIndex * STRIDE + COLOR;
vertices[offset] = (abgr[0] << 24) |
(abgr[1] << 16) |
(abgr[2] << 8) |
abgr[3];
vertices[offset] = (abgr[0] << 24) | (abgr[1] << 16) | (abgr[2] << 8) | abgr[3];
}

public static void putColorARGB(int[] vertices, int vertexIndex, int argb) {
int[] blockColorABGR = new int[4];
blockColorABGR[0] = 0xFF | (argb >> 24 & 0xFF);
Expand All @@ -123,9 +149,7 @@ public static void putColorARGB(int[] vertices, int vertexIndex, int argb) {
blockColorABGR[1] = argb & 0xFF;

int offset = vertexIndex * STRIDE + COLOR;
vertices[offset] = (blockColorABGR[0] << 24) |
(blockColorABGR[1] << 16) |
(blockColorABGR[2] << 8) |
blockColorABGR[3];
vertices[offset] = (blockColorABGR[0] << 24) | (blockColorABGR[1] << 16) | (blockColorABGR[2] << 8)
| blockColorABGR[3];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.enderio.core.client.gui.screen;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
Expand All @@ -13,13 +17,9 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import org.joml.Vector2i;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Deprecated(forRemoval = true, since = "7.0")
public abstract class EIOScreen<T extends AbstractContainerMenu> extends AbstractContainerScreen<T> implements EnderScreen {
public abstract class EIOScreen<T extends AbstractContainerMenu> extends AbstractContainerScreen<T>
implements EnderScreen {

private final boolean renderLabels;
private final List<EditBox> editBoxList = new ArrayList<>();
Expand Down Expand Up @@ -51,9 +51,10 @@ public void resize(Minecraft pMinecraft, int pWidth, int pHeight) {

@Override
public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) {
/*if (menu instanceof SyncedMenu<?> syncedMenu && syncedMenu.getBlockEntity() == null) {
return;
}*/
/*
* if (menu instanceof SyncedMenu<?> syncedMenu && syncedMenu.getBlockEntity()
* == null) { return; }
*/

super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks);
this.renderTooltip(guiGraphics, pMouseX, pMouseY);
Expand All @@ -66,7 +67,7 @@ protected void renderBg(GuiGraphics guiGraphics, float pPartialTick, int pMouseX

@Override
public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {
if (pKeyCode == 256) { //ESC has priority
if (pKeyCode == 256) { // ESC has priority
Minecraft.getInstance().player.closeContainer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -22,10 +25,6 @@
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public abstract class EnderContainerScreen<T extends AbstractContainerMenu> extends AbstractContainerScreen<T> {

private static final int ITEM_RENDER_Z = 400;
Expand All @@ -48,7 +47,8 @@ protected void centerAlignTitleLabelX() {

@Override
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
if (menu instanceof BaseBlockEntityMenu<?> baseBlockEntityMenu && baseBlockEntityMenu.getBlockEntity() == null) {
if (menu instanceof BaseBlockEntityMenu<?> baseBlockEntityMenu
&& baseBlockEntityMenu.getBlockEntity() == null) {
return;
}

Expand All @@ -74,7 +74,8 @@ protected void renderLabels(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY)

for (var overlay : overlayRenderables.get(layer)) {
if (!(overlay instanceof AbstractWidget widget) || widget.isActive()) {
overlay.render(pGuiGraphics, pMouseX, pMouseY, Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false));
overlay.render(pGuiGraphics, pMouseX, pMouseY,
Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false));

if (overlay instanceof BaseOverlay baseOverlay) {
zOffset += baseOverlay.getAdditionalZOffset();
Expand Down Expand Up @@ -114,7 +115,8 @@ protected void renderTooltip(GuiGraphics pGuiGraphics, int pX, int pY) {
}

@Override
protected void renderSlotContents(GuiGraphics guiGraphics, ItemStack itemstack, Slot slot, @Nullable String countString) {
protected void renderSlotContents(GuiGraphics guiGraphics, ItemStack itemstack, Slot slot,
@Nullable String countString) {
super.renderSlotContents(guiGraphics, itemstack, slot, countString);

if (slot instanceof SlotWithOverlay slotWithOverlay) {
Expand Down Expand Up @@ -158,7 +160,8 @@ protected void clearWidgets() {
@Override
public void resize(Minecraft pMinecraft, int pWidth, int pHeight) {
// Gather state to persist
Map<String, Object> valuesBeforeResize = stateRestoringWidgets.entrySet().stream()
Map<String, Object> valuesBeforeResize = stateRestoringWidgets.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getValueForRestore()));

super.resize(pMinecraft, pWidth, pHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public interface StateRestoringWidget {
Object getValueForRestore();

void restoreValue(Object value);
}
Loading
Loading