diff options
Diffstat (limited to 'runtime/src')
3 files changed, 49 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 e35f0e3c2..88e084b61 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -52,7 +52,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; @@ -88,6 +90,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; @@ -106,6 +109,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; @@ -141,6 +145,26 @@ public class RoughlyEnoughItemsCoreClient { ClientInternals.attachInstance((Function<Object, Tooltip.Entry>) QueuedTooltip.TooltipEntryImpl::new, "tooltipEntryProvider"); 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) { @@ -149,11 +173,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 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 |
