From 40d8a8ad7869332f1087d24326ed5b7c32ebf8fd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 29 Mar 2021 21:35:20 +0800 Subject: Publish REI 6 to Forge Signed-off-by: shedaniel --- .github/workflows/curseforge.yml | 10 +--- .github/workflows/stale.yml | 20 ------- api/build.gradle | 2 - .../rei/api/client/gui/screen/DisplayScreen.java | 54 +++++++++++++++++ .../rei/api/common/util/CollectionUtils.java | 70 ++++++++-------------- build.gradle | 31 ++++++++-- default-plugin/build.gradle | 2 - fabric/build.gradle | 27 ++++++++- forge/build.gradle | 28 ++++++++- .../forge/RoughlyEnoughItemsInitializerImpl.java | 3 + forge/src/main/resources/META-INF/mods.toml | 6 +- runtime/build.gradle | 2 - .../rei/impl/client/ClientHelperImpl.java | 23 +++---- .../shedaniel/rei/impl/client/REIHelperImpl.java | 24 ++++---- .../gui/screen/AbstractDisplayViewingScreen.java | 29 +++++---- .../gui/screen/CompositeDisplayViewingScreen.java | 7 ++- .../gui/screen/DefaultDisplayViewingScreen.java | 27 +++++---- .../rei/impl/client/gui/screen/RecipeScreen.java | 42 ------------- .../gui/screen/UncertainDisplayViewingScreen.java | 2 +- 19 files changed, 231 insertions(+), 178 deletions(-) delete mode 100644 .github/workflows/stale.yml create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/RecipeScreen.java diff --git a/.github/workflows/curseforge.yml b/.github/workflows/curseforge.yml index 00aa6971a..f22f5b7a2 100644 --- a/.github/workflows/curseforge.yml +++ b/.github/workflows/curseforge.yml @@ -11,6 +11,7 @@ on: - 4.x-unstable - 4.x - 5.x + - 6.x jobs: build: @@ -22,13 +23,8 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 - - name: Clean Gradle - run: ./gradlew clean --refresh-dependencies --stacktrace - env: - danielshe_curse_api_key: ${{ secrets.CF_API_KEY }} - BRANCH_NAME: ${{ github.ref }} - - name: Upload to CurseForge and Maven - run: ./gradlew build publish releaseOnCf --stacktrace + - name: Upload to CurseForge + run: ./gradlew build curseforge --stacktrace env: danielshe_curse_api_key: ${{ secrets.CF_API_KEY }} BRANCH_NAME: ${{ github.ref }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 5bcf6e137..000000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Mark stale issues and pull requests - -on: - schedule: - - cron: "0 0 * * *" - -jobs: - stale: - - runs-on: ubuntu-latest - - steps: - - uses: actions/stale@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is marked with stale as this issue had no activity in 60 days. This issue will not be automatically closed.' - stale-pr-message: 'This pull request is marked with stale as this pull request had no activity in 60 days. This pull request will not be automatically closed.' - stale-issue-label: 'stale' - stale-pr-label: 'stale' - days-before-close: 1000000000 diff --git a/api/build.gradle b/api/build.gradle index 925fed277..3a332c299 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1,5 +1,3 @@ -archivesBaseName = "api" - dependencies { modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") modCompileOnly("me.shedaniel.cloth:cloth-config:${cloth_config_version}") diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java new file mode 100644 index 000000000..259088e2f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/screen/DisplayScreen.java @@ -0,0 +1,54 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.client.gui.screen; + +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.entry.EntryStack; + +public interface DisplayScreen { + Rectangle getBounds(); + + void setIngredientStackToNotice(EntryStack stack); + + void setResultStackToNotice(EntryStack stack); + + EntryStack getIngredientStackToNotice(); + + EntryStack getResultStackToNotice(); + + default CategoryIdentifier getCurrentCategoryId() { + return getCurrentCategory().getCategoryIdentifier(); + } + + DisplayCategory getCurrentCategory(); + + void recalculateCategoryPage(); + + void previousCategory(); + + void nextCategory(); +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 45d065ee6..a191d85ce 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -47,16 +47,18 @@ import java.util.stream.StreamSupport; public class CollectionUtils { public static List getOrPutEmptyList(Map> map, A key) { List b = map.get(key); - if (b != null) + if (b != null) { return b; + } map.put(key, new ArrayList<>()); return map.get(key); } public static T findFirstOrNullEquals(Iterable list, T obj) { for (T t : list) { - if (t.equals(obj)) + if (t.equals(obj)) { return t; + } } return null; } @@ -64,26 +66,24 @@ public class CollectionUtils { public static List castAndMap(Iterable list, Class castClass) { List l = new ArrayList<>(); for (T t : list) { - if (castClass.isAssignableFrom(t.getClass())) + if (castClass.isAssignableFrom(t.getClass())) { l.add((R) t); + } } return l; } public static T findFirstOrNull(Iterable list, Predicate predicate) { for (T t : list) { - if (predicate.test(t)) + if (predicate.test(t)) { return t; + } } return null; } public static boolean anyMatch(Iterable list, Predicate predicate) { - for (T t : list) { - if (predicate.test(t)) - return true; - } - return false; + return findFirstOrNull(list, predicate) != null; } public static EntryStack findFirstOrNullEqualsExact(Iterable> list, EntryStack stack) { @@ -155,8 +155,9 @@ public class CollectionUtils { } public static Optional mapAndMax(Collection list, Function function, Comparator comparator) { - if (list.isEmpty()) + if (list.isEmpty()) { return Optional.empty(); + } return list.stream().max(Comparator.comparing(function, comparator)).map(function); } @@ -167,34 +168,28 @@ public class CollectionUtils { } public static Optional max(Collection list, Comparator comparator) { - if (list.isEmpty()) + if (list.isEmpty()) { return Optional.empty(); + } return list.stream().max(comparator); } public static Optional max(T[] list, Comparator comparator) { - if (list.length <= 0) + if (list.length <= 0) { return Optional.empty(); + } return Stream.of(list).max(comparator); } - public static String joinToString(Iterable list, String separator) { - StringJoiner joiner = new StringJoiner(separator); - for (String t : list) { - joiner.add(t); - } - return joiner.toString(); + public static String joinToString(Iterable list, CharSequence separator) { + return String.join(separator, list); } - public static String joinToString(String[] list, String separator) { - StringJoiner joiner = new StringJoiner(separator); - for (String t : list) { - joiner.add(t); - } - return joiner.toString(); + public static String joinToString(CharSequence[] list, CharSequence separator) { + return String.join(separator, list); } - public static String mapAndJoinToString(Iterable list, Function function, String separator) { + public static String mapAndJoinToString(Iterable list, Function function, CharSequence separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); @@ -202,7 +197,7 @@ public class CollectionUtils { return joiner.toString(); } - public static String mapAndJoinToString(T[] list, Function function, String separator) { + public static String mapAndJoinToString(T[] list, Function function, CharSequence separator) { StringJoiner joiner = new StringJoiner(separator); for (T t : list) { joiner.add(function.apply(t)); @@ -282,8 +277,8 @@ public class CollectionUtils { return sum; } - public static Iterable> partition(List list, int size) { - return () -> new UnmodifiableIterator>() { + public static Iterable> partition(List list, int size) { + return () -> new UnmodifiableIterator>() { int i = 0; int partitionSize = Mth.ceil(list.size() / (float) size); @@ -293,22 +288,9 @@ public class CollectionUtils { } @Override - public Iterable next() { - UnmodifiableIterator iterator = new UnmodifiableIterator() { - int cursor = i++ * size; - int curSize = cursor + Math.min(list.size() - cursor, size); - - @Override - public boolean hasNext() { - return cursor < curSize; - } - - @Override - public T next() { - return list.get(cursor++); - } - }; - return () -> iterator; + public List next() { + int cursor = i++ * size; + return list.subList(cursor, cursor + Math.min(list.size() - cursor, size)); } }; } diff --git a/build.gradle b/build.gradle index 1aff1a6b3..3e18d4b57 100755 --- a/build.gradle +++ b/build.gradle @@ -11,8 +11,8 @@ import java.text.SimpleDateFormat archivesBaseName = "RoughlyEnoughItems" -def runNumber = (System.getenv("GITHUB_RUN_NUMBER") == null ? "9999" : System.getenv("GITHUB_RUN_NUMBER")) -version = rootProject.base_version + "." + runNumber +def runNumber = System.getenv("GITHUB_RUN_NUMBER") ?: "9999" +version = rootProject.base_version + "." + runNumber + "-alpha" group = "me.shedaniel" @@ -66,6 +66,7 @@ subprojects { group = rootProject.group version = rootProject.version + archivesBaseName = rootProject.name // loom { // silentMojangMappingsLicense() @@ -147,10 +148,10 @@ task releaseOnCf { dependsOn tasks.getByName("curseforge") } -/*curseforge { +curseforge { if (project.hasProperty('danielshe_curse_api_key') || System.getenv('danielshe_curse_api_key') != null) { apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key') - project { + /*project { id = "310111" releaseType = "release" changelogType = "html" @@ -175,6 +176,26 @@ task releaseOnCf { afterEvaluate { uploadTask.dependsOn("build") } + }*/ + project { + id = "392060" + releaseType = "beta" + changelogType = "html" + changelog = releaseChangelog + addGameVersion "1.16.4" + addGameVersion "1.16.5" + addGameVersion "Java 8" + addGameVersion "Forge" + relations { + requiredDependency "architectury-forge" + requiredDependency "cloth-config-forge" + } + addArtifact(project("forge").tasks.getByName("remapJar")) { + displayName = "[Forge $project.supported_version] v$project.version" + } + afterEvaluate { + uploadTask.dependsOn("forge:build") + } } } options { @@ -183,7 +204,7 @@ task releaseOnCf { } } -publishing { +/*publishing { publications { mavenJava(MavenPublication) { artifact(jar) { diff --git a/default-plugin/build.gradle b/default-plugin/build.gradle index 4f7fbee58..88bf7f1f4 100644 --- a/default-plugin/build.gradle +++ b/default-plugin/build.gradle @@ -1,5 +1,3 @@ -archivesBaseName = "default-plugin" - loom { accessWidener = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener") } diff --git a/fabric/build.gradle b/fabric/build.gradle index be813394e..a96854333 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,4 +1,10 @@ -archivesBaseName = "fabric" +plugins { + id "com.github.johnrengelman.shadow" version "5.0.0" +} + +configurations { + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. +} architectury { platformSetupLoomIde() @@ -36,4 +42,23 @@ dependencies { developmentFabric(project(path: ":api")) { transitive = false } developmentFabric(project(path: ":default-plugin")) { transitive = false } developmentFabric(project(path: ":runtime")) { transitive = false } + + shadowCommon(project(path: ":api", configuration: "transformProductionFabric")) { transitive = false } + shadowCommon(project(path: ":default-plugin", configuration: "transformProductionFabric")) { transitive = false } + shadowCommon(project(path: ":runtime", configuration: "transformProductionFabric")) { transitive = false } +} + +shadowJar { + configurations = [project.configurations.shadowCommon] + classifier "dev-shadow" +} + +remapJar { + input.set shadowJar.archiveFile + dependsOn shadowJar + classifier "fabric" +} + +jar { + classifier "dev" } diff --git a/forge/build.gradle b/forge/build.gradle index 338ecaa99..2674432f9 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,4 +1,10 @@ -archivesBaseName = "forge" +plugins { + id "com.github.johnrengelman.shadow" version "5.0.0" +} + +configurations { + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. +} architectury { platformSetupLoomIde() @@ -38,9 +44,29 @@ dependencies { developmentForge(project(path: ":runtime")) { transitive = false } developmentForge(project(path: ":jei-compatibility-layer")) { transitive = false } + shadowCommon(project(path: ":api", configuration: "transformProductionForge")) { transitive = false } + shadowCommon(project(path: ":default-plugin", configuration: "transformProductionForge")) { transitive = false } + shadowCommon(project(path: ":runtime", configuration: "transformProductionForge")) { transitive = false } + shadowCommon(project(path: ":jei-compatibility-layer")) { transitive = false } + modRuntime("curse.maven:chiselsbits-231095:3176033") modRuntime("curse.maven:jumbofurnace-390880:3120970") modRuntime("curse.maven:cyclic-239286:3221427") modRuntime("curse.maven:mekanism-268560:3206392") modRuntime("appeng:appliedenergistics2:8.2.0") } + +shadowJar { + configurations = [project.configurations.shadowCommon] + classifier "dev-shadow" +} + +remapJar { + input.set shadowJar.archiveFile + dependsOn shadowJar + classifier "forge" +} + +jar { + classifier "dev" +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java index b6ce353b2..a433c87a5 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java @@ -34,6 +34,9 @@ public class RoughlyEnoughItemsInitializerImpl { } public static void checkMods() { + if (ModList.get().isLoaded("jei")) { + RoughlyEnoughItemsState.error("JEI is installed! REI is an replacement of JEI, we can't co-exist!"); + } if (isClient()) { if (!ModList.get().isLoaded("cloth-config")) { RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index aa62f0797..02685e595 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -13,8 +13,8 @@ To allow players to view items and recipes. ''' [[dependencies.roughlyenoughitems]] -modId = "cloth-config" +modId = "architectury" mandatory = true -versionRange = "[4.0.1,)" +versionRange = "[1.9.136,)" ordering = "NONE" -side = "CLIENT" \ No newline at end of file +side = "BOTH" diff --git a/runtime/build.gradle b/runtime/build.gradle index 5d6c24c49..53c1100d7 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -1,5 +1,3 @@ -archivesBaseName = "runtime" - architectury { common() } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 9590c62a7..abaf8443f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -43,7 +43,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.impl.client.gui.screen.CompositeDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; -import me.shedaniel.rei.impl.client.gui.screen.RecipeScreen; +import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.impl.client.gui.screen.UncertainDisplayViewingScreen; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -242,14 +242,17 @@ public class ClientHelperImpl implements ClientHelper { } else { screen = new DefaultDisplayViewingScreen(map, builder.getPreferredOpenedCategory()); } - if (screen instanceof RecipeScreen) { - if (builder.getInputNotice() != null) - ((RecipeScreen) screen).addIngredientStackToNotice(builder.getInputNotice()); - if (builder.getOutputNotice() != null) - ((RecipeScreen) screen).addResultStackToNotice(builder.getOutputNotice()); + if (screen instanceof DisplayScreen) { + if (builder.getInputNotice() != null) { + ((DisplayScreen) screen).setIngredientStackToNotice(builder.getInputNotice()); + } + if (builder.getOutputNotice() != null) { + ((DisplayScreen) screen).setResultStackToNotice(builder.getOutputNotice()); + } + } + if (Minecraft.getInstance().screen instanceof DisplayScreen) { + REIHelperImpl.getInstance().storeDisplayScreen((DisplayScreen) Minecraft.getInstance().screen); } - if (Minecraft.getInstance().screen instanceof RecipeScreen) - REIHelperImpl.getInstance().storeRecipeScreen((RecipeScreen) Minecraft.getInstance().screen); Minecraft.getInstance().setScreen(screen); return true; } @@ -269,8 +272,8 @@ public class ClientHelperImpl implements ClientHelper { public ViewSearchBuilder fillPreferredOpenedCategory() { if (getPreferredOpenedCategory() == null) { Screen currentScreen = Minecraft.getInstance().screen; - if (currentScreen instanceof RecipeScreen) { - setPreferredOpenedCategory(((RecipeScreen) currentScreen).getCurrentCategory()); + if (currentScreen instanceof DisplayScreen) { + setPreferredOpenedCategory(((DisplayScreen) currentScreen).getCurrentCategoryId()); } } return this; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java index 82c3eb983..568149a11 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java @@ -38,7 +38,7 @@ import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; -import me.shedaniel.rei.impl.client.gui.screen.RecipeScreen; +import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -64,7 +64,7 @@ public class REIHelperImpl implements REIHelper { private OverlaySearchField searchField; private AbstractContainerScreen previousContainerScreen = null; private Screen previousScreen = null; - private LinkedHashSet lastRecipeScreen = Sets.newLinkedHashSetWithExpectedSize(10); + private LinkedHashSet lastDisplayScreen = Sets.newLinkedHashSetWithExpectedSize(10); /** * @return the instance of screen helper @@ -97,19 +97,19 @@ public class REIHelperImpl implements REIHelper { return (OverlaySearchField) getInstance().getSearchTextField(); } - public void storeRecipeScreen(RecipeScreen screen) { - while (lastRecipeScreen.size() >= 10) - lastRecipeScreen.remove(Iterables.get(lastRecipeScreen, 0)); - lastRecipeScreen.add(screen); + public void storeDisplayScreen(DisplayScreen screen) { + while (lastDisplayScreen.size() >= 10) + lastDisplayScreen.remove(Iterables.get(lastDisplayScreen, 0)); + lastDisplayScreen.add(screen); } - public boolean hasLastRecipeScreen() { - return !lastRecipeScreen.isEmpty(); + public boolean hasLastDisplayScreen() { + return !lastDisplayScreen.isEmpty(); } - public Screen getLastRecipeScreen() { - RecipeScreen screen = Iterables.getLast(lastRecipeScreen); - lastRecipeScreen.remove(screen); + public Screen getLastDisplayScreen() { + DisplayScreen screen = Iterables.getLast(lastDisplayScreen); + lastDisplayScreen.remove(screen); screen.recalculateCategoryPage(); return (Screen) screen; } @@ -208,7 +208,7 @@ public class REIHelperImpl implements REIHelper { @Override public void startReload() { getOverlay().ifPresent(REIOverlay::queueReloadOverlay); - lastRecipeScreen.clear(); + lastDisplayScreen.clear(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index 05230cbe5..833f4fa01 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Slot; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; @@ -43,7 +44,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Map; -public abstract class AbstractDisplayViewingScreen extends Screen implements RecipeScreen { +public abstract class AbstractDisplayViewingScreen extends Screen implements DisplayScreen { protected final Map, List> categoryMap; protected final List> categories; protected EntryStack ingredientStackToNotice = EntryStack.empty(); @@ -67,36 +68,43 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Rec } } + @Override + public boolean isPauseScreen() { + return false; + } + @Override public Rectangle getBounds() { return bounds; } @Override - public void addIngredientStackToNotice(EntryStack stack) { + public void setIngredientStackToNotice(EntryStack stack) { this.ingredientStackToNotice = stack; } @Override - public void addResultStackToNotice(EntryStack stack) { + public void setResultStackToNotice(EntryStack stack) { this.resultStackToNotice = stack; } @Override - public boolean isPauseScreen() { - return false; + public EntryStack getIngredientStackToNotice() { + return ingredientStackToNotice; } @Override - public CategoryIdentifier getCurrentCategory() { - return getSelectedCategory().getCategoryIdentifier(); + public EntryStack getResultStackToNotice() { + return resultStackToNotice; } - public DisplayCategory getSelectedCategory() { + @Override + public DisplayCategory getCurrentCategory() { return (DisplayCategory) categories.get(selectedCategoryIndex); } - protected void previousCategory() { + @Override + public void previousCategory() { int currentCategoryIndex = selectedCategoryIndex; currentCategoryIndex--; if (currentCategoryIndex < 0) @@ -104,7 +112,8 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Rec ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice); } - protected void nextCategory() { + @Override + public void nextCategory() { int currentCategoryIndex = selectedCategoryIndex; currentCategoryIndex++; if (currentCategoryIndex >= categories.size()) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index 619b9ab7a..6214c0254 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -411,10 +411,11 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen return true; } if (keyCode == 259) { - if (REIHelperImpl.getInstance().hasLastRecipeScreen()) - minecraft.setScreen(REIHelperImpl.getInstance().getLastRecipeScreen()); - else + if (REIHelperImpl.getInstance().hasLastDisplayScreen()) { + minecraft.setScreen(REIHelperImpl.getInstance().getLastDisplayScreen()); + } else { minecraft.setScreen(REIHelper.getInstance().getPreviousScreen()); + } return true; } return super.keyPressed(keyCode, scanCode, modifiers); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index 915e85be6..85cb85994 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -143,10 +143,11 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { return true; } if (keyCode == 259) { - if (REIHelperImpl.getInstance().hasLastRecipeScreen()) - minecraft.setScreen(REIHelperImpl.getInstance().getLastRecipeScreen()); - else + if (REIHelperImpl.getInstance().hasLastDisplayScreen()) { + minecraft.setScreen(REIHelperImpl.getInstance().getLastDisplayScreen()); + } else { minecraft.setScreen(REIHelper.getInstance().getPreviousScreen()); + } return true; } return super.keyPressed(keyCode, scanCode, modifiers); @@ -164,7 +165,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { this.widgets.clear(); int largestWidth = width - 100; int largestHeight = Math.max(height - 34 - 30, 100); - int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), getSelectedCategory()::getDisplayWidth, Comparator.naturalOrder()).orElse(150); + int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), getCurrentCategory()::getDisplayWidth, Comparator.naturalOrder()).orElse(150); int guiWidth = Math.max(maxWidthDisplay + 40, 190); this.tabsPerPage = Math.max(5, Mth.floor((guiWidth - 20d) / tabSize)); if (this.categoryPages == -1) { @@ -194,7 +195,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { .enabled(categories.size() > tabsPerPage)); widgets.add(categoryBack = Widgets.createButton(new Rectangle(bounds.getX() + 5, bounds.getY() + 5, 12, 12), new TranslatableComponent("text.rei.left_arrow")) .onClick(button -> previousCategory()).tooltipLine(new TranslatableComponent("text.rei.previous_category"))); - widgets.add(Widgets.createClickableLabel(new Point(bounds.getCenterX(), bounds.getY() + 7), getSelectedCategory().getTitle(), clickableLabelWidget -> { + widgets.add(Widgets.createClickableLabel(new Point(bounds.getCenterX(), bounds.getY() + 7), getCurrentCategory().getTitle(), clickableLabelWidget -> { ClientHelper.getInstance().openView(ViewSearchBuilder.builder().addAllCategories().fillPreferredOpenedCategory()); }).tooltipLine(I18n.get("text.rei.view_all_categories"))); widgets.add(categoryNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), new TranslatableComponent("text.rei.right_arrow")) @@ -240,21 +241,21 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getTitle(), tab.getId() + categoryPages * tabsPerPage == selectedCategoryIndex); } } - Optional supplier = CategoryRegistry.getInstance().get(getCurrentCategory()).getPlusButtonArea(); - int recipeHeight = getSelectedCategory().getDisplayHeight(); + Optional supplier = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getPlusButtonArea(); + int recipeHeight = getCurrentCategory().getDisplayHeight(); List currentDisplayed = getCurrentDisplayed(); for (int i = 0; i < currentDisplayed.size(); i++) { final Display display = currentDisplayed.get(i); final Supplier displaySupplier = () -> display; - int displayWidth = getSelectedCategory().getDisplayWidth(displaySupplier.get()); + int displayWidth = getCurrentCategory().getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - recipeHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + recipeHeight * i + 4 * i, displayWidth, recipeHeight); - List setupDisplay = getSelectedCategory().setupDisplay(display, displayBounds); + List setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); recipeBounds.put(displayBounds, setupDisplay); this.widgets.addAll(setupDisplay); if (supplier.isPresent() && supplier.get().get(displayBounds) != null) - this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(displayBounds, supplier.get().get(displayBounds), new TextComponent(supplier.get().getButtonText()), displaySupplier, setupDisplay, getSelectedCategory())); + this.widgets.add(InternalWidgets.createAutoCraftingButtonWidget(displayBounds, supplier.get().get(displayBounds), new TextComponent(supplier.get().getButtonText()), displaySupplier, setupDisplay, getCurrentCategory())); } if (choosePageActivated) choosePageWidget = new DefaultDisplayChoosePageWidget(this, page, getCurrentTotalPages()); @@ -262,7 +263,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { choosePageWidget = null; workingStationsBaseWidget = null; - List workstations = CategoryRegistry.getInstance().get(getCurrentCategory()).getWorkstations(); + List workstations = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getWorkstations(); if (!workstations.isEmpty()) { int hh = Mth.floor((bounds.height - 16) / 18f); int actualHeight = Math.min(hh, workstations.size()); @@ -297,7 +298,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { public List getCurrentDisplayed() { List list = Lists.newArrayList(); int recipesPerPage = getRecipesPerPage(); - List displays = categoryMap.get(getSelectedCategory()); + List displays = categoryMap.get(getCurrentCategory()); for (int i = 0; i <= recipesPerPage; i++) { if (page * (recipesPerPage + 1) + i < displays.size()) { list.add(displays.get(page * (recipesPerPage + 1) + i)); @@ -315,7 +316,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } private int getRecipesPerPage() { - DisplayCategory selectedCategory = getSelectedCategory(); + DisplayCategory selectedCategory = getCurrentCategory(); if (selectedCategory.getFixedDisplaysPerPage() > 0) return selectedCategory.getFixedDisplaysPerPage() - 1; int height = selectedCategory.getDisplayHeight(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/RecipeScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/RecipeScreen.java deleted file mode 100644 index 7309262e1..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/RecipeScreen.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl.client.gui.screen; - -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.entry.EntryStack; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Internal -public interface RecipeScreen { - Rectangle getBounds(); - - void addIngredientStackToNotice(EntryStack stack); - - void addResultStackToNotice(EntryStack stack); - - CategoryIdentifier getCurrentCategory(); - - void recalculateCategoryPage(); -} \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java index 6c1fa75ee..b5f0607f8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java @@ -99,7 +99,7 @@ public class UncertainDisplayViewingScreen extends Screen { this.callback = callback; this.parent = parent; this.showTips = showTips; - if (showTips && Platform.isForge()) { + if (showTips && false && Platform.isForge()) { allModsUsingJEI = ClientInternals.getJeiCompatMods().stream() .distinct() .map(ClientHelper.getInstance()::getModFromModId) -- cgit