aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/impl/client
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-01-27 21:44:50 +0800
committershedaniel <daniel@shedaniel.me>2022-01-27 22:05:59 +0800
commit7e6321f649111cdeb0b391ef3203864247bd7b9d (patch)
treec5532344f3cdde505afb00f3b75fd16152371702 /runtime/src/main/java/me/shedaniel/rei/impl/client
parentef23b11140085651287ce35deca87723daf34e78 (diff)
downloadRoughlyEnoughItems-7e6321f649111cdeb0b391ef3203864247bd7b9d.tar.gz
RoughlyEnoughItems-7e6321f649111cdeb0b391ef3203864247bd7b9d.tar.bz2
RoughlyEnoughItems-7e6321f649111cdeb0b391ef3203864247bd7b9d.zip
Fix #730
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl/client')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java17
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java16
2 files changed, 9 insertions, 24 deletions
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 aa2215d7b..ade7f3489 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
@@ -50,15 +50,12 @@ import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
import me.shedaniel.rei.api.client.overlay.OverlayListWidget;
import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
-import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.screen.ClickArea;
import me.shedaniel.rei.api.client.registry.screen.OverlayDecider;
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.client.view.ViewSearchBuilder;
-import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.entry.EntryStack;
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.client.ClientHelperImpl;
@@ -85,12 +82,10 @@ 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.network.chat.Component;
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.item.ItemStack;
@@ -618,10 +613,9 @@ public class ScreenOverlayImpl extends ScreenOverlay {
return new Point(mouseX, mouseY);
}
};
- Set<CategoryIdentifier<?>> categories = ScreenRegistry.getInstance().handleClickArea((Class<Screen>) screen.getClass(), context);
- if (categories != null && !categories.isEmpty()) {
- Component collect = CollectionUtils.mapAndJoinToComponent(categories, identifier -> CategoryRegistry.getInstance().tryGet(identifier).map(config -> config.getCategory().getTitle()).orElse(new ImmutableTextComponent(identifier.toString())), new ImmutableTextComponent(", "));
- Tooltip.create(new TranslatableComponent("text.rei.view_recipes_for", collect)).queue();
+ List<Component> clickAreaTooltips = ScreenRegistry.getInstance().getClickAreaTooltips((Class<Screen>) screen.getClass(), context);
+ if (clickAreaTooltips != null && !clickAreaTooltips.isEmpty()) {
+ Tooltip.create(clickAreaTooltips).queue();
}
}
}
@@ -877,10 +871,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
return new Point(mouseX, mouseY);
}
};
- Set<CategoryIdentifier<?>> categories = ScreenRegistry.getInstance().handleClickArea((Class<Screen>) screen.getClass(), context);
- if (categories != null && !categories.isEmpty()) {
- ViewSearchBuilder.builder().addCategories(categories).open();
- Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
+ if (ScreenRegistry.getInstance().executeClickArea((Class<Screen>) screen.getClass(), context)) {
return true;
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
index 89d9031fb..6c401dd83 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
@@ -50,13 +50,11 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.inventory.AbstractContainerMenu;
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.commons.lang3.BooleanUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.*;
-import java.util.stream.Collectors;
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
@@ -212,20 +210,16 @@ public class ScreenRegistryImpl implements ScreenRegistry {
}
@Override
- @Nullable
- public <T extends Screen> Set<CategoryIdentifier<?>> handleClickArea(Class<T> screenClass, ClickArea.ClickAreaContext<T> context) {
- Mutable<Set<CategoryIdentifier<?>>> categories = new MutableObject<>(null);
+ public <T extends Screen> List<ClickArea.Result> evaluateClickArea(Class<T> screenClass, ClickArea.ClickAreaContext<T> context) {
+ List<ClickArea.Result> results = new ArrayList<>();
for (ClickArea<?> area : this.clickAreas.get(screenClass)) {
ClickArea.Result result = ((ClickArea<T>) area).handle(context);
if (result.isSuccessful()) {
- if (categories.getValue() == null) {
- categories.setValue(new LinkedHashSet<>());
- }
- result.getCategories().collect(Collectors.toCollection(categories::getValue));
+ results.add(result);
}
}
- return categories.getValue();
+ return results;
}
@Override