diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f2384ac..7066b63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,17 +15,22 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Setup JDK + - name: Setup JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 - - name: Build with Gradle Wrapper - run: chmod u+x gradlew && ./gradlew build + # This is needed to be able to run ./gradlew below + # You can run `git update-index --chmod +x gradlew` then remove this step. + - name: Make Gradle wrapper executable + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew build - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index ae1304a..868d481 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,8 @@ build # other eclipse run +runs run-data src/generated/resources/.cache/ + +repo \ No newline at end of file diff --git a/README.md b/README.md index 1183735..da25663 100644 --- a/README.md +++ b/README.md @@ -22,5 +22,4 @@ ## 📜 License This project is licensed under the MIT License. It also incorporates some source code from Applied Energistics 2, which is licensed under LGPL-3.0-or-later. -Many thanks to TeamAppliedEnergistics for developing such a wonderful mod. - +Many thanks to TeamAppliedEnergistics for developing such a wonderful mod. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5c6dfed..1e0edd1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,158 +1,94 @@ -buildscript { - repositories { - // These repositories are only for Gradle plugins, put any other repositories in the repository block further below - maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } - mavenCentral() - } - dependencies { - classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' - } -} - plugins { - id 'eclipse' - id 'idea' + id 'java-library' id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'net.neoforged.gradle.userdev' version '7.1.4' } -apply plugin: 'org.spongepowered.mixin' +tasks.named('wrapper', Wrapper).configure { + distributionType = Wrapper.DistributionType.BIN +} version = mod_version group = mod_group_id -base { - archivesName = mod_id +repositories { + mavenCentral() } -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" -minecraft { - mappings channel: mapping_channel, version: mapping_version - copyIdeResources = true - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - runs { - configureEach { - workingDirectory project.file('run') - property 'forge.logging.markers', 'REGISTRIES' - property 'forge.logging.console.level', 'debug' - - mods { - "${mod_id}" { - source sourceSets.main - } - } - - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" - } - - client { - property 'forge.enabledGameTestNamespaces', mod_id - } - - server { - property 'forge.enabledGameTestNamespaces', mod_id - args '--nogui' - } - - gameTestServer { - property 'forge.enabledGameTestNamespaces', mod_id - } - - data { - workingDirectory project.file('run-data') - args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') - } - } +base { + archivesName = mod_id } -sourceSets.main.resources { srcDir 'src/generated/resources' } +java.toolchain.languageVersion = JavaLanguageVersion.of(21) -repositories { -// flatDir { -// dir 'libs' -// } - - exclusiveContent { - forRepository { - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - } - } - forRepositories(fg.repository) - filter { - includeGroup "maven.modrinth" - } +runs { + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + systemProperty 'forge.logging.console.level', 'debug' + modSource project.sourceSets.main } - maven { - url "https://cursemaven.com" - content { - includeGroup "curse.maven" - } + client { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } -} -dependencies { - //noinspection VulnerableLibrariesLocal - minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' + server { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + argument '--nogui' + } - implementation fg.deobf("maven.modrinth:guideme:$guideme_version") - implementation fg.deobf("maven.modrinth:ae2:$ae2_version") - runtimeOnly fg.deobf("maven.modrinth:refined-storage:$refined_storage_version") + gameTestServer { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + } - runtimeOnly fg.deobf("curse.maven:glodium-957920:5226922") - runtimeOnly fg.deobf("curse.maven:applied-flux-965012:6755986") + data { + arguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() + } +} - runtimeOnly fg.deobf("curse.maven:mekanism-268560:6552911") - runtimeOnly fg.deobf("curse.maven:applied-mekanistics-574300:4842281") +sourceSets.main.resources { srcDir 'src/generated/resources' } - runtimeOnly fg.deobf("curse.maven:catalogue-459701:4766090") - runtimeOnly fg.deobf("curse.maven:configured-457570:5180900") +configurations { + runtimeClasspath.extendsFrom localRuntime } -mixin { - add sourceSets.main, "${mod_id}.refmap.json" - config "${mod_id}.mixins.json" +dependencies { + implementation "net.neoforged:neoforge:${neo_version}" + implementation "org.appliedenergistics:appliedenergistics2:${ae2_version}" } -tasks.named('processResources', ProcessResources).configure { +tasks.withType(ProcessResources).configureEach { var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, mod_url: mod_url, - ae2_version_range: ae2_version_range + minecraft_version : minecraft_version, + minecraft_version_range: minecraft_version_range, + neo_version : neo_version, + loader_version_range : loader_version_range, + mod_id : mod_id, + mod_name : mod_name, + mod_license : mod_license, + mod_version : mod_version, + mod_authors : mod_authors, + mod_description : mod_description, + ae2_version_range : ae2_version_range ] inputs.properties replaceProperties - filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { - expand replaceProperties + [project: project] + filesMatching(['META-INF/neoforge.mods.toml']) { + expand replaceProperties } } tasks.named('jar', Jar).configure { - manifest { - attributes([ - 'Specification-Title' : mod_id, - 'Specification-Vendor' : mod_authors, - 'Specification-Version' : '1', - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.jar.archiveVersion, - 'Implementation-Vendor' : mod_authors, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) - } - finalizedBy 'reobfJar' - archiveFileName = "${project.archivesBaseName}-forge-${minecraft_version}-v${project.version}.jar" + archiveFileName = "${mod_id}-neo-${minecraft_version}-v${project.version}.jar" } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } + +idea { + module { + downloadSources = true + downloadJavadoc = true + } +} diff --git a/gradle.properties b/gradle.properties index ac77a9d..840ec4b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,16 @@ -org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false +org.gradle.jvmargs=-Xmx1G +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.configuration-cache=false -## Environment Properties -minecraft_version=1.20.1 -minecraft_version_range=[1.20.1,1.21) -forge_version=47.4.0 -forge_version_range=[47,) -loader_version_range=[47,) -mapping_channel=official -mapping_version=1.20.1 +neogradle.subsystems.parchment.minecraftVersion=1.21.1 +neogradle.subsystems.parchment.mappingsVersion=2024.11.17 +minecraft_version=1.21.1 +minecraft_version_range=[1.21.1] +neo_version=21.1.215 +loader_version_range=[1,) -## Mod Properties -# [a-z][a-z0-9_]{1,63} mod_id=appliedsorting mod_name=Applied Sorting mod_license=MIT and LGPL-3.0-or-later (see NOTICE file for details) @@ -19,10 +18,6 @@ mod_version=1.0.0 mod_group_id=io.github.meatwo310.appliedsorting mod_authors=Meatwo310 mod_description=Enhances the AE2 terminal with configurable ID-based sorting. -mod_url=https://github.com/Meatwo310/applied-sorting/ -## Dependency Properties -ae2_version=Zfyso1sP -ae2_version_range=[15.4.0,) -guideme_version=mfDRKud3 -refined_storage_version=ZITLFjjf +ae2_version=19.2.17 +ae2_version_range=[19,) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a7..f8e1ee3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2617362..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 index aeb74cb..adff685 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,7 +85,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -111,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -130,10 +132,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -141,7 +146,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -149,7 +154,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -166,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -198,16 +202,15 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,22 +59,21 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 0077fa7..3e63a5f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,12 +2,11 @@ pluginManagement { repositories { gradlePluginPortal() maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' + url = 'https://maven.neoforged.net/releases' } } } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' } diff --git a/src/main/java/io/github/meatwo310/appliedsorting/AppliedSorting.java b/src/main/java/io/github/meatwo310/appliedsorting/AppliedSorting.java index 4829ab3..d27046d 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/AppliedSorting.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/AppliedSorting.java @@ -1,9 +1,10 @@ package io.github.meatwo310.appliedsorting; import io.github.meatwo310.appliedsorting.config.ClientConfig; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; import java.util.List; @@ -11,8 +12,8 @@ public class AppliedSorting { public static final String MODID = "appliedsorting"; - public AppliedSorting(FMLJavaModLoadingContext context) { - context.registerConfig(ModConfig.Type.CLIENT, ClientConfig.SPEC); + public AppliedSorting(ModContainer container, IEventBus eventBus) { + container.registerConfig(ModConfig.Type.CLIENT, ClientConfig.SPEC); } public static int indexOfOr(List list, E element, int or) { diff --git a/src/main/java/io/github/meatwo310/appliedsorting/ae2/ConfigToggleButton.java b/src/main/java/io/github/meatwo310/appliedsorting/ae2/ConfigToggleButton.java index 42b2c39..111ca15 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/ae2/ConfigToggleButton.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/ae2/ConfigToggleButton.java @@ -15,10 +15,12 @@ * You should have received a copy of the GNU Lesser General Public License * along with Applied Energistics 2. If not, see . */ + /* * MODFICATIONS: * - Meatwo310: Changed package/class name and texture location. * - Meatwo310: Heavily modified to use ForgeConfigSpec.EnumValue and support dynamic icons/tooltips. + * - Mochi_753: Change `ForgeConfigSpec` to `ModConfigSpec`. * See NOTICE file for license details. */ @@ -38,42 +40,33 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; -import net.minecraftforge.common.ForgeConfigSpec; -import org.jetbrains.annotations.Nullable; +import net.neoforged.neoforge.common.ModConfigSpec; +import javax.annotation.Nullable; import java.util.*; import java.util.function.Predicate; public class ConfigToggleButton> extends CustomIconButton { private static Map, ButtonAppearance> appearances; - private final ForgeConfigSpec.EnumValue configSpec; + private final ModConfigSpec.EnumValue configSpec; private final IHandler> onPress; private final EnumSet validValues; private T currentValue; - @FunctionalInterface - public interface IHandler> { - void handle(T button, boolean backwards); - } - - public ConfigToggleButton(ForgeConfigSpec.EnumValue configSpec, IHandler> onPress) { + public ConfigToggleButton(ModConfigSpec.EnumValue configSpec, IHandler> onPress) { this(configSpec, configSpec.get(), onPress); } - public ConfigToggleButton(ForgeConfigSpec.EnumValue configSpec, T val, - IHandler> onPress) { + public ConfigToggleButton(ModConfigSpec.EnumValue configSpec, T val, IHandler> onPress) { this(configSpec, val, t -> true, onPress); } - public ConfigToggleButton(ForgeConfigSpec.EnumValue configSpec, T val, Predicate isValidValue, - IHandler> onPress) { + public ConfigToggleButton(ModConfigSpec.EnumValue configSpec, T val, Predicate isValidValue, IHandler> onPress) { super(ConfigToggleButton::onPress); this.onPress = onPress; - // Build a list of values (in order) that are valid w.r.t. the given predicate EnumSet validValues = EnumSet.allOf(val.getDeclaringClass()); validValues.removeIf(isValidValue.negate()); -// validValues.removeIf(s -> !configSpec.getValues().contains(s)); this.validValues = validValues; this.configSpec = configSpec; @@ -120,52 +113,42 @@ public ConfigToggleButton(ForgeConfigSpec.EnumValue configSpec, T val, Predic } } - private static void onPress(Button btn) { - if (btn instanceof ConfigToggleButton) { - ((ConfigToggleButton) btn).triggerPress(); + private static void onPress(Button button) { + if (button instanceof ConfigToggleButton) { + ((ConfigToggleButton) button).triggerPress(); } } - private void triggerPress() { - boolean backwards = false; - // This isn't great, but we don't get any information about right-clicks - // otherwise - Screen currentScreen = Minecraft.getInstance().screen; - if (currentScreen instanceof AEBaseScreen) { - backwards = ((AEBaseScreen) currentScreen).isHandlingRightClick(); - } - onPress.handle(this, backwards); - } - - private static > void registerApp(Blitter blitter, ForgeConfigSpec.EnumValue setting, T val, - LocalizationEnum title, Component... tooltipLines) { + private static > void registerApp(Blitter blitter, ModConfigSpec.EnumValue setting, T val, LocalizationEnum title, Component... tooltipLines) { var lines = new ArrayList(); lines.add(title.text()); Collections.addAll(lines, tooltipLines); - appearances.put( - new EnumPair<>(setting, val), - new ButtonAppearance(blitter, null, lines)); + appearances.put(new EnumPair<>(setting, val), new ButtonAppearance(blitter, null, lines)); } - private static > void registerApp(ItemLike item, ForgeConfigSpec.EnumValue setting, T val, - LocalizationEnum title, Component... tooltipLines) { + private static > void registerApp(ItemLike item, ModConfigSpec.EnumValue setting, T val, LocalizationEnum title, Component... tooltipLines) { var lines = new ArrayList(); lines.add(title.text()); Collections.addAll(lines, tooltipLines); - appearances.put( - new EnumPair<>(setting, val), - new ButtonAppearance(null, item.asItem(), lines)); + appearances.put(new EnumPair<>(setting, val), new ButtonAppearance(null, item.asItem(), lines)); } - private static > void registerApp(Blitter blitter, ForgeConfigSpec.EnumValue setting, T val, - LocalizationEnum title, LocalizationEnum hint) { + private static > void registerApp(Blitter blitter, ModConfigSpec.EnumValue setting, T val, LocalizationEnum title, LocalizationEnum hint) { registerApp(blitter, setting, val, title, hint.text()); } - @Nullable - private ButtonAppearance getApperance() { + private void triggerPress() { + boolean backwards = false; + Screen currentScreen = Minecraft.getInstance().screen; + if (currentScreen instanceof AEBaseScreen) { + backwards = ((AEBaseScreen) currentScreen).isHandlingRightClick(); + } + onPress.handle(this, backwards); + } + + private ButtonAppearance getAppearance() { if (this.configSpec != null && this.currentValue != null) { return appearances.get(new EnumPair<>(this.configSpec, this.currentValue)); } @@ -174,23 +157,23 @@ private ButtonAppearance getApperance() { @Override protected Blitter getBlitter() { - var app = getApperance(); - if (app != null && app.blitter != null) { - return app.blitter(); + ButtonAppearance appearance = getAppearance(); + if (appearance != null && appearance.blitter != null) { + return appearance.blitter(); } return Icon.TOOLBAR_BUTTON_BACKGROUND.getBlitter(); } @Override - protected Item getItemOverlay() { - var app = getApperance(); - if (app != null && app.item != null) { - return app.item; + protected @org.jetbrains.annotations.Nullable Item getItemOverlay() { + ButtonAppearance appearance = getAppearance(); + if (appearance != null && appearance.item != null) { + return appearance.item(); } return null; } - public ForgeConfigSpec.EnumValue getSetting() { + public ModConfigSpec.EnumValue getSetting() { return this.configSpec; } @@ -199,9 +182,7 @@ public T getCurrentValue() { } public void set(T e) { - if (this.currentValue != e) { - this.currentValue = e; - } + if (this.currentValue != e) this.currentValue = e; } public T getNextValue(boolean backwards) { @@ -221,12 +202,11 @@ public void toggleConfig(boolean backwards) { @Override public List getTooltipMessage() { - if (this.configSpec == null || this.currentValue == null) { return Collections.emptyList(); } - var buttonAppearance = appearances.get(new EnumPair<>(this.configSpec, this.currentValue)); + ButtonAppearance buttonAppearance = appearances.get(new EnumPair<>(this.configSpec, this.currentValue)); if (buttonAppearance == null) { return Collections.singletonList(ButtonToolTips.NoSuchMessage.text()); } @@ -234,12 +214,15 @@ public List getTooltipMessage() { return buttonAppearance.tooltipLines; } - private static final class EnumPair> { + public interface IHandler> { + void handle(T button, boolean backwards); + } - final ForgeConfigSpec.EnumValue setting; + private static final class EnumPair> { + final ModConfigSpec.EnumValue setting; final T value; - public EnumPair(ForgeConfigSpec.EnumValue setting, T value) { + public EnumPair(ModConfigSpec.EnumValue setting, T value) { this.setting = setting; this.value = value; } @@ -251,12 +234,8 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } + if (obj == null) return false; + if (this.getClass() != obj.getClass()) return false; final EnumPair other = (EnumPair) obj; return other.setting == this.setting && other.value == this.value; } diff --git a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomButtonTooltips.java b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomButtonTooltips.java index 7083bfb..4174ed3 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomButtonTooltips.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomButtonTooltips.java @@ -28,8 +28,7 @@ public enum CustomButtonTooltips implements LocalizationEnum { InternalId("Internal ID"), - ResourceLocation("Resource Location") - ; + ResourceLocation("Resource Location"); private final String englishText; diff --git a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIcon.java b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIcon.java index aa89337..3f29a99 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIcon.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIcon.java @@ -34,21 +34,19 @@ * Edit in {@code assets/appliedsorting/textures/guis/states.png}. */ public enum CustomIcon { - SORT_BY_ID(0, 0), SORT_BY_RESOURCE_LOCATION(16, 0); - public final int x; - public final int y; - public final int width; - public final int height; - public static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath( AppliedSorting.MODID, "textures/guis/states.png" ); public static final int TEXTURE_WIDTH = 32; public static final int TEXTURE_HEIGHT = 32; + public final int x; + public final int y; + public final int width; + public final int height; CustomIcon(int x, int y) { this(x, y, 16, 16); @@ -65,4 +63,4 @@ public Blitter getBlitter() { return Blitter.texture(TEXTURE, TEXTURE_WIDTH, TEXTURE_HEIGHT) .src(x, y, width, height); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIconButton.java b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIconButton.java index 1570d84..a070a7d 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIconButton.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/ae2/CustomIconButton.java @@ -20,6 +20,7 @@ * MODFICATIONS: * - Meatwo310: Changed package/class name. * - Meatwo310: Generalized to render any icon via an abstract `getBlitter()` method. + * - Mochi_753: Modified to match the design of AE2 in Minecraft 1.21.1. * * See NOTICE file for license details. */ @@ -30,6 +31,7 @@ import appeng.client.gui.style.Blitter; import appeng.client.gui.widgets.ITooltip; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.renderer.Rect2i; @@ -37,43 +39,36 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; public abstract class CustomIconButton extends Button implements ITooltip { - private boolean halfSize = false; - private boolean disableClickSound = false; - private boolean disableBackground = false; - public CustomIconButton(OnPress onPress) { + protected CustomIconButton(OnPress onPress) { super(0, 0, 16, 16, Component.empty(), onPress, Button.DEFAULT_NARRATION); } - public void setVisibility(boolean vis) { - this.visible = vis; - this.active = vis; + public void setVisibility(boolean visibility) { + this.visible = visibility; + this.active = visibility; } @Override - public void playDownSound(SoundManager soundHandler) { - if (!disableClickSound) { - super.playDownSound(soundHandler); - } + public void playDownSound(@NotNull SoundManager handler) { + if (!this.disableClickSound) super.playDownSound(handler); } @Override - public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) { - + protected void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { if (this.visible) { Blitter blitter = this.getBlitter(); - if (!this.active) { - blitter.opacity(0.5f); - } + if (!this.active) blitter.opacity(0.5F); if (this.halfSize) { this.width = 8; @@ -81,43 +76,43 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float } RenderSystem.disableDepthTest(); - RenderSystem.enableBlend(); // FIXME: This should be the _default_ state, but some vanilla widget disables - - if (isFocused()) { - // Draw 1px border with 4 quads, don't rely on the background as it can be disabled. - // top - guiGraphics.fill(getX() - 1, getY() - 1, getX() + width + 1, getY(), 0xFFFFFFFF); - // left - guiGraphics.fill(getX() - 1, getY(), getX(), getY() + height, 0xFFFFFFFF); - // right - guiGraphics.fill(getX() + width, getY(), getX() + width + 1, getY() + height, 0xFFFFFFFF); - // bottom - guiGraphics.fill(getX() - 1, getY() + height, getX() + width + 1, getY() + height + 1, 0xFFFFFFFF); - } + RenderSystem.enableBlend(); if (this.halfSize) { - var pose = guiGraphics.pose(); + PoseStack pose = guiGraphics.pose(); pose.pushPose(); pose.translate(getX(), getY(), 0.0F); pose.scale(0.5f, 0.5f, 1.f); - if (!disableBackground) { - Icon.TOOLBAR_BUTTON_BACKGROUND.getBlitter().dest(0, 0).blit(guiGraphics); - } - blitter.dest(0, 0).blit(guiGraphics); + if (!disableBackground) renderBackground(guiGraphics); + renderIcon(guiGraphics); pose.popPose(); } else { - if (!disableBackground) { - Icon.TOOLBAR_BUTTON_BACKGROUND.getBlitter().dest(getX(), getY()).blit(guiGraphics); - } - this.getBlitter().dest(getX(), getY()).blit(guiGraphics); + if (!disableBackground) renderBackground(guiGraphics); + renderIcon(guiGraphics); } RenderSystem.enableDepthTest(); - var item = this.getItemOverlay(); - if (item != null) { - guiGraphics.renderItem(new ItemStack(item), getX(), getY()); - } + Item item = this.getItemOverlay(); + if (item != null) guiGraphics.renderItem(new ItemStack(item), getX(), getY()); + } + } + + private void renderBackground(GuiGraphics guiGraphics) { + if (isHovered()) { + Icon.TOOLBAR_BUTTON_BACKGROUND_HOVER.getBlitter().dest(getX() - 1, getY() + 1).blit(guiGraphics); + } else if (isFocused()) { + Icon.TOOLBAR_BUTTON_BACKGROUND_FOCUS.getBlitter().dest(getX() - 1, getY()).blit(guiGraphics); + } else { + Icon.TOOLBAR_BUTTON_BACKGROUND.getBlitter().dest(getX() - 1, getY()).blit(guiGraphics); + } + } + + private void renderIcon(GuiGraphics guiGraphics) { + if (isHovered) { + this.getBlitter().dest(getX(), getY() + 2).blit(guiGraphics); + } else { + this.getBlitter().dest(getX(), getY() + 1).blit(guiGraphics); } } @@ -146,11 +141,7 @@ public List getTooltipMessage() { @Override public Rect2i getTooltipArea() { - return new Rect2i( - getX(), - getY(), - this.halfSize ? 8 : 16, - this.halfSize ? 8 : 16); + return new Rect2i(getX(), getY(), this.halfSize ? 8 : 16, this.halfSize ? 8 : 16); } @Override @@ -181,5 +172,4 @@ public boolean isDisableBackground() { public void setDisableBackground(boolean disableBackground) { this.disableBackground = disableBackground; } - } diff --git a/src/main/java/io/github/meatwo310/appliedsorting/config/ClientConfig.java b/src/main/java/io/github/meatwo310/appliedsorting/config/ClientConfig.java index ee6c1b9..67ac516 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/config/ClientConfig.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/config/ClientConfig.java @@ -1,22 +1,22 @@ package io.github.meatwo310.appliedsorting.config; -import net.minecraftforge.common.ForgeConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec; public class ClientConfig { - private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); + private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); - public static final ForgeConfigSpec.EnumValue ALTERNATIVE_SORT = BUILDER + public static final ModConfigSpec.EnumValue ALTERNATIVE_SORT = BUILDER .comment("Replaces the default sorting with the selected option") .defineEnum("alternativeSort", SortBy.INTERNAL_ID); - public static final ForgeConfigSpec.BooleanValue REMOVE_DEFAULT_SORT_BUTTON = BUILDER + public static final ModConfigSpec.BooleanValue REMOVE_DEFAULT_SORT_BUTTON = BUILDER .comment("Removes the default sort button from the ME terminal") .define("removeDefaultSortButton", true); - public static final ForgeConfigSpec.BooleanValue RESOURCE_LOCATION_MINECRAFT_FIRST = BUILDER + public static final ModConfigSpec.BooleanValue RESOURCE_LOCATION_MINECRAFT_FIRST = BUILDER .push("resourceLocation") .comment("Sort Minecraft items first when sorting by resource location") .define("minecraftFirst", true); - public static final ForgeConfigSpec SPEC = BUILDER.build(); + public static final ModConfigSpec SPEC = BUILDER.build(); } diff --git a/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASDataGens.java b/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASDataGens.java deleted file mode 100644 index ed095b8..0000000 --- a/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASDataGens.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.meatwo310.appliedsorting.datagen; - -import io.github.meatwo310.appliedsorting.AppliedSorting; -import net.minecraftforge.data.event.GatherDataEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber(modid = AppliedSorting.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) -public class ASDataGens { - @SubscribeEvent - public static void onGatherData(GatherDataEvent event) { - var generator = event.getGenerator(); - var output = generator.getPackOutput(); - - ASLangGen.register(generator, output); - } -} diff --git a/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASLangGen.java b/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASLangGen.java deleted file mode 100644 index 8739f97..0000000 --- a/src/main/java/io/github/meatwo310/appliedsorting/datagen/ASLangGen.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.github.meatwo310.appliedsorting.datagen; - -import appeng.core.localization.LocalizationEnum; -import io.github.meatwo310.appliedsorting.AppliedSorting; -import io.github.meatwo310.appliedsorting.ae2.CustomButtonTooltips; -import net.minecraft.data.DataGenerator; -import net.minecraft.data.PackOutput; -import net.minecraftforge.common.data.LanguageProvider; - -public class ASLangGen { - protected ASLangGen() {} - - public static void register(DataGenerator generator, PackOutput output) { - generator.addProvider(true, new EnUs(output)); - generator.addProvider(true, new JaJp(output)); - } - - public static class EnUs extends CustomLanguageProvider { - protected EnUs(PackOutput output) { - super(output, "en_us"); - } - - @Override - protected void addTranslations() { - addEnum(CustomButtonTooltips.class); - } - } - - public static class JaJp extends CustomLanguageProvider { - protected JaJp(PackOutput output) { - super(output, "ja_jp"); - } - - @Override - protected void addTranslations() { - for (var value : CustomButtonTooltips.class.getEnumConstants()) { - this.add(value.getTranslationKey(), switch (value) { - case InternalId -> "数値ID"; - case ResourceLocation -> "リソース名"; - }); - } - } - } - - private static abstract class CustomLanguageProvider extends LanguageProvider { - protected CustomLanguageProvider(PackOutput output, String locale) { - this(output, AppliedSorting.MODID, locale); - } - - protected CustomLanguageProvider(PackOutput output, String modid, String locale) { - super(output, modid, locale); - } - - protected & LocalizationEnum> void addEnum(Class localizedEnum) { - for (var value : localizedEnum.getEnumConstants()) { - this.add(value.getTranslationKey(), value.getEnglishText()); - } - } - } -} diff --git a/src/main/java/io/github/meatwo310/appliedsorting/mixin/.gitkeep b/src/main/java/io/github/meatwo310/appliedsorting/mixin/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/AEBaseScreenInvoker.java b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/AEBaseScreenInvoker.java deleted file mode 100644 index c9e93c2..0000000 --- a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/AEBaseScreenInvoker.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.meatwo310.appliedsorting.mixin.ae2; - -import appeng.client.gui.AEBaseScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(value = AEBaseScreen.class, remap = false) -public interface AEBaseScreenInvoker { - @Invoker("openHelp") - void openHelp(); -} diff --git a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/KeySortersMixin.java b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/KeySortersMixin.java index a103a34..fddba7e 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/KeySortersMixin.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/KeySortersMixin.java @@ -17,10 +17,21 @@ @Mixin(targets = "appeng.client.gui.me.common.KeySorters", remap = false) public class KeySortersMixin { - @Shadow @Final public static Comparator NAME_ASC; - @Shadow @Final public static Comparator NAME_DESC; - @Shadow @Final public static Comparator MOD_ASC; - @Shadow @Final public static Comparator MOD_DESC; + @Shadow + @Final + public static Comparator NAME_ASC; + + @Shadow + @Final + public static Comparator NAME_DESC; + + @Shadow + @Final + public static Comparator MOD_ASC; + + @Shadow + @Final + public static Comparator MOD_DESC; @Inject(method = "getComparator", at = @At("HEAD"), cancellable = true) private static void injectComparator(SortOrder order, SortDir dir, CallbackInfoReturnable> cir) { diff --git a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/MEStorageScreenMixin.java b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/MEStorageScreenMixin.java index c835195..bb08575 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/MEStorageScreenMixin.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/MEStorageScreenMixin.java @@ -4,7 +4,6 @@ import appeng.client.gui.me.common.MEStorageScreen; import appeng.client.gui.me.common.Repo; import appeng.client.gui.style.ScreenStyle; -import appeng.client.gui.style.TerminalStyle; import appeng.client.gui.widgets.SettingToggleButton; import appeng.menu.me.common.MEStorageMenu; import io.github.meatwo310.appliedsorting.AppliedSorting; @@ -20,17 +19,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = MEStorageScreen.class, remap = false) -public abstract class MEStorageScreenMixin { - @Shadow @Final private TerminalStyle style; - @Shadow @Final protected Repo repo; - @Shadow private SettingToggleButton sortByToggle; +public class MEStorageScreenMixin { + @Shadow + @Final + protected Repo repo; + + /* + @Shadow + @Final + private TerminalStyle style; + */ + + @Shadow + private SettingToggleButton sortByToggle; @Inject(method = "", at = @At("RETURN")) private void injectButton(MEStorageMenu menu, Inventory playerInventory, Component title, ScreenStyle screenStyle, CallbackInfo ci) { - if (!style.isSortable()) return; + // if (!style.isSortable) return; var verticalToolbar = ((AEBaseScreenAccessor) this).getVerticalToolbar(); - var buttons = ((VerticalButtonBarInvoker) verticalToolbar).getButtons(); + var buttons = ((VerticalButtonBarAccessor) verticalToolbar).getButtons(); var button = new ConfigToggleButton<>(ClientConfig.ALTERNATIVE_SORT, (btn, backwards) -> { btn.toggleConfig(backwards); diff --git a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarInvoker.java b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarAccessor.java similarity index 89% rename from src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarInvoker.java rename to src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarAccessor.java index 9dbbe61..2e1462e 100644 --- a/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarInvoker.java +++ b/src/main/java/io/github/meatwo310/appliedsorting/mixin/ae2/VerticalButtonBarAccessor.java @@ -8,7 +8,7 @@ import java.util.List; @Mixin(value = VerticalButtonBar.class, remap = false) -public interface VerticalButtonBarInvoker { +public interface VerticalButtonBarAccessor { @Accessor List