diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-08-28 18:50:24 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-08-28 18:50:24 +0900 |
| commit | 94e323f75c17e297c33fba1d3afb5c47ae66a8ad (patch) | |
| tree | 3c6cb6c1721fbda792050b96707fad50d1db64e9 /api/src | |
| parent | f5061d043cac7f0217bbe9d4c041b77f9ef911a1 (diff) | |
| download | RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.tar.gz RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.tar.bz2 RoughlyEnoughItems-94e323f75c17e297c33fba1d3afb5c47ae66a8ad.zip | |
Separate EntryListWidget and FavoritesListWidget more
Diffstat (limited to 'api/src')
11 files changed, 181 insertions, 9 deletions
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 7169e83ad..c044b583c 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,6 +28,7 @@ import me.shedaniel.rei.api.client.config.ConfigObject; 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.networking.NetworkingHelper; import me.shedaniel.rei.api.common.util.FormattingUtils; import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; @@ -206,5 +207,7 @@ public interface ClientHelper { * * @return whether the client can use move items packets */ - boolean canUseMovePackets(); + default boolean canUseMovePackets() { + return NetworkingHelper.getInstance().client().canUseMovePackets(); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java index e4ff00b7b..aa91c9b76 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java @@ -39,6 +39,10 @@ public class DelegateWidget extends WidgetWithBounds { this.widget = widget; } + public DelegateWidget() { + this(Widgets.noOp()); + } + protected Widget delegate() { return widget; } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java index 593a62588..e7f00d773 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java @@ -36,6 +36,18 @@ public class DelegateWidgetWithBounds extends DelegateWidget { this.bounds = bounds; } + public DelegateWidgetWithBounds(Supplier<Rectangle> bounds) { + this(Widgets.noOp(), bounds); + } + + public DelegateWidgetWithBounds(Rectangle bounds) { + this(Widgets.noOp(), () -> bounds); + } + + public DelegateWidgetWithBounds() { + this(new Rectangle()); + } + @Override public Rectangle getBounds() { return bounds.get(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java index c938cd8d6..007cd777c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java @@ -1,3 +1,26 @@ +/* + * 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 me.shedaniel.rei.impl.client.ClientInternals; 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 67dfe7cbb..0183b480e 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 @@ -333,7 +333,7 @@ public final class Widgets { } public static Widget delegate(Supplier<Widget> supplier) { - return new DelegateWidget(Widgets.noOp()) { + return new DelegateWidget() { @Override protected Widget delegate() { return supplier.get(); @@ -342,7 +342,7 @@ public final class Widgets { } public static WidgetWithBounds delegateWithBounds(Supplier<WidgetWithBounds> supplier) { - return new DelegateWidgetWithBounds(Widgets.noOp(), Rectangle::new) { + return new DelegateWidgetWithBounds() { @Override protected WidgetWithBounds delegate() { return supplier.get(); 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 b9758f235..5d8ed2b80 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 @@ -28,8 +28,11 @@ 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 me.shedaniel.rei.api.client.search.SearchFilter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -97,6 +100,15 @@ public abstract class ScreenOverlay extends WidgetWithBounds { public abstract TextField getSearchField(); /** + * Returns the current search filter. + * + * @return the current search filter + */ + @ApiStatus.Experimental + @Nullable + public abstract SearchFilter getCurrentSearchFilter(); + + /** * Renders a tooltip. * * @param matrices the matrices transform 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 8b6aad935..97d46001e 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 @@ -44,6 +44,20 @@ public interface ClickArea<T extends Screen> { @ApiStatus.NonExtendable interface ClickAreaContext<T extends Screen> { + static <T extends Screen> ClickAreaContext<T> of(T screen, Point mouse) { + return new ClickAreaContext<>() { + @Override + public T getScreen() { + return screen; + } + + @Override + public Point getMousePosition() { + return mouse; + } + }; + } + T getScreen(); Point getMousePosition(); 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 5f7a2c1a4..985048b7a 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 @@ -220,6 +220,21 @@ public interface ViewSearchBuilder { ViewSearchBuilder processingVisibilityHandlers(boolean processingVisibilityHandlers); /** + * Force-all displays to the view search builder. + * + * @param displays the displays to add + * @return the {@link ViewSearchBuilder} for chaining + */ + ViewSearchBuilder addDisplays(Collection<Display> displays); + + /** + * Returns the collection of additional displays to show. + * + * @return the collection of additional displays to show. + */ + Collection<Display> getAdditionalDisplays(); + + /** * Opens the view after the search is complete. * * @return whether the view was opened diff --git a/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java new file mode 100644 index 000000000..ca1e2ad41 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java @@ -0,0 +1,56 @@ +/* + * 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.common.networking; + +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.registry.Reloadable; + +public interface NetworkingHelper extends Reloadable<REIServerPlugin> { + static NetworkingHelper getInstance() { + return PluginManager.getServerInstance().get(NetworkingHelper.class); + } + + Client client(); + + interface Client { + boolean hasPermissionToUsePackets(); + + boolean hasOperatorPermission(); + + /** + * Returns whether the client can use delete items packets. + * + * @return whether the client can use delete items packets + */ + boolean canUseDeletePackets(); + + /** + * Returns whether the client can use move items packets. + * + * @return whether the client can use move items packets + */ + boolean canUseMovePackets(); + } +} 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 index 0791ec310..eeb03e5fb 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java @@ -40,7 +40,6 @@ import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.impl.client.provider.*; 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; @@ -66,9 +65,9 @@ public final class ClientInternals { private static final List<OverlayTicker> OVERLAY_TICKERS = resolveServices(OverlayTicker.class); private static final AutoCraftingEvaluator AUTO_CRAFTING_EVALUATOR = resolveService(AutoCraftingEvaluator.class); private static final TooltipQueue TOOLTIP_QUEUE = resolveService(TooltipQueue.class); + private static final TooltipRenderer TOOLTIP_RENDERER = resolveService(TooltipRenderer.class); private static Function<CompoundTag, DataResult<FavoriteEntry>> favoriteEntryFromJson = (object) -> throwNotSetup(); private static Function<Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); - private static BiConsumer<List<ClientTooltipComponent>, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection<Tooltip.Entry>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static TriFunction<Point, @Nullable TooltipFlag, Boolean, TooltipContext> tooltipContextProvider = (point, texts, search) -> throwNotSetup(); private static Function<Object, Tooltip.Entry> tooltipEntryProvider = (component) -> throwNotSetup(); @@ -135,14 +134,14 @@ public final class ClientInternals { return clickAreaHandlerResult.apply(applicable); } - public static void getClientTooltipComponent(List<ClientTooltipComponent> tooltip, TooltipComponent component) { - clientTooltipComponentProvider.accept(tooltip, component); - } - public static Tooltip createTooltip(@Nullable Point point, Collection<Tooltip.Entry> texts) { return tooltipProvider.apply(point, texts); } + public static TooltipRenderer getTooltipRenderer() { + return TOOLTIP_RENDERER; + } + public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) { return tooltipContextProvider.apply(point, flag, isSearch); } diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java new file mode 100644 index 000000000..df510bee7 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.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.blaze3d.vertex.PoseStack; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public interface TooltipRenderer { + void renderTooltip(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY); +} |
