From 8c13c015031a0de865d2e767cd8e879754f803e2 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 5 Aug 2022 01:30:08 +0800 Subject: More work --- .../me/shedaniel/rei/api/client/ClientHelper.java | 2 +- .../me/shedaniel/rei/api/client/REIRuntime.java | 4 +- .../rei/api/client/favorites/FavoriteEntry.java | 2 +- .../rei/api/client/gui/widgets/BatchedSlots.java | 40 ++++ .../shedaniel/rei/api/client/gui/widgets/Slot.java | 22 +- .../rei/api/client/gui/widgets/TextField.java | 51 ++++- .../rei/api/client/gui/widgets/Tooltip.java | 2 +- .../rei/api/client/gui/widgets/TooltipContext.java | 2 +- .../rei/api/client/gui/widgets/Widgets.java | 11 +- .../rei/api/client/overlay/ScreenOverlay.java | 7 + .../registry/entry/PreFilteredEntryList.java | 3 +- .../rei/api/client/registry/screen/ClickArea.java | 2 +- .../client/registry/transfer/TransferHandler.java | 2 +- .../rei/api/client/view/ViewSearchBuilder.java | 2 +- .../api/common/category/CategoryIdentifier.java | 2 +- .../rei/api/common/entry/EntryIngredient.java | 2 +- .../shedaniel/rei/api/common/entry/EntryStack.java | 2 +- .../common/entry/comparison/EntryComparator.java | 2 +- .../rei/api/common/entry/type/EntryType.java | 2 +- .../rei/api/common/plugins/PluginManager.java | 4 +- .../rei/api/common/plugins/PluginView.java | 13 +- .../rei/api/common/registry/ParentReloadable.java | 2 +- .../rei/api/common/util/CollectionUtils.java | 9 +- .../me/shedaniel/rei/impl/ClientInternals.java | 233 --------------------- .../main/java/me/shedaniel/rei/impl/Internals.java | 184 ---------------- .../shedaniel/rei/impl/client/ClientInternals.java | 183 ++++++++++++++++ .../provider/DelegatingFavoriteEntryProvider.java | 34 +++ .../provider/FavoritesEntriesListProvider.java | 32 +++ .../provider/MissingStacksTooltipProvider.java | 33 +++ .../rei/impl/client/provider/WidgetsProvider.java | 82 ++++++++ .../shedaniel/rei/impl/common/InternalLogger.java | 1 - .../me/shedaniel/rei/impl/common/Internals.java | 144 +++++++++++++ .../provider/CategoryIdentifierConstructor.java | 31 +++ .../provider/DeferringEntryTypeProvider.java | 31 +++ .../common/provider/EntryIngredientProvider.java | 41 ++++ .../impl/common/provider/EntryStackProvider.java | 34 +++ .../impl/common/provider/NbtHasherProvider.java | 31 +++ .../common/provider/PluginManagerConstructor.java | 34 +++ 38 files changed, 872 insertions(+), 446 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/BatchedSlots.java delete mode 100644 api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java delete mode 100644 api/src/main/java/me/shedaniel/rei/impl/Internals.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/provider/DelegatingFavoriteEntryProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/provider/FavoritesEntriesListProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/provider/MissingStacksTooltipProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/provider/WidgetsProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/Internals.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/CategoryIdentifierConstructor.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/DeferringEntryTypeProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/EntryIngredientProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/EntryStackProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/NbtHasherProvider.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/common/provider/PluginManagerConstructor.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java index 2e1be6030..6b62994b1 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java @@ -28,7 +28,7 @@ import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.FormattingUtils; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java index a17751703..540dcc2ab 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java @@ -134,7 +134,9 @@ public interface REIRuntime extends Reloadable { * @return the text field used for searching, or {@code null} if none */ @Nullable - TextField getSearchTextField(); + default TextField getSearchTextField() { + return getOverlay().map(ScreenOverlay::getSearchField).orElse(null); + } /** * Queues a tooltip to be displayed. diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java index 6c5415910..e1f18684d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java @@ -29,7 +29,7 @@ import me.shedaniel.rei.api.client.entry.region.RegionEntry; import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.client.util.ClientEntryStacks; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/BatchedSlots.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/BatchedSlots.java new file mode 100644 index 000000000..6cead07dd --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/BatchedSlots.java @@ -0,0 +1,40 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.api.client.gui.widgets; + +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.mutable.MutableLong; + +import java.util.Collection; +import java.util.List; + +public abstract class BatchedSlots extends Widget implements List { + public abstract void addUnbatched(Slot slot); + + public abstract void addAllUnbatched(Collection slots); + + public abstract boolean isBatched(); + + public abstract void addDebugger(MutableInt size, MutableLong time); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Slot.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Slot.java index f0b2842e6..88220ecf2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Slot.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Slot.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.api.client.gui.widgets; +import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -30,13 +31,14 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; +import java.util.function.UnaryOperator; public abstract class Slot extends WidgetWithBounds { public static final byte UN_MARKED = 0; public static final byte INPUT = 1; public static final byte OUTPUT = 2; - public Slot unmarkInputOrOutput() { + public final Slot unmarkInputOrOutput() { setNoticeMark(UN_MARKED); return this; } @@ -59,7 +61,7 @@ public abstract class Slot extends WidgetWithBounds { public abstract boolean isInteractable(); - public Slot interactable(boolean interactable) { + public final Slot interactable(boolean interactable) { setInteractable(interactable); return this; } @@ -76,7 +78,7 @@ public abstract class Slot extends WidgetWithBounds { public abstract boolean isInteractableFavorites(); - public Slot interactableFavorites(boolean interactableFavorites) { + public final Slot interactableFavorites(boolean interactableFavorites) { setInteractableFavorites(interactableFavorites); return this; } @@ -140,8 +142,22 @@ public abstract class Slot extends WidgetWithBounds { public abstract Rectangle getInnerBounds(); + public abstract void drawBackground(PoseStack matrices, int mouseX, int mouseY, float delta); + @Nullable + @Deprecated(forRemoval = true) public Tooltip getCurrentTooltip(Point point) { + return getCurrentTooltip(TooltipContext.of(point)); + } + + public abstract void drawExtra(PoseStack matrices, int mouseX, int mouseY, float delta); + + @Nullable + public Tooltip getCurrentTooltip(TooltipContext context) { return null; } + + public abstract void drawHighlighted(PoseStack matrices, int mouseX, int mouseY, float delta); + + public abstract void tooltipProcessor(UnaryOperator operator); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java index 7002ad26f..803502972 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TextField.java @@ -23,7 +23,23 @@ package me.shedaniel.rei.api.client.gui.widgets; -public interface TextField { +import com.mojang.blaze3d.vertex.PoseStack; +import it.unimi.dsi.fastutil.booleans.BooleanConsumer; +import me.shedaniel.clothconfig2.api.TickableWidget; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; +import java.util.function.Function; + +import static me.shedaniel.rei.api.client.gui.widgets.Widget.mouse; + +public interface TextField extends TickableWidget { + void setFormatter(TextFormatter formatter); + + void setSuggestionRenderer(SuggestionRenderer renderer); + String getText(); void setText(String text); @@ -57,4 +73,37 @@ public interface TextField { boolean isFocused(); void setFocused(boolean focused); + + void setResponder(Consumer responder); + + void setFocusedResponder(BooleanConsumer responder); + + void setTextTransformer(Function textTransformer); + + @Nullable + String getSuggestion(); + + void setSuggestion(@Nullable String suggestion); + + void setBorderColorProvider(BorderColorProvider borderColorProvider); + + WidgetWithBounds asWidget(); + + interface TextFormatter { + TextFormatter DEFAULT = (text, index) -> { + return FormattedCharSequence.forward(text, Style.EMPTY); + }; + + FormattedCharSequence format(String text, int index); + } + + interface SuggestionRenderer { + void renderSuggestion(PoseStack matrices, int x, int y, int color); + } + + interface BorderColorProvider { + BorderColorProvider DEFAULT = textField -> textField.asWidget().containsMouse(mouse()) || textField.isFocused() ? 0xffffffff : 0xffa0a0a0; + + int getBorderColor(TextField textField); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index dad0e9d59..550c9b226 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -29,7 +29,7 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java index 598bbc292..cb20f2bd2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipContext.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import me.shedaniel.math.Point; import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.TooltipFlag; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index 028947c34..4e7e2d336 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -31,7 +31,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.DrawableConsumer; import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -327,6 +327,15 @@ public final class Widgets { return ClientInternals.getWidgetsProvider().wrapPadded(padLeft, padRight, padTop, padBottom, widget); } + public static TextField createTextField(Rectangle bounds) { + return ClientInternals.getWidgetsProvider().createTextField(bounds); + } + + @ApiStatus.Experimental + public static BatchedSlots createBatchedSlots() { + return ClientInternals.getWidgetsProvider().createBatchedSlots(); + } + public static Widget delegate(Supplier supplier) { return new DelegateWidget(Widgets.noOp()) { @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java index f7f5c481e..944755f61 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java @@ -23,7 +23,10 @@ package me.shedaniel.rei.api.client.overlay; +import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.rei.api.client.gui.drag.DraggingContext; +import me.shedaniel.rei.api.client.gui.widgets.TextField; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -43,4 +46,8 @@ public abstract class ScreenOverlay extends WidgetWithBounds { public abstract OverlayListWidget getEntryList(); public abstract Optional getFavoritesList(); + + public abstract TextField getSearchField(); + + public abstract void renderTooltip(PoseStack matrices, Tooltip tooltip); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/PreFilteredEntryList.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/PreFilteredEntryList.java index f9bd53422..f05db2347 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/PreFilteredEntryList.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/PreFilteredEntryList.java @@ -26,8 +26,7 @@ package me.shedaniel.rei.api.client.registry.entry; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.registry.Reloadable; -import me.shedaniel.rei.impl.ClientInternals; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.client.ClientInternals; import org.jetbrains.annotations.ApiStatus; import java.util.Collection; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java index 3f6803d97..8b6aad935 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api.client.registry.screen; import me.shedaniel.math.Point; import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.Screen; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java index ec32d75aa..3945e9c63 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java @@ -27,7 +27,7 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java index 1afa8f04d..5f7a2c1a4 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java @@ -31,7 +31,7 @@ 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.util.CollectionUtils; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import me.shedaniel.rei.impl.display.DisplaySpec; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/category/CategoryIdentifier.java b/api/src/main/java/me/shedaniel/rei/api/common/category/CategoryIdentifier.java index 8fd2136c0..001517a5c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/category/CategoryIdentifier.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/category/CategoryIdentifier.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api.common.category; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.util.Identifiable; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import net.minecraft.ResourceLocationException; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java index fd6302218..27f37f620 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.api.common.entry; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index 0dcb10eda..2d2f3ca15 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -37,7 +37,7 @@ import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.EntryType; import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.common.util.TextRepresentable; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java index e24d41327..c30fb7aa7 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparator.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.api.common.entry.comparison; import dev.architectury.fluid.FluidStack; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryType.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryType.java index 6db72c191..69834c070 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryType.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/type/EntryType.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api.common.entry.type; import me.shedaniel.rei.api.client.entry.type.BuiltinClientEntryTypes; import me.shedaniel.rei.api.common.util.Identifiable; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java index f135fded3..b42a5d8f5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginManager.java @@ -28,8 +28,8 @@ import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.registry.ParentReloadable; import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.impl.ClientInternals; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.client.ClientInternals; +import me.shedaniel.rei.impl.common.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java index ff5584789..bda9797ca 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/PluginView.java @@ -25,12 +25,14 @@ package me.shedaniel.rei.api.common.plugins; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.registry.ReloadStage; -import me.shedaniel.rei.impl.ClientInternals; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.client.ClientInternals; +import me.shedaniel.rei.impl.common.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; +import java.util.List; + @ApiStatus.Internal public interface PluginView

> { @Environment(EnvType.CLIENT) @@ -70,10 +72,17 @@ public interface PluginView

> { public void post(ReloadStage stage) { PluginView.this.post(stage); } + + @Override + public List getObservedStages() { + return PluginView.this.getObservedStages(); + } }; } void pre(ReloadStage stage); void post(ReloadStage stage); + + List getObservedStages(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java b/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java index e91f19245..a6bfcea38 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/registry/ParentReloadable.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.api.common.registry; import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import java.util.List; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index d657e0c4e..5680b4ab4 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -424,6 +424,10 @@ public class CollectionUtils { @SafeVarargs public static List concatUnmodifiable(List... lists) { + return new ListConcatenationView<>(Arrays.asList(lists)); + } + + public static List concatUnmodifiable(Iterable> lists) { return new ListConcatenationView<>(lists); } @@ -431,10 +435,9 @@ public class CollectionUtils { * A list which acts as view of the concatenation of a number of lists. */ private static class ListConcatenationView extends AbstractList { - private final List[] lists; + private final Iterable> lists; - @SafeVarargs - public ListConcatenationView(List... lists) { + public ListConcatenationView(Iterable> lists) { this.lists = lists; } diff --git a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java deleted file mode 100644 index df5e4938e..000000000 --- a/api/src/main/java/me/shedaniel/rei/impl/ClientInternals.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 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; - -import com.mojang.math.Matrix4f; -import com.mojang.serialization.DataResult; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.favorites.FavoriteEntry; -import me.shedaniel.rei.api.client.gui.DrawableConsumer; -import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.widgets.*; -import me.shedaniel.rei.api.client.plugins.REIClientPlugin; -import me.shedaniel.rei.api.client.registry.entry.PreFilteredEntryList; -import me.shedaniel.rei.api.client.registry.screen.ClickArea; -import me.shedaniel.rei.api.client.view.ViewSearchBuilder; -import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import net.minecraft.ReportedException; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.FormattedText; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.inventory.tooltip.TooltipComponent; -import net.minecraft.world.item.TooltipFlag; -import org.apache.commons.lang3.function.TriFunction; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; -import java.util.function.*; - -@ApiStatus.Internal -public final class ClientInternals { - private static final ClientHelper CLIENT_HELPER = resolveService(ClientHelper.class); - private static final WidgetsProvider WIDGETS_PROVIDER = resolveService(WidgetsProvider.class); - private static final ViewSearchBuilder VIEW_SEARCH_BUILDER = resolveService(ViewSearchBuilder.class); - private static final PluginManager CLIENT_PLUGIN_MANAGER = Internals.createPluginManager( - REIClientPlugin.class, - UnaryOperator.identity()); - private static final DelegatingFavoriteEntryProvider DELEGATE_FAVORITE_ENTRY = resolveService(DelegatingFavoriteEntryProvider.class); - private static final FavoritesEntriesListProvider FAVORITES_ENTRIES_LIST = resolveService(FavoritesEntriesListProvider.class); - private static Function> favoriteEntryFromJson = (object) -> throwNotSetup(); - private static Function clickAreaHandlerResult = (result) -> throwNotSetup(); - private static BiConsumer, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); - private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); - private static TriFunction tooltipContextProvider = (point, texts, search) -> throwNotSetup(); - private static Function tooltipEntryProvider = (component) -> throwNotSetup(); - private static Supplier> jeiCompatMods = ClientInternals::throwNotSetup; - private static Supplier builtinClientPlugin = ClientInternals::throwNotSetup; - private static Function, TooltipComponent> missingTooltip = (stacks) -> throwNotSetup(); - private static BiConsumer crashHandler = (exception, component) -> throwNotSetup(); - private static Supplier preFilteredEntryList = ClientInternals::throwNotSetup; - - public static T resolveService(Class serviceClass) { - return Internals.resolveService(serviceClass); - } - - public static List resolveServices(Class serviceClass) { - return Internals.resolveServices(serviceClass); - } - - private static T throwNotSetup() { - throw new AssertionError("REI Internals have not been initialized!"); - } - - @ApiStatus.Internal - public static void attachInstance(T instance, Class clazz) { - attachInstanceSupplier(instance, clazz.getSimpleName()); - } - - @ApiStatus.Internal - public static void attachInstanceSupplier(T instance, String name) { - attachInstance((Supplier) () -> instance, name); - } - - public static void attachInstance(T instance, String name) { - try { - for (Field field : ClientInternals.class.getDeclaredFields()) { - if (field.getName().equalsIgnoreCase(name)) { - field.setAccessible(true); - field.set(null, instance); - return; - } - } - throw new RuntimeException("Failed to attach " + instance + " with field name: " + name); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static ClientHelper getClientHelper() { - return CLIENT_HELPER; - } - - public static WidgetsProvider getWidgetsProvider() { - return WIDGETS_PROVIDER; - } - - public static ViewSearchBuilder createViewSearchBuilder() { - return VIEW_SEARCH_BUILDER; - } - - public static Object getBuiltinPlugin() { - return builtinClientPlugin.get(); - } - - public static ClickArea.Result createClickAreaHandlerResult(boolean applicable) { - return clickAreaHandlerResult.apply(applicable); - } - - public static void getClientTooltipComponent(List tooltip, TooltipComponent component) { - clientTooltipComponentProvider.accept(tooltip, component); - } - - public static Tooltip createTooltip(@Nullable Point point, Collection texts) { - return tooltipProvider.apply(point, texts); - } - - public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) { - return tooltipContextProvider.apply(point, flag, isSearch); - } - - public static Tooltip.Entry createTooltipEntry(Object component) { - return tooltipEntryProvider.apply(component); - } - - public static FavoriteEntry delegateFavoriteEntry(Supplier> supplier, Supplier toJoin) { - return DELEGATE_FAVORITE_ENTRY.delegate(supplier, toJoin); - } - - public static List getFavoritesEntriesList() { - return FAVORITES_ENTRIES_LIST.get(); - } - - public static DataResult favoriteEntryFromJson(CompoundTag tag) { - return favoriteEntryFromJson.apply(tag); - } - - public static List getJeiCompatMods() { - return jeiCompatMods.get(); - } - - public static PluginManager getPluginManager() { - return CLIENT_PLUGIN_MANAGER; - } - - public static TooltipComponent createMissingTooltip(List stacks) { - return missingTooltip.apply(stacks); - } - - public static PreFilteredEntryList getPreFilteredEntryList() { - return preFilteredEntryList.get(); - } - - public static void crash(ReportedException exception, String component) { - crashHandler.accept(exception, component); - } - - public interface WidgetsProvider { - boolean isRenderingPanel(Panel panel); - - Widget wrapVanillaWidget(GuiEventListener element); - - WidgetWithBounds wrapRenderer(Supplier bounds, Renderer renderer); - - WidgetWithBounds withTranslate(WidgetWithBounds widget, Supplier translate); - - Widget createDrawableWidget(DrawableConsumer drawable); - - Slot createSlot(Point point); - - Slot createSlot(Rectangle bounds); - - Button createButton(Rectangle bounds, Component text); - - Panel createPanelWidget(Rectangle bounds); - - Label createLabel(Point point, FormattedText text); - - Arrow createArrow(Rectangle rectangle); - - BurningFire createBurningFire(Rectangle rectangle); - - DrawableConsumer createTexturedConsumer(ResourceLocation texture, int x, int y, int width, int height, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight); - - DrawableConsumer createFillRectangleConsumer(Rectangle rectangle, int color); - - Widget createShapelessIcon(Point point); - - Widget concatWidgets(List widgets); - - WidgetWithBounds noOp(); - - WidgetWithBounds wrapOverflow(Rectangle bounds, WidgetWithBounds widget); - - WidgetWithBounds wrapPadded(int padLeft, int padRight, int padTop, int padBottom, WidgetWithBounds widget); - } - - public interface DelegatingFavoriteEntryProvider { - FavoriteEntry delegate(Supplier> result, Supplier tag); - } - - public interface FavoritesEntriesListProvider { - List get(); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java deleted file mode 100644 index d5ad63e1b..000000000 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 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; - -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.comparison.EntryComparator; -import me.shedaniel.rei.api.common.entry.type.EntryDefinition; -import me.shedaniel.rei.api.common.entry.type.EntryType; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.plugins.PluginView; -import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.api.common.plugins.REIServerPlugin; -import me.shedaniel.rei.impl.common.InternalLogger; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Unit; -import org.jetbrains.annotations.ApiStatus; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.ServiceLoader; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -@ApiStatus.Internal -public final class Internals { - private static final EntryStackProvider ENTRY_STACK_PROVIDER = resolveService(EntryStackProvider.class); - private static final EntryIngredientProvider ENTRY_INGREDIENT_PROVIDER = resolveService(EntryIngredientProvider.class); - private static final DeferringEntryTypeProvider ENTRY_TYPE_DEFERRED = resolveService(DeferringEntryTypeProvider.class); - private static final PluginManagerConstructor PLUGIN_MANAGER_CONSTRUCTOR = resolveService(PluginManagerConstructor.class); - private static final PluginManager> COMMON_PLUGIN_MANAGER = createPluginManager( - (Class>) (Class) REIPlugin.class, - UnaryOperator.identity()); - private static final PluginManager SERVER_PLUGIN_MANAGER = createPluginManager( - REIServerPlugin.class, - view -> view.then(COMMON_PLUGIN_MANAGER.view())); - private static final NbtHasherProvider NBT_HASHER_PROVIDER = resolveService(NbtHasherProvider.class); - private static final CategoryIdentifierConstructor CATEGORY_IDENTIFIER_CONSTRUCTOR = resolveService(CategoryIdentifierConstructor.class); - private static Supplier logger = Internals::throwNotSetup; - private static Runnable reloadREI = Internals::throwNotSetup; - - private static T throwNotSetup() { - throw new AssertionError("REI Internals have not been initialized!"); - } - - public static T resolveService(Class serviceClass) { - ServiceLoader loader = ServiceLoader.load(serviceClass); - List> providers = loader.stream().toList(); - if (providers.isEmpty()) { - throw new IllegalArgumentException("No service providers found for class " + serviceClass.getName()); - } else if (providers.size() > 1) { - throw new IllegalArgumentException("Multiple service providers found for class " + serviceClass.getName() + ": " + - providers.stream().map(provider -> provider.type().getName()) - .collect(Collectors.joining(", "))); - } else { - return providers.get(0).get(); - } - } - - public static List resolveServices(Class serviceClass) { - ServiceLoader loader = ServiceLoader.load(serviceClass); - return loader.stream().map(ServiceLoader.Provider::get).toList(); - } - - public static void attachInstanceSupplier(T instance, String name) { - attachInstance((Supplier) () -> instance, name); - } - - public static void attachInstance(T instance, String name) { - try { - for (Field field : Internals.class.getDeclaredFields()) { - if (field.getName().equalsIgnoreCase(name)) { - field.setAccessible(true); - field.set(null, instance); - return; - } - } - throw new RuntimeException("Failed to attach " + instance + " with field name: " + name); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static EntryStackProvider getEntryStackProvider() { - return ENTRY_STACK_PROVIDER; - } - - public static EntryIngredientProvider getEntryIngredientProvider() { - return ENTRY_INGREDIENT_PROVIDER; - } - - public static EntryType deferEntryType(ResourceLocation id) { - return ENTRY_TYPE_DEFERRED.get(id); - } - - public static

> PluginManager

createPluginManager(Class

clazz, UnaryOperator> constructor) { - return PLUGIN_MANAGER_CONSTRUCTOR.create(clazz, constructor); - } - - public static PluginManager> getPluginManager() { - return COMMON_PLUGIN_MANAGER; - } - - public static PluginManager getServerPluginManager() { - return SERVER_PLUGIN_MANAGER; - } - - public static EntryComparator getNbtHasher(String[] ignoredKeys) { - return NBT_HASHER_PROVIDER.provide(ignoredKeys); - } - - public static CategoryIdentifier getCategoryIdentifier(String location) { - return CATEGORY_IDENTIFIER_CONSTRUCTOR.create(location); - } - - public static InternalLogger getInternalLogger() { - return logger.get(); - } - - public static void reloadREI() { - reloadREI.run(); - } - - public interface EntryStackProvider { - EntryStack empty(); - - EntryStack of(EntryDefinition definition, T value); - } - - public interface EntryIngredientProvider { - EntryIngredient empty(); - - EntryIngredient of(EntryStack stack); - - EntryIngredient of(EntryStack... stacks); - - EntryIngredient of(Iterable> stacks); - - EntryIngredient.Builder builder(); - - EntryIngredient.Builder builder(int initialCapacity); - } - - public interface PluginManagerConstructor { -

> PluginManager

create(Class

clazz, UnaryOperator> constructor); - } - - public interface NbtHasherProvider { - EntryComparator provide(String... ignoredKeys); - } - - public interface DeferringEntryTypeProvider { - EntryType get(ResourceLocation id); - } - - public interface CategoryIdentifierConstructor { - CategoryIdentifier create(String location); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java new file mode 100644 index 000000000..b684d3554 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java @@ -0,0 +1,183 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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; + +import com.mojang.serialization.DataResult; +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.client.ClientHelper; +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.entry.PreFilteredEntryList; +import me.shedaniel.rei.api.client.registry.screen.ClickArea; +import me.shedaniel.rei.api.client.view.ViewSearchBuilder; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.impl.client.provider.DelegatingFavoriteEntryProvider; +import me.shedaniel.rei.impl.client.provider.FavoritesEntriesListProvider; +import me.shedaniel.rei.impl.client.provider.MissingStacksTooltipProvider; +import me.shedaniel.rei.impl.client.provider.WidgetsProvider; +import me.shedaniel.rei.impl.common.Internals; +import net.minecraft.ReportedException; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.TooltipFlag; +import org.apache.commons.lang3.function.TriFunction; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.List; +import java.util.function.*; + +@ApiStatus.Internal +public final class ClientInternals { + private static final ClientHelper CLIENT_HELPER = resolveService(ClientHelper.class); + private static final WidgetsProvider WIDGETS_PROVIDER = resolveService(WidgetsProvider.class); + private static final ViewSearchBuilder VIEW_SEARCH_BUILDER = resolveService(ViewSearchBuilder.class); + private static final PluginManager CLIENT_PLUGIN_MANAGER = Internals.createPluginManager( + REIClientPlugin.class, + UnaryOperator.identity()); + private static final DelegatingFavoriteEntryProvider DELEGATE_FAVORITE_ENTRY = resolveService(DelegatingFavoriteEntryProvider.class); + private static final FavoritesEntriesListProvider FAVORITES_ENTRIES_LIST = resolveService(FavoritesEntriesListProvider.class); + private static Function> favoriteEntryFromJson = (object) -> throwNotSetup(); + private static Function clickAreaHandlerResult = (result) -> throwNotSetup(); + private static BiConsumer, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); + private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); + private static TriFunction tooltipContextProvider = (point, texts, search) -> throwNotSetup(); + private static Function tooltipEntryProvider = (component) -> throwNotSetup(); + private static Supplier> jeiCompatMods = ClientInternals::throwNotSetup; + private static Supplier builtinClientPlugin = ClientInternals::throwNotSetup; + private static final MissingStacksTooltipProvider MISSING_TOOLTIP = resolveService(MissingStacksTooltipProvider.class); + private static BiConsumer crashHandler = (exception, component) -> throwNotSetup(); + private static Supplier preFilteredEntryList = ClientInternals::throwNotSetup; + + public static T resolveService(Class serviceClass) { + return Internals.resolveService(serviceClass); + } + + public static List resolveServices(Class serviceClass) { + return Internals.resolveServices(serviceClass); + } + + private static T throwNotSetup() { + throw new AssertionError("REI Internals have not been initialized!"); + } + + @ApiStatus.Internal + public static void attachInstance(T instance, Class clazz) { + attachInstanceSupplier(instance, clazz.getSimpleName()); + } + + @ApiStatus.Internal + public static void attachInstanceSupplier(T instance, String name) { + attachInstance((Supplier) () -> instance, name); + } + + public static void attachInstance(T instance, String name) { + try { + for (Field field : ClientInternals.class.getDeclaredFields()) { + if (field.getName().equalsIgnoreCase(name)) { + field.setAccessible(true); + field.set(null, instance); + return; + } + } + throw new RuntimeException("Failed to attach " + instance + " with field name: " + name); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public static ClientHelper getClientHelper() { + return CLIENT_HELPER; + } + + public static WidgetsProvider getWidgetsProvider() { + return WIDGETS_PROVIDER; + } + + public static ViewSearchBuilder createViewSearchBuilder() { + return VIEW_SEARCH_BUILDER; + } + + public static Object getBuiltinPlugin() { + return builtinClientPlugin.get(); + } + + public static ClickArea.Result createClickAreaHandlerResult(boolean applicable) { + return clickAreaHandlerResult.apply(applicable); + } + + public static void getClientTooltipComponent(List tooltip, TooltipComponent component) { + clientTooltipComponentProvider.accept(tooltip, component); + } + + public static Tooltip createTooltip(@Nullable Point point, Collection texts) { + return tooltipProvider.apply(point, texts); + } + + public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) { + return tooltipContextProvider.apply(point, flag, isSearch); + } + + public static Tooltip.Entry createTooltipEntry(Object component) { + return tooltipEntryProvider.apply(component); + } + + public static FavoriteEntry delegateFavoriteEntry(Supplier> supplier, Supplier toJoin) { + return DELEGATE_FAVORITE_ENTRY.delegate(supplier, toJoin); + } + + public static List getFavoritesEntriesList() { + return FAVORITES_ENTRIES_LIST.get(); + } + + public static DataResult favoriteEntryFromJson(CompoundTag tag) { + return favoriteEntryFromJson.apply(tag); + } + + public static List getJeiCompatMods() { + return jeiCompatMods.get(); + } + + public static PluginManager getPluginManager() { + return CLIENT_PLUGIN_MANAGER; + } + + public static TooltipComponent createMissingTooltip(List stacks) { + return MISSING_TOOLTIP.provide(stacks); + } + + public static PreFilteredEntryList getPreFilteredEntryList() { + return preFilteredEntryList.get(); + } + + public static void crash(ReportedException exception, String component) { + crashHandler.accept(exception, component); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/DelegatingFavoriteEntryProvider.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/DelegatingFavoriteEntryProvider.java new file mode 100644 index 000000000..2eec919f8 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/DelegatingFavoriteEntryProvider.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.provider; + +import com.mojang.serialization.DataResult; +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import net.minecraft.nbt.CompoundTag; + +import java.util.function.Supplier; + +public interface DelegatingFavoriteEntryProvider { + FavoriteEntry delegate(Supplier> result, Supplier tag); +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/FavoritesEntriesListProvider.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/FavoritesEntriesListProvider.java new file mode 100644 index 000000000..d2c1ec23c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/FavoritesEntriesListProvider.java @@ -0,0 +1,32 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.provider; + +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; + +import java.util.List; + +public interface FavoritesEntriesListProvider { + List get(); +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/MissingStacksTooltipProvider.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/MissingStacksTooltipProvider.java new file mode 100644 index 000000000..b10675f1f --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/MissingStacksTooltipProvider.java @@ -0,0 +1,33 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.provider; + +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import net.minecraft.world.inventory.tooltip.TooltipComponent; + +import java.util.List; + +public interface MissingStacksTooltipProvider { + TooltipComponent provide(List stacks); +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/WidgetsProvider.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/WidgetsProvider.java new file mode 100644 index 000000000..6d985e4a2 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/WidgetsProvider.java @@ -0,0 +1,82 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.provider; + +import com.mojang.math.Matrix4f; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.DrawableConsumer; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.*; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.resources.ResourceLocation; + +import java.util.List; +import java.util.function.Supplie