aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-01-27 21:44:50 +0800
committershedaniel <daniel@shedaniel.me>2022-01-27 21:44:50 +0800
commitac2c8ad0d6e27682b8a05dabd9f7a08f7c25e096 (patch)
tree654d4a8a2d0dd230c86e42c1aec04c8e1dfdacc4 /runtime/src/main/java
parent3efbe517ff76a29b3c5b62809a8d0a58b9f2c15a (diff)
downloadRoughlyEnoughItems-ac2c8ad0d6e27682b8a05dabd9f7a08f7c25e096.tar.gz
RoughlyEnoughItems-ac2c8ad0d6e27682b8a05dabd9f7a08f7c25e096.tar.bz2
RoughlyEnoughItems-ac2c8ad0d6e27682b8a05dabd9f7a08f7c25e096.zip
Fix #730
Diffstat (limited to 'runtime/src/main/java')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java40
-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.java15
3 files changed, 48 insertions, 24 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
index bacfe9409..92976ca38 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java
@@ -51,7 +51,9 @@ import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.plugins.PluginView;
import me.shedaniel.rei.api.common.registry.ReloadStage;
+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.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
@@ -87,6 +89,7 @@ import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.CompoundTag;
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.world.InteractionResult;
import net.minecraft.world.inventory.CraftingMenu;
@@ -105,6 +108,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiFunction;
+import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -139,6 +143,26 @@ public class RoughlyEnoughItemsCoreClient {
ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection<Component>, Tooltip>) QueuedTooltip::impl, "tooltipProvider");
ClientInternals.attachInstance((Function<@Nullable Boolean, ClickArea.Result>) successful -> new ClickArea.Result() {
private List<CategoryIdentifier<?>> categories = Lists.newArrayList();
+ private BooleanSupplier execute = () -> {
+ return false;
+ };
+ private Supplier<Component @Nullable []> tooltip = () -> {
+ 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(", "));
+ return new Component[]{new TranslatableComponent("text.rei.view_recipes_for", collect)};
+ }
+
+ return null;
+ };
+
+ @Override
+ public ClickArea.Result executor(BooleanSupplier task) {
+ this.execute = task;
+ return this;
+ }
@Override
public ClickArea.Result category(CategoryIdentifier<?> category) {
@@ -147,11 +171,27 @@ public class RoughlyEnoughItemsCoreClient {
}
@Override
+ public ClickArea.Result tooltip(Supplier<Component @Nullable []> tooltip) {
+ this.tooltip = tooltip;
+ return this;
+ }
+
+ @Override
public boolean isSuccessful() {
return successful;
}
@Override
+ public boolean execute() {
+ return this.execute.getAsBoolean();
+ }
+
+ @Override
+ public Component @Nullable [] getTooltips() {
+ return tooltip.get();
+ }
+
+ @Override
public Stream<CategoryIdentifier<?>> getCategories() {
return categories.stream();
}
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 5e8134473..d467d7801 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;
@@ -608,10 +603,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();
}
}
}
@@ -870,10 +864,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 031e9c227..149986727 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
@@ -51,13 +51,10 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.inventory.AbstractContainerMenu;
import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.mutable.Mutable;
-import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.*;
-import java.util.stream.Collectors;
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
@@ -213,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