diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-09 23:17:05 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-09 23:17:05 +0800 |
| commit | de461fde691f593b85ffeae837b5b419a9abf7cc (patch) | |
| tree | cec6e08c99427eddf9eef5e19d04edca56d3d0d4 /runtime | |
| parent | 64bc9937d6ec04c6d66240a84b4fb345026c0b12 (diff) | |
| download | RoughlyEnoughItems-de461fde691f593b85ffeae837b5b419a9abf7cc.tar.gz RoughlyEnoughItems-de461fde691f593b85ffeae837b5b419a9abf7cc.tar.bz2 RoughlyEnoughItems-de461fde691f593b85ffeae837b5b419a9abf7cc.zip | |
Use AbstractRecipeViewingScreen and remove static from ScreenHelper
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'runtime')
47 files changed, 566 insertions, 510 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java index 5e6de2399..528e279a6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java +++ b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java @@ -1,3 +1,26 @@ +/* + * 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; import me.shedaniel.architectury.annotations.ExpectPlatform; diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index c668dc282..15bee847e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -74,7 +74,6 @@ import net.minecraft.client.gui.screens.recipebook.GhostRecipe; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; import net.minecraft.client.resources.language.I18n; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.TextComponent; @@ -392,7 +391,6 @@ public class RoughlyEnoughItemsCore { return hasPermissionToUsePackets() || Minecraft.getInstance().gameMode.hasInfiniteItems(); } - @SuppressWarnings("deprecation") public void onInitializeClient() { IssuesDetector.detect(); registerClothEvents(); @@ -456,8 +454,9 @@ public class RoughlyEnoughItemsCore { if (!decider.isHandingScreen(screen)) continue; InteractionResult result = decider.shouldScreenBeOverlaid(screen); - if (result != InteractionResult.PASS) - return result == InteractionResult.FAIL || REIHelper.getInstance().getPreviousContainerScreen() == null; + if (result != InteractionResult.PASS) { + return result == InteractionResult.FAIL || REIHelper.getInstance().getPreviousScreen() == null; + } } } catch (ConcurrentModificationException ignored) { } @@ -477,12 +476,11 @@ public class RoughlyEnoughItemsCore { return InteractionResult.PASS; });*/ GuiEvent.INIT_POST.register((screen, widgets, children) -> { + REIHelperImpl.getInstance().setPreviousScreen(screen); if (shouldReturn(screen)) return; if (screen instanceof InventoryScreen && client.gameMode.hasInfiniteItems()) return; - if (screen instanceof AbstractContainerScreen) - ScreenHelper.setPreviousContainerScreen((AbstractContainerScreen<?>) screen); boolean alreadyAdded = false; for (GuiEventListener element : Lists.newArrayList(children)) if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) @@ -491,14 +489,14 @@ public class RoughlyEnoughItemsCore { else alreadyAdded = true; if (!alreadyAdded) - children.add(ScreenHelper.getLastOverlay(true, false)); + children.add(REIHelper.getInstance().getOverlay(true).get()); }); ClientScreenInputEvent.MOUSE_CLICKED_PRE.register((minecraftClient, screen, mouseX, mouseY, button) -> { isLeftModePressed = true; - if (ScreenHelper.getOptionalOverlay().isPresent()) + if (REIHelper.getInstance().getOverlay().isPresent()) if (screen instanceof CreativeModeInventoryScreen) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseClicked(mouseX, mouseY, button)) { - screen.setFocused(ScreenHelper.getLastOverlay()); + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseClicked(mouseX, mouseY, button)) { + screen.setFocused(REIHelper.getInstance().getOverlay().get()); if (button == 0) screen.setDragging(true); return InteractionResult.SUCCESS; @@ -509,8 +507,8 @@ public class RoughlyEnoughItemsCore { isLeftModePressed = false; if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.getOptionalOverlay().isPresent()) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseReleased(mouseX, mouseY, button)) { + if (REIHelper.getInstance().getOverlay().isPresent()) + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseReleased(mouseX, mouseY, button)) { return InteractionResult.SUCCESS; } return InteractionResult.PASS; @@ -518,29 +516,29 @@ public class RoughlyEnoughItemsCore { ClientScreenInputEvent.MOUSE_SCROLLED_PRE.register((minecraftClient, screen, mouseX, mouseY, amount) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseScrolled(mouseX, mouseY, amount)) + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseScrolled(mouseX, mouseY, amount)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); ClientScreenInputEvent.CHAR_TYPED_PRE.register((minecraftClient, screen, character, keyCode) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.getLastOverlay().charTyped(character, keyCode)) + if (REIHelper.getInstance().getOverlay().get().charTyped(character, keyCode)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); GuiEvent.RENDER_POST.register((screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen)) return; - ScreenHelper.getLastOverlay().render(matrices, mouseX, mouseY, delta); - if (!ScreenHelper.isOverlayVisible()) + REIHelper.getInstance().getOverlay().get().render(matrices, mouseX, mouseY, delta); + if (!REIHelper.getInstance().isOverlayVisible()) return; - ScreenHelper.getLastOverlay().lateRender(matrices, mouseX, mouseY, delta); + ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).lateRender(matrices, mouseX, mouseY, delta); }); ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((minecraftClient, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (screen instanceof AbstractContainerScreen && ScreenHelper.getLastOverlay().mouseDragged(mouseX1, mouseY1, button, mouseX2, mouseY2)) + if (screen instanceof AbstractContainerScreen && REIHelper.getInstance().getOverlay().get().mouseDragged(mouseX1, mouseY1, button, mouseX2, mouseY2)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); @@ -554,7 +552,7 @@ public class RoughlyEnoughItemsCore { } if (screen.getFocused() != null && screen.getFocused() instanceof EditBox || (screen.getFocused() instanceof RecipeBookComponent && ((RecipeBookComponent) screen.getFocused()).searchBox != null && ((RecipeBookComponent) screen.getFocused()).searchBox.isFocused())) return InteractionResult.PASS; - if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) + if (REIHelper.getInstance().getOverlay().get().keyPressed(i, i1, i2)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 7308fbb38..dfe52a3a2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -49,7 +49,7 @@ public class RoughlyEnoughItemsInitializer { initializeEntryPoint("me.shedaniel.rei.RoughlyEnoughItemsCore"); initializeEntryPoint("me.shedaniel.rei.REIModMenuEntryPoint"); initializeEntryPoint("me.shedaniel.rei.impl.ClientHelperImpl"); - initializeEntryPoint("me.shedaniel.rei.impl.ScreenHelper"); + initializeEntryPoint("me.shedaniel.rei.impl.REIHelperImpl"); } initializeEntryPoint("me.shedaniel.rei.impl.ErrorDisplayer"); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index 4f8c42bec..c827b50d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -25,7 +25,6 @@ package me.shedaniel.rei; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Env; -import net.fabricmc.api.EnvType; import net.minecraft.util.Tuple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java index f5d5464a2..cdd1b5add 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java @@ -26,7 +26,10 @@ package me.shedaniel.rei.api.gui.config.entry; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; @@ -36,13 +39,13 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.ConfigObject; -import me.shedaniel.rei.api.registry.entry.EntryRegistry; -import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.gui.widgets.Tooltip; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.entry.EntryRegistry; +import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.OverlaySearchField; import me.shedaniel.rei.gui.widget.EntryWidget; -import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.SearchArgument; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; @@ -262,7 +265,7 @@ public class FilteringScreen extends Screen { this.backButton.render(matrices, mouseX, mouseY, delta); if (tooltip != null) { - ScreenHelper.getLastOverlay().renderTooltip(matrices, tooltip); + ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).renderTooltip(matrices, tooltip); } this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); @@ -378,10 +381,7 @@ public class FilteringScreen extends Screen { return true; } } - if (backButton.mouseClicked(double_1, double_2, int_1)) { - return true; - } - return false; + return backButton.mouseClicked(double_1, double_2, int_1); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java index ed3aff6b7..3f32747e9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java @@ -27,8 +27,8 @@ import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.gui.entries.TooltipListEntry; -import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.api.gui.config.RecipeScreenType; +import me.shedaniel.rei.gui.PreRecipeViewingScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.AbstractButton; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java new file mode 100644 index 000000000..fd8007d19 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java @@ -0,0 +1,136 @@ +/* + * 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.gui; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.gui.widgets.Widget; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.api.registry.display.DisplayCategory; +import me.shedaniel.rei.api.util.CollectionUtils; +import me.shedaniel.rei.gui.widget.EntryWidget; +import me.shedaniel.rei.impl.ClientHelperImpl; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; + +public abstract class AbstractRecipeViewingScreen extends Screen implements RecipeScreen { + protected final Map<DisplayCategory<?>, List<Display>> categoryMap; + protected final List<DisplayCategory<?>> categories; + protected EntryStack<?> ingredientStackToNotice = EntryStack.empty(); + protected EntryStack<?> resultStackToNotice = EntryStack.empty(); + protected int selectedCategoryIndex = 0; + protected int tabsPerPage; + protected Rectangle bounds; + + protected AbstractRecipeViewingScreen(Map<DisplayCategory<?>, List<Display>> categoryMap, @Nullable ResourceLocation category, int tabsPerPage) { + super(NarratorChatListener.NO_TITLE); + this.categoryMap = categoryMap; + this.categories = Lists.newArrayList(categoryMap.keySet()); + this.tabsPerPage = tabsPerPage; + if (category != null) { + for (int i = 0; i < categories.size(); i++) { + if (categories.get(i).getIdentifier().equals(category)) { + this.selectedCategoryIndex = i; + break; + } + } + } + } + + @Override + public Rectangle getBounds() { + return bounds; + } + + @Override + public void addIngredientStackToNotice(EntryStack<?> stack) { + this.ingredientStackToNotice = stack; + } + + @Override + public void addResultStackToNotice(EntryStack<?> stack) { + this.resultStackToNotice = stack; + } + + @Override + public boolean isPauseScreen() { + return false; + } + + @Override + public ResourceLocation getCurrentCategory() { + return getSelectedCategory().getIdentifier(); + } + + public DisplayCategory<Display> getSelectedCategory() { + return (DisplayCategory<Display>) categories.get(selectedCategoryIndex); + } + + protected void previousCategory() { + int currentCategoryIndex = selectedCategoryIndex; + currentCategoryIndex--; + if (currentCategoryIndex < 0) + currentCategoryIndex = categories.size() - 1; + ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getIdentifier(), ingredientStackToNotice, resultStackToNotice); + } + + protected void nextCategory() { + int currentCategoryIndex = selectedCategoryIndex; + currentCategoryIndex++; + if (currentCategoryIndex >= categories.size()) + currentCategoryIndex = 0; + ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getIdentifier(), ingredientStackToNotice, resultStackToNotice); + } + + protected void transformIngredientNotice(List<Widget> setupDisplay, EntryStack<?> noticeStack) { + transformNotice(1, setupDisplay, noticeStack); + } + + protected void transformResultNotice(List<Widget> setupDisplay, EntryStack<?> noticeStack) { + transformNotice(2, setupDisplay, noticeStack); + } + + private static void transformNotice(int marker, List<Widget> setupDisplay, EntryStack<?> noticeStack) { + if (noticeStack.isEmpty()) + return; + for (Widget widget : setupDisplay) { + if (widget instanceof EntryWidget) { + EntryWidget entry = (EntryWidget) widget; + if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { + EntryStack<?> stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.getEntries(), noticeStack); + if (stack != null) { + entry.clearStacks(); + ent |
