From c65b2a347b38724ccb777114f5353e7f18b978b5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 14 Oct 2021 20:50:18 +0800 Subject: Make search report better errors, and cache more --- .../java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java | 3 +++ .../me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java | 9 --------- .../shedaniel/rei/impl/client/search/argument/Argument.java | 11 ++++++++++- .../me/shedaniel/rei/impl/client/util/CrashReportUtils.java | 7 +++++++ 4 files changed, 20 insertions(+), 10 deletions(-) (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index 07a94a0b3..e80e5f572 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -43,6 +43,7 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.hints.HintProvider; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; +import me.shedaniel.rei.impl.client.search.argument.Argument; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -216,6 +217,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void startReload() { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); lastDisplayScreen.clear(); } @@ -227,6 +229,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void endReload(ReloadStage stage) { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index b8525b6dc..04901ba45 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -58,7 +58,6 @@ import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; -import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.craftable.CraftableFilter; @@ -70,29 +69,24 @@ import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import me.shedaniel.rei.impl.client.search.argument.Argument; import me.shedaniel.rei.impl.common.util.Weather; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.PlayerInfo; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionResult; import net.minecraft.world.inventory.Slot; -import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.GameType; import net.minecraft.world.level.block.Blocks; @@ -102,8 +96,6 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; @ApiStatus.Internal public class ScreenOverlayImpl extends ScreenOverlay { @@ -225,7 +217,6 @@ public class ScreenOverlayImpl extends ScreenOverlay { } public void init() { - Argument.SEARCH_CACHE.clear(); draggingStack.set(DraggableStackProvider.from(() -> ScreenRegistry.getInstance().getDraggableProviders()), DraggableStackVisitor.from(() -> ScreenRegistry.getInstance().getDraggableVisitors())); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java index b7e733321..0d1ba77b4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; +import it.unimi.dsi.fastutil.shorts.Short2ObjectMaps; import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; import me.shedaniel.rei.api.client.gui.config.SearchMode; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -40,6 +41,7 @@ import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry; import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; import net.minecraft.util.Unit; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.Mutable; @@ -50,6 +52,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -57,7 +61,8 @@ import java.util.regex.Pattern; @Environment(EnvType.CLIENT) public class Argument { public static final String SPACE = " ", EMPTY = ""; - public static final Short2ObjectMap> SEARCH_CACHE = new Short2ObjectOpenHashMap<>(); + public static final Short2ObjectMap> SEARCH_CACHE = Short2ObjectMaps.synchronize(new Short2ObjectOpenHashMap<>()); + private static final AtomicReference lastLanguage = new AtomicReference<>(); static final Argument ALWAYS = new Argument<>(AlwaysMatchingArgumentType.INSTANCE, EMPTY, true, -1, -1, true); private ArgumentType argumentType; private String text; @@ -169,6 +174,10 @@ public class Argument { @ApiStatus.Internal public static boolean matches(EntryStack stack, List compoundArguments) { if (compoundArguments.isEmpty()) return true; + String newLanguage = Minecraft.getInstance().options.languageCode; + if (!Objects.equals(lastLanguage.getAndSet(newLanguage), newLanguage)) { + SEARCH_CACHE.clear(); + } Mutable mutable = new MutableObject<>(); a: diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java index d55567909..ac7cc3777 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java @@ -32,6 +32,13 @@ import net.minecraft.client.gui.screens.Screen; public class CrashReportUtils { public static CrashReport essential(Throwable throwable, String task) { + Throwable temp = throwable; + while (temp != null) { + temp = temp.getCause(); + if (temp instanceof ReportedException reportedException) { + return essential(reportedException, task); + } + } CrashReport report = CrashReport.forThrowable(throwable, task); screen(report, Minecraft.getInstance().screen); return report; -- cgit From a7b0a0dd4b305eb8655b008ebcfdcd2f7b70079a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Oct 2021 02:43:07 +0800 Subject: Fix merge conflicts --- .../main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java index ac7cc3777..d3159a9ca 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java @@ -35,8 +35,8 @@ public class CrashReportUtils { Throwable temp = throwable; while (temp != null) { temp = temp.getCause(); - if (temp instanceof ReportedException reportedException) { - return essential(reportedException, task); + if (temp instanceof ReportedException) { + return essential(temp, task); } } CrashReport report = CrashReport.forThrowable(throwable, task); -- cgit From 3a84bfa28bb233b3a6f0a14f2e90956a98512453 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Oct 2021 02:43:32 +0800 Subject: Add tag match & JEI recipe ids --- .../gui/screen/DefaultDisplayViewingScreen.java | 43 ++++++++++++++++++++++ .../rei/impl/client/gui/widget/EntryWidget.java | 9 +++++ .../impl/client/gui/widget/InternalWidgets.java | 3 +- 3 files changed, 54 insertions(+), 1 deletion(-) (limited to 'runtime/src/main/java/me') 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 08fa19f81..c190033b2 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 @@ -29,6 +29,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; +import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -46,6 +47,9 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; @@ -67,7 +71,11 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -246,8 +254,12 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { 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 = getCurrentCategory().setupDisplay(display, displayBounds); + setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = true; + } recipeBounds.put(displayBounds, setupDisplay); this.widgets.addAll(setupDisplay); if (supplier.isPresent() && supplier.get().get(displayBounds) != null) @@ -287,6 +299,37 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { _children().addAll(preWidgets); } + private void setupTags(List widgets) { + TagContainer tags = Minecraft.getInstance().getConnection().getTags(); + outer: + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = false; + if (widget.getEntries().size() <= 1) continue; + EntryType type = null; + for (EntryStack entry : widget.getEntries()) { + if (type == null) { + type = entry.getType(); + } else if (type != entry.getType()) { + continue outer; + } + } + // TODO: Don't hardcode + TagCollection collection; + List objects; + if (type == VanillaEntryTypes.ITEM) { + collection = tags.getItems(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); + } else if (type == VanillaEntryTypes.FLUID) { + collection = tags.getFluids(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); + } else continue; + Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); + if (firstOrNull != null) { + widget.tagMatch = firstOrNull.getKey(); + } + } + } + public List getWidgets() { return widgets; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index 053186a50..f1693459b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -43,12 +43,14 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; +import net.minecraft.ChatFormatting; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; @@ -77,6 +79,8 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { protected boolean wasClicked = false; private Rectangle bounds; private List> entryStacks; + public ResourceLocation tagMatch; + public boolean removeTagMatch = true; public EntryWidget(Point point) { this(new Rectangle(point.x - 1, point.y - 1, 18, 18)); @@ -231,6 +235,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { } entryStacks.add(stack); } + if (removeTagMatch) tagMatch = null; return this; } @@ -241,6 +246,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { entryStacks = new ArrayList<>(entryStacks); } entryStacks.addAll(stacks); + if (removeTagMatch) tagMatch = null; } return this; } @@ -318,6 +324,9 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { tooltip.addAllTexts(Stream.of(I18n.get("text.rei.favorites_tooltip", name).split("\n")) .map(TextComponent::new).collect(Collectors.toList())); } + if (tagMatch != null) { + tooltip.add(new TranslatableComponent("text.rei.tag_match", tagMatch.toString()).withStyle(ChatFormatting.GRAY)); + } tooltip.queue(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java index 8df053102..1529a9e4b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java @@ -48,6 +48,7 @@ import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; @@ -176,7 +177,7 @@ public final class InternalWidgets { str.add(errorTooltip[0].get(0).copy().withStyle(ChatFormatting.RED)); } } - if (Minecraft.getInstance().options.advancedItemTooltips && displaySupplier.get().getDisplayLocation().isPresent()) { + if ((Minecraft.getInstance().options.advancedItemTooltips || Screen.hasShiftDown()) && displaySupplier.get().getDisplayLocation().isPresent()) { str.add(new TranslatableComponent("text.rei.recipe_id", "", new TextComponent(displaySupplier.get().getDisplayLocation().get().toString()).withStyle(ChatFormatting.GRAY)).withStyle(ChatFormatting.GRAY)); } return str.toArray(new Component[0]); -- cgit From 6e7a641926d8b0ea2d0a1caddbf348fe24b669ce Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 00:37:19 +0800 Subject: Fix JEI recipes duplicating and going to the wrong category, Fix JER's insane resource reload during plugin application, Add DisplayAdditionReason, Safeguard DisplayCategory#setupDisplay --- .../gui/screen/AbstractDisplayViewingScreen.java | 40 ++++++++++++++++ .../gui/screen/CompositeDisplayViewingScreen.java | 17 ++++++- .../gui/screen/DefaultDisplayViewingScreen.java | 55 +++++----------------- .../registry/display/DisplayRegistryImpl.java | 23 ++++++--- .../rei/impl/common/plugins/PluginManagerImpl.java | 49 +++++++++++++++---- 5 files changed, 122 insertions(+), 62 deletions(-) (limited to 'runtime/src/main/java/me') 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 0d69d3fce..48aea3c1a 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 @@ -24,6 +24,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; +import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Slot; @@ -33,12 +34,20 @@ 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; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; +import net.minecraft.tags.TagContainer; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -151,4 +160,35 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis } } } + + protected void setupTags(List widgets) { + TagContainer tags = Minecraft.getInstance().getConnection().getTags(); + outer: + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = false; + if (widget.getEntries().size() <= 1) continue; + EntryType type = null; + for (EntryStack entry : widget.getEntries()) { + if (type == null) { + type = entry.getType(); + } else if (type != entry.getType()) { + continue outer; + } + } + // TODO: Don't hardcode + TagCollection collection; + List objects; + if (type == VanillaEntryTypes.ITEM) { + collection = tags.getItems(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); + } else if (type == VanillaEntryTypes.FLUID) { + collection = tags.getFluids(); + objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); + } else continue; + Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); + if (firstOrNull != null) { + widget.tagMatch = firstOrNull.getKey(); + } + } + } } 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 b2b86fb47..5d1d66a98 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 @@ -47,6 +47,7 @@ import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; +import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.TabWidget; import net.minecraft.client.Minecraft; @@ -61,6 +62,7 @@ import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -152,9 +154,22 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen this.widgets.add(Widgets.createSlotBase(scrollListBounds)); Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); - List setupDisplay = category.setupDisplay(display, recipeBounds); + List setupDisplay; + try { + setupDisplay = category.setupDisplay(display, recipeBounds); + } catch (Throwable throwable) { + throwable.printStackTrace(); + setupDisplay = new ArrayList<>(); + setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + } + setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); + for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { + widget.removeTagMatch = true; + } this.widgets.addAll(setupDisplay); Optional supplier = CategoryRegistry.getInstance().get(category.getCategoryIdentifier()).getPlusButtonArea(); if (supplier.isPresent() && supplier.get().get(recipeBounds) != null) 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 c190033b2..52e5b3a67 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 @@ -29,7 +29,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; -import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -47,9 +46,6 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.EntryType; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; @@ -71,18 +67,11 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; -import net.minecraft.tags.Tag; -import net.minecraft.tags.TagCollection; -import net.minecraft.tags.TagContainer; import net.minecraft.util.Mth; -import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.function.Supplier; @ApiStatus.Internal @@ -253,7 +242,16 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { final Supplier displaySupplier = () -> display; 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 = getCurrentCategory().setupDisplay(display, displayBounds); + List setupDisplay; + try { + setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); + } catch (Throwable throwable) { + throwable.printStackTrace(); + setupDisplay = new ArrayList<>(); + setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); + setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + } setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); transformResultNotice(setupDisplay, resultStackToNotice); @@ -299,37 +297,6 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { _children().addAll(preWidgets); } - private void setupTags(List widgets) { - TagContainer tags = Minecraft.getInstance().getConnection().getTags(); - outer: - for (EntryWidget widget : Widgets.walk(widgets, EntryWidget.class::isInstance)) { - widget.removeTagMatch = false; - if (widget.getEntries().size() <= 1) continue; - EntryType type = null; - for (EntryStack entry : widget.getEntries()) { - if (type == null) { - type = entry.getType(); - } else if (type != entry.getType()) { - continue outer; - } - } - // TODO: Don't hardcode - TagCollection collection; - List objects; - if (type == VanillaEntryTypes.ITEM) { - collection = tags.getItems(); - objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); - } else if (type == VanillaEntryTypes.FLUID) { - collection = tags.getFluids(); - objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); - } else continue; - Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); - if (firstOrNull != null) { - widget.tagMatch = firstOrNull.getKey(); - } - } - } - public List getWidgets() { return widgets; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java index e638f14fd..bfc975188 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java @@ -31,6 +31,8 @@ import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReason; +import me.shedaniel.rei.api.client.registry.display.reason.DisplayAdditionReasons; import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; @@ -41,6 +43,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; @@ -139,9 +142,14 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl typeClass.isInstance(o) && ((Predicate) predicate).test((T) o), o -> ((Function) filler).apply((T) o)); } + @Override + public void registerFiller(Class typeClass, BiPredicate predicate, Function filler) { + fillers.add(new DisplayFiller<>((o, s) -> typeClass.isInstance(o) && ((BiPredicate) predicate).test(o, s), (Function) filler)); + } + @Override public void registerFiller(Predicate predicate, Function filler) { - fillers.add(new DisplayFiller<>((Predicate) predicate, (Function) filler)); + fillers.add(new DisplayFiller<>((o, s) -> ((Predicate) predicate).test(o), (Function) filler)); } @Override @@ -160,17 +168,18 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl> allSortedRecipes = getAllSortedRecipes(); for (int i = allSortedRecipes.size() - 1; i >= 0; i--) { Recipe recipe = allSortedRecipes.get(i); - add(recipe); + addWithReason(recipe, DisplayAdditionReason.RECIPE_MANAGER); } } } @Override - public Collection tryFillDisplay(T value) { + public Collection tryFillDisplay(T value, DisplayAdditionReason... reason) { if (value instanceof Display) return Collections.singleton((Display) value); List displays = null; + DisplayAdditionReasons reasons = reason.length == 0 ? DisplayAdditionReasons.Impl.EMPTY : new DisplayAdditionReasons.Impl(reason); for (DisplayFiller filler : fillers) { - Display display = tryFillDisplayGenerics(filler, value); + Display display = tryFillDisplayGenerics(filler, value, reasons); if (display != null) { if (displays == null) displays = Collections.singletonList(display); else { @@ -185,9 +194,9 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl D tryFillDisplayGenerics(DisplayFiller filler, Object value) { + private D tryFillDisplayGenerics(DisplayFiller filler, Object value, DisplayAdditionReasons reasons) { try { - if (filler.predicate.test(value)) { + if (filler.predicate.test(value, reasons)) { return filler.mappingFunction.apply(value); } } catch (Throwable e) { @@ -204,7 +213,7 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl( - Predicate predicate, + BiPredicate predicate, Function mappingFunction ) {} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 82bc8f518..f3421e76e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -23,10 +23,13 @@ package me.shedaniel.rei.impl.common.plugins; -import com.google.common.base.MoreObjects; import com.google.common.base.Stopwatch; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; +import me.shedaniel.architectury.platform.Platform; +import me.shedaniel.architectury.utils.Env; +import me.shedaniel.architectury.utils.EnvExecutor; +import me.shedaniel.architectury.utils.GameInstance; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; @@ -36,8 +39,11 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.CollectionUtils; import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.server.MinecraftServer; import org.apache.commons.lang3.tuple.MutablePair; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.io.Closeable; import java.util.*; @@ -103,7 +109,7 @@ public class PluginManagerImpl

> implements PluginManager< @Override public void registerPlugin(REIPluginProvider plugin) { plugins.add((REIPluginProvider

) plugin); - RoughlyEnoughItemsCore.LOGGER.info("Registered plugin provider %s for %s", plugin.getPluginProviderName(), pluginClass.getSimpleName()); + RoughlyEnoughItemsCore.LOGGER.info("Registered plugin provider %s for %s", plugin.getPluginProviderName(), name(pluginClass)); } @Override @@ -139,23 +145,40 @@ public class PluginManagerImpl

> implements PluginManager< return new SectionClosable(sectionData, section); } - private void pluginSection(MutablePair sectionData, String sectionName, List

list, Consumer

consumer) { + private void pluginSection(MutablePair sectionData, String sectionName, List

list, @Nullable Reloadable reloadable, Consumer

consumer) { for (P plugin : list) { try (SectionClosable section = section(sectionData, sectionName + " for " + plugin.getPluginProviderName())) { - consumer.accept(plugin); + if (reloadable == null || !plugin.shouldBeForcefullyDoneOnMainThread(reloadable)) { + consumer.accept(plugin); + } else if (Platform.getEnvironment() == Env.CLIENT) { + EnvExecutor.runInEnv(Env.CLIENT, () -> () -> queueExecutionClient(() -> consumer.accept(plugin))); + } else { + queueExecution(() -> consumer.accept(plugin)); + } } catch (Throwable throwable) { RoughlyEnoughItemsCore.LOGGER.error(plugin.getPluginProviderName() + " plugin failed to " + sectionName + "!", throwable); } } } + private void queueExecution(Runnable runnable) { + MinecraftServer server = GameInstance.getServer(); + if (server != null) { + server.executeBlocking(runnable); + } + } + + private void queueExecutionClient(Runnable runnable) { + Minecraft.getInstance().executeBlocking(runnable); + } + @Override public void pre() { List

plugins = new ArrayList<>(getPlugins().toList()); plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); Collections.reverse(plugins); MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); - pluginSection(sectionData, "pre-register", plugins, REIPlugin::preRegister); + pluginSection(sectionData, "pre-register", plugins, null, REIPlugin::preRegister); } @Override @@ -164,7 +187,13 @@ public class PluginManagerImpl

> implements PluginManager< plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); Collections.reverse(plugins); MutablePair sectionData = new MutablePair<>(Stopwatch.createUnstarted(), ""); - pluginSection(sectionData, "post-register", plugins, REIPlugin::postRegister); + pluginSection(sectionData, "post-register", plugins, null, REIPlugin::postRegister); + } + + private static String name(Class clazz) { + String simpleName = clazz.getSimpleName(); + if (simpleName.isEmpty()) return clazz.getName(); + return simpleName; } @Override @@ -176,7 +205,7 @@ public class PluginManagerImpl

> implements PluginManager< for (Reloadable

reloadable : reloadables) { Class reloadableClass = reloadable.getClass(); - try (SectionClosable startReload = section(sectionData, "start-reload-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()))) { + try (SectionClosable startReload = section(sectionData, "start-reload-" + name(reloadableClass))) { reloadable.startReload(stage); } catch (Throwable throwable) { throwable.printStackTrace(); @@ -185,17 +214,17 @@ public class PluginManagerImpl

> implements PluginManager< List

plugins = new ArrayList<>(getPlugins().toList()); plugins.sort(Comparator.comparingDouble(P::getPriority).reversed()); - RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s] stage [%s], registered %d plugins: %s", pluginClass.getSimpleName(), stage.toString(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, REIPlugin::getPluginProviderName, ", ")); + RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s] stage [%s], registered %d plugins: %s", name(pluginClass), stage.toString(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, REIPlugin::getPluginProviderName, ", ")); Collections.reverse(plugins); for (Reloadable

reloadable : getReloadables()) { Class reloadableClass = reloadable.getClass(); - pluginSection(sectionData, "reloadable-plugin-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()), plugins, plugin -> reloadable.acceptPlugin(plugin, stage)); + pluginSection(sectionData, "reloadable-plugin-" + name(reloadableClass), plugins, reloadable, plugin -> reloadable.acceptPlugin(plugin, stage)); } for (Reloadable

reloadable : reloadables) { Class reloadableClass = reloadable.getClass(); - try (SectionClosable endReload = section(sectionData, "end-reload-" + MoreObjects.firstNonNull(reloadableClass.getSimpleName(), reloadableClass.getName()))) { + try (SectionClosable endReload = section(sectionData, "end-reload-" + name(reloadableClass))) { reloadable.endReload(stage); } catch (Throwable throwable) { throwable.printStackTrace(); -- cgit From 1dcf535cdf25c808ee4c0827a27c5b0e50094fda Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 00:59:29 +0800 Subject: Fix merge conflicts --- .../rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java | 7 ++++--- .../me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'runtime/src/main/java/me') 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 48aea3c1a..c9015efa3 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 @@ -24,7 +24,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; -import me.shedaniel.architectury.fluid.FluidStack; +import dev.architectury.fluid.FluidStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.Slot; @@ -43,6 +43,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.tags.TagCollection; @@ -179,10 +180,10 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis TagCollection collection; List objects; if (type == VanillaEntryTypes.ITEM) { - collection = tags.getItems(); + collection = tags.getOrEmpty(Registry.ITEM_REGISTRY); objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getItem()); } else if (type == VanillaEntryTypes.FLUID) { - collection = tags.getFluids(); + collection = tags.getOrEmpty(Registry.FLUID_REGISTRY); objects = CollectionUtils.map(widget.getEntries(), stack -> stack.castValue().getFluid()); } else continue; Map.Entry> firstOrNull = CollectionUtils.findFirstOrNull(collection.getAllTags().entrySet(), entry -> entry.getValue().getValues().equals(objects)); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index f3421e76e..5969aada1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -26,10 +26,10 @@ package me.shedaniel.rei.impl.common.plugins; import com.google.common.base.Stopwatch; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; -import me.shedaniel.architectury.platform.Platform; -import me.shedaniel.architectury.utils.Env; -import me.shedaniel.architectury.utils.EnvExecutor; -import me.shedaniel.architectury.utils.GameInstance; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import dev.architectury.utils.EnvExecutor; +import dev.architectury.utils.GameInstance; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; -- cgit From 23e61ae08a66fa07f045c91bcbe2d46f705deacd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 01:06:55 +0800 Subject: Remove favorites dragging overlay --- .../me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java index e89ff560e..5041887a4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java @@ -276,7 +276,7 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt @Override public Stream getDraggableAcceptingBounds(DraggingContext context, DraggableStack stack) { - return checkDraggedStacks(context, stack).isPresent() ? Stream.of(DraggableStackVisitor.BoundsProvider.ofShape(buildBounds())) : Stream.empty(); + return Stream.empty(); } private VoxelShape buildBounds() { -- cgit From 2b5c4148b5964309d80f731d67d14675981c0e18 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 16 Oct 2021 03:02:14 +0800 Subject: Try to remove excessive spacing and keep the top bar stationary --- .../rei/impl/client/config/ConfigObjectImpl.java | 2 +- .../gui/screen/CompositeDisplayViewingScreen.java | 6 +- .../gui/screen/DefaultDisplayViewingScreen.java | 116 ++++++++++++--------- 3 files changed, 68 insertions(+), 56 deletions(-) (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 089819553..fba1fd4c2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -493,7 +493,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private EntryPanelOrderingConfig entryPanelOrdering = EntryPanelOrderingConfig.REGISTRY_ASCENDING; @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99) - private int maxRecipesPerPage = 15; + private int maxRecipesPerPage = 3; @Comment("Declares whether entry rendering time should be debugged.") private boolean debugRenderTimeRequired = false; } 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 5d1d66a98..115d44f3d 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 @@ -160,9 +160,9 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen } catch (Throwable throwable) { throwable.printStackTrace(); setupDisplay = new ArrayList<>(); - setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); - setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); - setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + setupDisplay.add(Widgets.createRecipeBase(recipeBounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.createLabel(new Point(recipeBounds.getCenterX(), recipeBounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); + setupDisplay.add(Widgets.createLabel(new Point(recipeBounds.getCenterX(), recipeBounds.getCenterY() + 1), new TextComponent("Check console for error"))); } setupTags(setupDisplay); transformIngredientNotice(setupDisplay, ingredientStackToNotice); 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 52e5b3a67..cca34512f 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 @@ -112,9 +112,9 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { return true; } if (keyCode == 258 && !minecraft.options.keyInventory.matches(keyCode, scanCode)) { - boolean boolean_1 = !hasShiftDown(); - if (!this.changeFocus(boolean_1)) - this.changeFocus(boolean_1); + boolean next = !hasShiftDown(); + if (!this.changeFocus(next)) + this.changeFocus(next); return true; } if (choosePageActivated) @@ -149,26 +149,30 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { @Override public void init() { super.init(); - boolean isCompactTabs = ConfigObject.getInstance().isUsingCompactTabs(); - int tabSize = isCompactTabs ? 24 : 28; this.children().clear(); this.recipeBounds.clear(); this.tabs.clear(); this.preWidgets.clear(); this.widgets.clear(); - int largestWidth = width - 100; int largestHeight = Math.max(height - 34 - 30, 100); 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) { - this.categoryPages = Math.max(0, selectedCategoryIndex / tabsPerPage); - } - this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - largestHeight / 2, guiWidth, largestHeight); + int maxHeight = CollectionUtils., Integer>mapAndMax(categories, + category -> (category.getDisplayHeight() + 4) * Math.max(1, getRecipesPerPage(largestHeight, category) + 1) + 36, Comparator.naturalOrder()).orElse(66); + int totalDisplayHeight = (getCurrentCategory().getDisplayHeight() + 4) * Math.max(1, getRecipesPerPage(maxHeight, getCurrentCategory()) + 1) + 36; + int guiWidth = Math.max(maxWidthDisplay + 10, 190); + this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - maxHeight / 2, guiWidth, Math.min(maxHeight, totalDisplayHeight)); if (ConfigObject.getInstance().isSubsetsEnabled()) { this.bounds.setLocation(this.bounds.getX(), this.bounds.getY() + 15); this.bounds.setSize(this.bounds.getWidth(), this.bounds.getHeight() - 10); } + + boolean isCompactTabs = ConfigObject.getInstance().isUsingCompactTabs(); + int tabSize = isCompactTabs ? 24 : 28; + this.tabsPerPage = Math.max(5, Mth.floor((guiWidth - 20d) / tabSize)); + if (this.categoryPages == -1) { + this.categoryPages = Math.max(0, selectedCategoryIndex / tabsPerPage); + } + this.page = Mth.clamp(page, 0, getCurrentTotalPages() - 1); this.widgets.add(Widgets.createButton(new Rectangle(bounds.x, bounds.y - 16, 10, 10), new TranslatableComponent("text.rei.left_arrow")) .onClick(button -> { @@ -186,71 +190,81 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { DefaultDisplayViewingScreen.this.init(); }) .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")) + this.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), getCurrentCategory().getTitle(), clickableLabelWidget -> { + this.widgets.add(Widgets.createClickableLabel(new Point(bounds.getCenterX(), bounds.getY() + 7), getCurrentCategory().getTitle(), clickableLabelWidget -> { ViewSearchBuilder.builder().addAllCategories().open(); }).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")) + this.widgets.add(categoryNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), new TranslatableComponent("text.rei.right_arrow")) .onClick(button -> nextCategory()).tooltipLine(new TranslatableComponent("text.rei.next_category"))); - categoryBack.setEnabled(categories.size() > 1); - categoryNext.setEnabled(categories.size() > 1); - - widgets.add(recipeBack = Widgets.createButton(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), new TranslatableComponent("text.rei.left_arrow")) + this.categoryBack.setEnabled(categories.size() > 1); + this.categoryNext.setEnabled(categories.size() > 1); + + this.widgets.add(recipeBack = Widgets.createButton(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), new TranslatableComponent("text.rei.left_arrow")) .onClick(button -> { page--; if (page < 0) page = getCurrentTotalPages() - 1; DefaultDisplayViewingScreen.this.init(); }).tooltipLine(new TranslatableComponent("text.rei.previous_page"))); - widgets.add(Widgets.createClickableLabel(new Point(bounds.getCenterX(), bounds.getY() + 21), NarratorChatListener.NO_TITLE, label -> { + this.widgets.add(Widgets.createClickableLabel(new Point(bounds.getCenterX(), bounds.getY() + 21), NarratorChatListener.NO_TITLE, label -> { DefaultDisplayViewingScreen.this.choosePageActivated = true; DefaultDisplayViewingScreen.this.init(); }).onRender((matrices, label) -> { label.setMessage(new ImmutableTextComponent(String.format("%d/%d", page + 1, getCurrentTotalPages()))); label.setClickable(getCurrentTotalPages() > 1); }).tooltipSupplier(label -> label.isClickable() ? I18n.get("text.rei.choose_page") : null)); - widgets.add(recipeNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), new TranslatableComponent("text.rei.right_arrow")) + this.widgets.add(recipeNext = Widgets.createButton(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), new TranslatableComponent("text.rei.right_arrow")) .onClick(button -> { page++; if (page >= getCurrentTotalPages()) page = 0; DefaultDisplayViewingScreen.this.init(); }).tooltipLine(new TranslatableComponent("text.rei.next_page"))); - recipeBack.setEnabled(getCurrentTotalPages() > 1); - recipeNext.setEnabled(getCurrentTotalPages() > 1); - int tabV = isCompactTabs ? 166 : 192; - for (int i = 0; i < tabsPerPage; i++) { - int j = i + categoryPages * tabsPerPage; - if (categories.size() > j) { + this.recipeBack.setEnabled(getCurrentTotalPages() > 1); + this.recipeNext.setEnabled(getCurrentTotalPages() > 1); + for (int id = 0; id < tabsPerPage; id++) { + int tabIndex = id + categoryPages * tabsPerPage; + if (categories.size() > tabIndex) { TabWidget tab; - tabs.add(tab = TabWidget.create(i, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - categoryPages * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, tabV, widget -> { + tabs.add(tab = TabWidget.create(id, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - categoryPages * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, isCompactTabs ? 166 : 192, widget -> { Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); if (widget.getId() + categoryPages * tabsPerPage == selectedCategoryIndex) return false; ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(widget.getId() + categoryPages * tabsPerPage).getCategoryIdentifier(), ingredientStackToNotice, resultStackToNotice); return true; })); - tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getTitle(), tab.getId() + categoryPages * tabsPerPage == selectedCategoryIndex); + tab.setRenderer(categories.get(tabIndex), categories.get(tabIndex).getIcon(), categories.get(tabIndex).getTitle(), tab.getId() + categoryPages * tabsPerPage == selectedCategoryIndex); } } - Optional supplier = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getPlusButtonArea(); - int recipeHeight = getCurrentCategory().getDisplayHeight(); + + choosePageWidget = choosePageActivated ? new DefaultDisplayChoosePageWidget(this, page, getCurrentTotalPages()) : null; + initDisplays(); + initWorkstations(preWidgets); + + _children().addAll(tabs); + _children().addAll(widgets); + _children().addAll(preWidgets); + } + + private void initDisplays() { + Optional plusButtonArea = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getPlusButtonArea(); + int displayHeight = 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 = 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); + final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().getCenterY() + 16 - displayHeight * (getRecipesPerPage() + 1) / 2 - 2 * (getRecipesPerPage() + 1) + displayHeight * i + 4 * i, displayWidth, displayHeight); List setupDisplay; try { setupDisplay = getCurrentCategory().setupDisplay(display, displayBounds); } catch (Throwable throwable) { throwable.printStackTrace(); setupDisplay = new ArrayList<>(); - setupDisplay.add(Widgets.createRecipeBase(bounds).color(0xFFBB0000)); - setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() - 8), new TextComponent("Failed to initiate setupDisplay"))); - setupDisplay.add(Widgets.createLabel(new Point(bounds.getCenterX(), bounds.getCenterY() + 1), new TextComponent("Check console for error"))); + setupDisplay.add(Widgets.createRecipeBase(displayBounds).color(0xFFBB0000)); + setupDisplay.add(Widgets.crea