Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,25 +259,6 @@ private static void transformNotice(int marker, List<? extends GuiEventListener>
}
}

@SuppressWarnings("RedundantCast")
protected void transformFiltering(List<? extends GuiEventListener> setupDisplay) {
for (EntryWidget widget : Widgets.<EntryWidget>walk(setupDisplay, EntryWidget.class::isInstance)) {
if (widget.getEntries().size() > 1) {
Collection<EntryStack<?>> refiltered = EntryRegistry.getInstance().refilterNew(false, widget.getEntries());
EntryIngredient asEntryIngredient = widget.getEntries() instanceof EntryIngredient ingredient ? ingredient : null;
if (!refiltered.isEmpty() && !widget.getEntries().equals(refiltered)) {
widget.clearStacks();
EntryIngredient newIngredient = EntryIngredient.of(refiltered);
if (asEntryIngredient != null && (Object) asEntryIngredient.getSetting(EntryIngredientSetting.FOCUS_UUID) instanceof UUID uuid) {
newIngredient.setting(EntryIngredientSetting.FOCUS_UUID,
new UUID(uuid.getMostSignificantBits() ^ refiltered.size(), uuid.getLeastSignificantBits() ^ refiltered.size()));
}
widget.entries(newIngredient);
}
}
}
}

protected static long hashFocusIngredient(EntryIngredient ingredient) {
UUID uuid = ingredient.getSetting(EntryIngredientSetting.FOCUS_UUID);
if (uuid == null) return System.identityHashCode(ingredient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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.util.SetupDisplayUtils;
import me.shedaniel.rei.impl.display.DisplaySpec;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void init() {
setupDisplay.add(Widgets.createLabel(new Point(recipeBounds.getCenterX(), recipeBounds.getCenterY() + 1), Component.literal("Check console for error")));
}
setupTags(setupDisplay);
transformFiltering(setupDisplay);
SetupDisplayUtils.TransformFiltering(setupDisplay);
transformIngredientNotice(setupDisplay, ingredientStackToNotice);
transformResultNotice(setupDisplay, resultStackToNotice);
unifyIngredients(setupDisplay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import me.shedaniel.rei.impl.client.gui.toast.ExportRecipeIdentifierToast;
import me.shedaniel.rei.impl.client.gui.widget.*;
import me.shedaniel.rei.impl.client.gui.widget.basewidgets.PanelWidget;
import me.shedaniel.rei.impl.client.util.SetupDisplayUtils;
import me.shedaniel.rei.impl.display.DisplaySpec;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -253,7 +254,7 @@ private void initDisplays() {
setupDisplay.add(Widgets.createLabel(new Point(displayBounds.getCenterX(), displayBounds.getCenterY() + 1), Component.literal("Check console for error")));
}
setupTags(setupDisplay);
transformFiltering(setupDisplay);
SetupDisplayUtils.TransformFiltering(setupDisplay);
transformIngredientNotice(setupDisplay, ingredientStackToNotice);
transformResultNotice(setupDisplay, resultStackToNotice);
unifyIngredients(setupDisplay);
Expand Down Expand Up @@ -445,7 +446,7 @@ private boolean checkExportDisplays() {
setupDisplay.add(Widgets.createLabel(new Point(displayBounds.getCenterX(), displayBounds.getCenterY() + 1), Component.literal("Check console for error")));
}
setupTags(setupDisplay);
transformFiltering(setupDisplay);
SetupDisplayUtils.TransformFiltering(setupDisplay);
transformIngredientNotice(setupDisplay, ingredientStackToNotice);
transformResultNotice(setupDisplay, resultStackToNotice);
unifyIngredients(setupDisplay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import me.shedaniel.rei.api.client.util.MatrixUtils;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.impl.client.util.SetupDisplayUtils;
import me.shedaniel.rei.impl.display.DisplaySpec;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand All @@ -60,6 +61,7 @@ public DisplayTooltipComponent(DisplaySpec display) {
DisplayCategory<Display> category = configuration.getCategory();
this.bounds = new Rectangle(0, 0, category.getDisplayWidth(internalDisplay), category.getDisplayHeight());
List<Widget> widgets = configuration.getView(internalDisplay).setupDisplay(internalDisplay, bounds);
SetupDisplayUtils.TransformFiltering(widgets);

this.display = display;
this.widgets = widgets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.impl.client.ClientHelperImpl;
import me.shedaniel.rei.impl.client.gui.widget.AutoCraftingEvaluator;
import me.shedaniel.rei.impl.client.util.SetupDisplayUtils;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -125,7 +126,9 @@ private List<Widget> setupWidgets() {

private List<Widget> setupDisplay(CategoryRegistry.CategoryConfiguration<Display> configuration, Rectangle displayBounds) {
try {
return configuration.getView(display).setupDisplay(display, displayBounds);
List<Widget> widgets = configuration.getView(display).setupDisplay(display, displayBounds);
SetupDisplayUtils.TransformFiltering(widgets);
return widgets;
} catch (Throwable throwable) {
throwable.printStackTrace();
List<Widget> w = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is licensed under the MIT License, part of Roughly Enough Items.
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.util;

import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.settings.EntryIngredientSetting;
import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
import net.minecraft.client.gui.components.events.GuiEventListener;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

public class SetupDisplayUtils {
@SuppressWarnings("RedundantCast")
public static void TransformFiltering(List<? extends GuiEventListener> setupDisplay) {
for (EntryWidget widget : Widgets.<EntryWidget>walk(setupDisplay, EntryWidget.class::isInstance)) {
if (widget.getEntries().size() > 1) {
Collection<EntryStack<?>> refiltered = EntryRegistry.getInstance().refilterNew(false, widget.getEntries());
EntryIngredient asEntryIngredient = widget.getEntries() instanceof EntryIngredient ingredient ? ingredient : null;
if (!refiltered.isEmpty() && !widget.getEntries().equals(refiltered)) {
widget.clearStacks();
EntryIngredient newIngredient = EntryIngredient.of(refiltered);
if (asEntryIngredient != null && (Object) asEntryIngredient.getSetting(EntryIngredientSetting.FOCUS_UUID) instanceof UUID uuid) {
newIngredient.setting(EntryIngredientSetting.FOCUS_UUID,
new UUID(uuid.getMostSignificantBits() ^ refiltered.size(), uuid.getLeastSignificantBits() ^ refiltered.size()));
}
widget.entries(newIngredient);
}
}
}
}
}