Skip to content

Commit

Permalink
chore: spotlessApply for EnderCore
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Sep 30, 2024
1 parent 9055406 commit 7b19580
Show file tree
Hide file tree
Showing 39 changed files with 312 additions and 304 deletions.
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.enderio.core.client.gui.screen.EnderScreen;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -13,12 +18,6 @@
import net.minecraft.resources.ResourceLocation;
import org.joml.Vector2i;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

public abstract class BaseEnumPickerWidget<T extends Enum<T>> extends EnderButton {

private final Class<T> clazz;
Expand All @@ -39,7 +38,8 @@ public abstract class BaseEnumPickerWidget<T extends Enum<T>> extends EnderButto

private final Component optionName;

public BaseEnumPickerWidget(int pX, int pY, int width, int height, Class<T> clazz, Supplier<T> getter, Consumer<T> setter, Component optionName) {
public BaseEnumPickerWidget(int pX, int pY, int width, int height, Class<T> clazz, Supplier<T> getter,
Consumer<T> setter, Component optionName) {
super(pX, pY, width, height, Component.empty());

this.clazz = clazz;
Expand All @@ -52,9 +52,8 @@ public BaseEnumPickerWidget(int pX, int pY, int width, int height, Class<T> claz
Vector2i elementDistance = new Vector2i(width, height).add(SPACE_BETWEEN_ELEMENTS, SPACE_BETWEEN_ELEMENTS);
for (int i = 0; i < values.length; i++) {
T value = values[i];
Vector2i subWidgetPos = new Vector2i(
pos.x() + getColumn(i) * elementDistance.x() + pX,
pos.y() + getRow(i) * elementDistance.y() + pY);
Vector2i subWidgetPos = new Vector2i(pos.x() + getColumn(i) * elementDistance.x() + pX,
pos.y() + getRow(i) * elementDistance.y() + pY);
SelectionWidget widget = new SelectionWidget(subWidgetPos, width + 2, height + 2, value);

Component tooltip = getValueTooltip(value);
Expand Down Expand Up @@ -83,6 +82,7 @@ public BaseEnumPickerWidget(int pX, int pY, int width, int height, Class<T> claz

@Nullable
public abstract Component getValueTooltip(T value);

public abstract ResourceLocation getValueIcon(T value);

public T[] getValues() {
Expand Down Expand Up @@ -138,7 +138,8 @@ private static int getRow(int index) {
return index / ELEMENTS_IN_ROW;
}

@Nullable private T tooltipDisplayCache;
@Nullable
private T tooltipDisplayCache;

@Override
public void renderButtonFace(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
Expand All @@ -161,7 +162,8 @@ private void updateTooltip(T value) {
}

@Override
public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {}
public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {
}

public boolean isExpanded() {
return Minecraft.getInstance().screen instanceof SelectionScreen;
Expand Down Expand Up @@ -197,13 +199,14 @@ public void renderBackground(GuiGraphics guiGraphics, int pMouseX, int pMouseY,

@Override
public void renderTransparentBackground(GuiGraphics pGuiGraphics) {
//Don't make background dark
// Don't make background dark
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!(parentWidget.expandTopLeft.x() <= mouseX && parentWidget.expandBottomRight.x() >= mouseX && parentWidget.expandTopLeft.y() <= mouseY && parentWidget.expandBottomRight.y() >= mouseY
|| parentWidget.isMouseOver(mouseX, mouseY))) {
if (!(parentWidget.expandTopLeft.x() <= mouseX && parentWidget.expandBottomRight.x() >= mouseX
&& parentWidget.expandTopLeft.y() <= mouseY && parentWidget.expandBottomRight.y() >= mouseY
|| parentWidget.isMouseOver(mouseX, mouseY))) {
Minecraft.getInstance().popGuiLayer();
}

Expand Down Expand Up @@ -241,7 +244,8 @@ public void onPress() {
}

@Override
public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {}
public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {
}

@Override
public void renderButtonFace(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
// The same as AbstractButton but does not show the white outline when focussed.
public abstract class EnderButton extends AbstractWidget {
protected static final WidgetSprites SPRITES = new WidgetSprites(
ResourceLocation.withDefaultNamespace("widget/button"),
ResourceLocation.withDefaultNamespace("widget/button_disabled"),
ResourceLocation.withDefaultNamespace("widget/button_highlighted")
);
ResourceLocation.withDefaultNamespace("widget/button"),
ResourceLocation.withDefaultNamespace("widget/button_disabled"),
ResourceLocation.withDefaultNamespace("widget/button_highlighted"));

public EnderButton(int pX, int pY, int pWidth, int pHeight, Component pMessage) {
super(pX, pY, pWidth, pHeight, pMessage);
Expand All @@ -26,7 +25,8 @@ protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY,
pGuiGraphics.setColor(1.0F, 1.0F, 1.0F, this.alpha);
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
pGuiGraphics.blitSprite(SPRITES.get(this.active, this.isHovered()), this.getX(), this.getY(), this.getWidth(), this.getHeight());
pGuiGraphics.blitSprite(SPRITES.get(this.active, this.isHovered()), this.getX(), this.getY(), this.getWidth(),
this.getHeight());
pGuiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
renderButtonFace(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
}
Expand Down
Loading

0 comments on commit 7b19580

Please sign in to comment.