Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/format-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Runs formatting requirements
name: Java Formatting

on:
push:
branches: ['1.20.1', '1.21.1']
paths: ['src/main/java/**', 'src/test/**']
pull_request:
paths: ['**']

concurrency:
group: formatting-${{ github.ref }}
cancel-in-progress: true

jobs:
formatting:
name: Formatting
runs-on: ubuntu-latest
permissions:
pull-requests: read
steps:
- name: Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # do a full checkout instead of a shallow clone of HEAD so spotless's ratchetFrom works
- name: Check Path Filter
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
code:
- 'src/main/java/**'
- 'src/test/**'
- name: Setup Java
if: steps.filter.outputs.code == 'true'
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
- name: Setup Gradle
if: steps.filter.outputs.code == 'true'
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: true
- name: Run Spotless Formatting Check with Gradle
if: steps.filter.outputs.code == 'true'
run: chmod +x ./gradlew && ./gradlew spotlessCheck --warning-mode all
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'maven-publish'
alias libs.plugins.modDevGradle
//alias libs.plugins.shadow
alias libs.plugins.editorconfig
alias libs.plugins.spotless
alias libs.plugins.lombok
}

Expand Down Expand Up @@ -66,7 +66,7 @@ apply from: "$rootDir/gradle/scripts/repositories.gradle"
apply from: "$rootDir/dependencies.gradle"
apply from: "$rootDir/gradle/scripts/resources.gradle"
apply from: "$rootDir/gradle/scripts/publishing.gradle"
apply from: "$rootDir/gradle/scripts/formatting.gradle"
apply from: "$rootDir/gradle/scripts/spotless.gradle"
apply from: "$rootDir/gradle/scripts/docs.gradle"


Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ neoForge = "21.1.265"
loader = "4"
parchment = "2024.11.17" # https://parchmentmc.org/docs/getting-started
shadow = "8.3.5"
editorconfig = "0.1.0"
spotless = "8.1.0"
modDevGradle = "2.0.86"
lombok = "8.14"

Expand All @@ -27,5 +27,5 @@ mcdevAnnotations = { module = "com.demonwav.mcdev:annotations", version.ref = "m
[plugins]
modDevGradle = { id = "net.neoforged.moddev", version.ref = "modDevGradle" }
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
editorconfig = { id = "org.ec4j.editorconfig", version.ref = "editorconfig" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
lombok = { id = "io.freefair.lombok", version.ref = "lombok" }
6 changes: 0 additions & 6 deletions gradle/scripts/formatting.gradle

This file was deleted.

27 changes: 27 additions & 0 deletions gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Spotless auto-formatter
// See https://github.com/diffplug/spotless/tree/main/plugin-gradle
// Can be locally toggled via spotless:off/spotless:on comments
spotless {
encoding 'UTF-8'
ratchetFrom 'origin/1.21.1'

format 'misc', {
target '.gitignore'

trimTrailingWhitespace()
leadingTabsToSpaces()
endWithNewline()
}
java {
target 'src/main/java/**/*.java', 'src/test/java/**/*.java'

def orderFile = file("$rootDir/spotless/spotless.importorder")
def formatFile = file("$rootDir/spotless/spotless.eclipseformat.xml")

toggleOffOn()
importOrderFile(orderFile)
removeUnusedImports('cleanthat-javaparser-unnecessaryimport')
endWithNewline()
eclipse('4.36').configFile(formatFile)
}
}
400 changes: 400 additions & 0 deletions spotless/spotless.eclipseformat.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions spotless/spotless.importorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Organize Import Order
0=brachy
1=net
2=
3=java
4=javax
5=\#
17 changes: 9 additions & 8 deletions src/main/java/brachy/modularui/ModularUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import com.mojang.brigadier.Command;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
Expand All @@ -32,6 +31,7 @@
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
import net.neoforged.neoforge.server.ServerLifecycleHooks;

import com.mojang.brigadier.Command;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -122,7 +122,7 @@ public static boolean isClientThread() {
/**
* @return if the game is the <strong>PHYSICAL</strong> client, e.g. not a dedicated server.
* @apiNote Do not use this to check if you're currently on the server thread for side-specific actions!
* It does <strong>NOT</strong> work for that. Use {@link #isClientThread()} instead.
* It does <strong>NOT</strong> work for that. Use {@link #isClientThread()} instead.
* @see #isClientThread()
*/
public static boolean isClientSide() {
Expand All @@ -133,7 +133,7 @@ public static boolean isClientSide() {
* This check isn't the same for client and server!
*
* @return if it's safe to access the current instance {@link net.minecraft.world.level.Level Level} on client or if
* it's safe to access any level on server.
* it's safe to access any level on server.
*/
public static boolean canGetServerLevel() {
if (isClientSide()) {
Expand Down Expand Up @@ -173,22 +173,23 @@ private void onRegisterCommand(RegisterCommandsEvent event) {
.executes(ctx -> {
ThemeManager.reload();
// TODO translations for this
ctx.getSource().sendSuccess(() -> Component.literal("ModularUI Themes reloaded").withStyle(Text.GREEN), true);
ctx.getSource().sendSuccess(
() -> Component.literal("ModularUI Themes reloaded").withStyle(Text.GREEN), true);
return Command.SINGLE_SUCCESS;
}));
event.getDispatcher().register(command);
}

public enum Mods {

//BLUR(ModIds.BLUR),
//BOGOSORTER(ModIds.BOGOSORTER),
// BLUR(ModIds.BLUR),
// BOGOSORTER(ModIds.BOGOSORTER),
CURIOS(ModIds.CURIOS),
EMI(ModIds.EMI),
JEI(ModIds.JEI),
REI(ModIds.REI),
//MODNAMETOOLTIP(ModIds.MODNAMETOOLTIP),
//NEA(ModIds.NEA),
// MODNAMETOOLTIP(ModIds.MODNAMETOOLTIP),
// NEA(ModIds.NEA),
SODIUM(ModIds.SODIUM),
IRIS(ModIds.IRIS);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/brachy/modularui/ModularUIConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package brachy.modularui;

import brachy.modularui.screen.RichTooltip;
import brachy.modularui.utils.Color;

import net.minecraft.ChatFormatting;
import net.neoforged.neoforge.common.ModConfigSpec;
Expand All @@ -27,7 +26,8 @@ public class ModularUIConfig {
.translation("config.modularui.defaultScrollSpeed")
.defineInRange("defaultScrollSpeed", 30, 1, 100);
public static final BooleanValue SMOOTH_PROGRESS_BARS = BUILDER
.comment("If progress bars should step in texture pixels or screen pixels. (Screen pixels are way smaller and therefore smoother)")
.comment(
"If progress bars should step in texture pixels or screen pixels. (Screen pixels are way smaller and therefore smoother)")
.translation("config.modularui.smoothProgressBars")
.define("smoothProgressBars", false);
public static final IntValue ANIMATION_TIME = BUILDER
Expand All @@ -40,7 +40,8 @@ public class ModularUIConfig {
.translation("config.modularui.tooltipPos")
.defineEnum("tooltipPos", RichTooltip.Pos.NEXT_TO_MOUSE);
public static final BooleanValue ESC_RESTORES_LAST_TEXT = BUILDER
.comment("If true, pressing ESC key in the text field will restore the last text instead of confirming current one.")
.comment(
"If true, pressing ESC key in the text field will restore the last text instead of confirming current one.")
.translation("config.modularui.escRestoresLastText")
.define("escRestoresLastText", false);
public static final BooleanValue USE_DARK_THEME_BY_DEFAULT = BUILDER
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/brachy/modularui/ModularUIMenuTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

public class ModularUIMenuTypes {

private static final DeferredRegister<MenuType<?>> MENU_TYPES = DeferredRegister.create(Registries.MENU, ModularUI.MOD_ID);
private static final DeferredRegister<MenuType<?>> MENU_TYPES = DeferredRegister.create(Registries.MENU,
ModularUI.MOD_ID);

public static final DeferredHolder<MenuType<?>, MenuType<ModularContainerMenu>> MODULAR_CONTAINER = MENU_TYPES.register(
"modular",
() -> IMenuTypeExtension.create(ModularContainerMenu::new));
public static final DeferredHolder<MenuType<?>, MenuType<ModularContainerMenu>> MODULAR_CONTAINER = MENU_TYPES
.register(
"modular",
() -> IMenuTypeExtension.create(ModularContainerMenu::new));

public static void register(IEventBus modBus) {
MENU_TYPES.register(modBus);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/brachy/modularui/api/IPanelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* With the difference, that the method from this interface also works on server
* side.
* </p>
* Synced panels must be created with {@link PanelSyncManager#syncedPanel(String, boolean, PanelSyncHandler.IPanelBuilder)}.
* Synced panels must be created with
* {@link PanelSyncManager#syncedPanel(String, boolean, PanelSyncHandler.IPanelBuilder)}.
* If the panel does not contain any synced widgets, a simple panel handler using
* {@link #simple(ModularPanel, SecondaryPanel.IPanelBuilder, boolean)}
* is likely what you need.
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/brachy/modularui/api/ITheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Encoder;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

import net.minecraft.util.ExtraCodecs;

import org.jetbrains.annotations.UnmodifiableView;

import java.util.Collection;
Expand All @@ -39,6 +35,7 @@ public interface ITheme {
ITheme::getId);

Encoder<ITheme> ENCODER = new Encoder<>() {

@Override
public <T> DataResult<T> encode(ITheme input, DynamicOps<T> ops, T prefix) {
var mapBuilder = ops.mapBuilder();
Expand All @@ -49,7 +46,8 @@ public <T> DataResult<T> encode(ITheme input, DynamicOps<T> ops, T prefix) {
for (WidgetThemeEntry<?> entry : input.getWidgetThemeEntries()) {
if (entry.key() == IThemeApi.FALLBACK) continue;
var set = encodedThemes.computeIfAbsent(entry.key().getName(), k -> new ObjectOpenHashSet<>());
if (entry.key().isSubWidgetTheme() && set.contains(entry.theme()) && set.contains(entry.hoverTheme())) continue;
if (entry.key().isSubWidgetTheme() && set.contains(entry.theme()) && set.contains(entry.hoverTheme()))
continue;
entry.encode(ops, mapBuilder, false);
set.add(entry.theme());
set.add(entry.hoverTheme());
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/brachy/modularui/api/IThemeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import brachy.modularui.utils.serialization.json.JsonBuilder;

import com.mojang.serialization.Codec;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -191,7 +190,8 @@ default void registerTheme(ThemeBuilder<?> themeBuilder) {
* @param defaultTheme default theme if no theme was found
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
default ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme, @Nullable String fallbackTheme) {
default ITheme getThemeForScreen(String owner, String name, @Nullable String defaultTheme,
@Nullable String fallbackTheme) {
return getThemeForScreen(owner, name, null, defaultTheme, fallbackTheme);
}

Expand All @@ -204,7 +204,8 @@ default ITheme getThemeForScreen(String owner, String name, @Nullable String def
* @param defaultTheme default theme if no theme was found
* @return the registered theme for the given screen or the given default theme or {@link #getDefaultTheme()}
*/
ITheme getThemeForScreen(String owner, String name, @Nullable String panel, @Nullable String defaultTheme, @Nullable String fallbackTheme);
ITheme getThemeForScreen(String owner, String name, @Nullable String panel, @Nullable String defaultTheme,
@Nullable String fallbackTheme);

/**
* Gets the appropriate theme for a specific panel.
Expand All @@ -215,7 +216,8 @@ default ITheme getThemeForScreen(String owner, String name, @Nullable String def
*/
default ITheme getThemeForScreen(ModularPanel<?> panel, @Nullable String defaultTheme) {
ModularScreen screen = panel.getScreen();
return getThemeForScreen(screen.getOwner(), screen.getName(), panel.getName(), defaultTheme, screen.getThemeOverride());
return getThemeForScreen(screen.getOwner(), screen.getName(), panel.getName(), defaultTheme,
screen.getThemeOverride());
}

/**
Expand Down Expand Up @@ -250,7 +252,8 @@ default void registerThemeForScreen(String owner, String name, String theme) {

@Deprecated
<T extends WidgetTheme> WidgetThemeKey<T> registerWidgetTheme(String id, T defaultTheme, T defaultHoverTheme,
WidgetThemeMerger<T> merger, WidgetThemeCodec<T> codec);
WidgetThemeMerger<T> merger,
WidgetThemeCodec<T> codec);

default <T extends WidgetTheme> WidgetThemeKeyBuilder<T> widgetThemeKeyBuilder(String id, Class<T> type) {
return new WidgetThemeKeyBuilder<>(id, type);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/brachy/modularui/api/ITreeNode.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package brachy.modularui.api;

import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;

import java.util.List;
import java.util.function.Predicate;
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/brachy/modularui/api/drawable/IDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import brachy.modularui.widget.Widget;
import brachy.modularui.widget.sizer.Area;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.MapCodec;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import com.google.gson.JsonElement;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.MapCodec;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -45,6 +45,7 @@ static IDrawable of(IDrawable... drawables) {
* An empty drawable. Does nothing.
*/
IDrawable EMPTY = new IDrawable() {

@Override
public void draw(GuiContext context, int x, int y, int width, int height, WidgetTheme widgetTheme) {}

Expand All @@ -58,6 +59,7 @@ public String toString() {
* An empty drawable used to mark hover textures as "should not be used"!
*/
IDrawable NONE = new IDrawable() {

@Override
public void draw(GuiContext context, int x, int y, int width, int height, WidgetTheme widgetTheme) {}

Expand All @@ -68,7 +70,8 @@ public String toString() {
};

CodecRegistry<IDrawable> CODECS = new CodecRegistry<>();
MapCodec<IDrawable> CODEC_DISPATCH = CodecUtil.dispatchNullable(Codec.STRING, IDrawable::getTypeName, CODECS::getNullable);
MapCodec<IDrawable> CODEC_DISPATCH = CodecUtil.dispatchNullable(Codec.STRING, IDrawable::getTypeName,
CODECS::getNullable);
Codec<IDrawable> CODEC_EMPTY_NONE = Codec.STRING.flatXmap(s -> {
if (s == null || s.equals("empty") || s.equals("null")) return DataResult.success(EMPTY);
if (s.equals("none")) return DataResult.success(NONE);
Expand Down Expand Up @@ -168,7 +171,8 @@ default void drawAtZero(GuiContext context, Area area, WidgetTheme widgetTheme)
*/
@OnlyIn(Dist.CLIENT)
default void drawAtZeroPadded(GuiContext context, Area area, WidgetTheme widgetTheme) {
draw(context, area.getPadding().left(), area.getPadding().top(), area.paddedWidth(), area.paddedHeight(), widgetTheme);
draw(context, area.getPadding().left(), area.getPadding().top(), area.paddedWidth(), area.paddedHeight(),
widgetTheme);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/brachy/modularui/api/drawable/ITextLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public interface ITextLine {

int getHeight(Font font);

void draw(GuiContext context, Font font, float x, float y, int color, boolean shadow, int availableWidth, int availableHeight);
void draw(GuiContext context, Font font, float x, float y, int color, boolean shadow, int availableWidth,
int availableHeight);

Object getHoveringElement(Font font, int x, int y);
}
Loading
Loading