From 020a705d3947c38c1f27d6d322bade09a17c0853 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 17 Jun 2022 21:52:16 +0800 Subject: Too much docs for today --- .../me/shedaniel/rei/api/client/ClientHelper.java | 40 +++++++-- .../me/shedaniel/rei/api/client/REIRuntime.java | 98 ++++++++++++++++++++++ .../api/client/registry/screen/ExclusionZones.java | 18 ++-- .../api/client/registry/screen/OverlayDecider.java | 10 +++ .../api/client/registry/screen/ScreenRegistry.java | 20 +++++ .../client/registry/transfer/TransferHandler.java | 35 ++++++++ .../me/shedaniel/rei/api/client/view/Views.java | 3 + 7 files changed, 211 insertions(+), 13 deletions(-) (limited to 'api/src/main/java') 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 55c481151..2e1be6030 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 @@ -101,7 +101,7 @@ public interface ClientHelper { void sendDeletePacket(); /** - * Gets the formatted mod from an item + * Returns the formatted mod from an item * * @param item the item to find * @return the mod name with blue and italic formatting @@ -114,7 +114,7 @@ public interface ClientHelper { } /** - * Gets the formatted mod from an identifier + * Returns the formatted mod from an identifier * * @param identifier the identifier to find * @return the mod name with blue and italic formatting @@ -127,18 +127,25 @@ public interface ClientHelper { } /** - * Gets the mod from a modid + * Returns the mod from a modid * - * @param modid the modid of the mod + * @param modId the modid of the mod * @return the mod name with blue and italic formatting */ - default Component getFormattedModFromModId(String modid) { - String mod = getModFromModId(modid); + default Component getFormattedModFromModId(String modId) { + String mod = getModFromModId(modId); if (mod.isEmpty()) return NarratorChatListener.NO_TITLE; return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); } + /** + * Appends the formatted mod to the list of tooltip components. + * + * @param components the list of tooltip components + * @param modId the modid of the mod + * @return the list of tooltip components + */ default List appendModIdToTooltips(List components, String modId) { final String modName = ClientHelper.getInstance().getModFromModId(modId); boolean alreadyHasMod = false; @@ -152,10 +159,16 @@ public interface ClientHelper { return components; } + /** + * Appends the formatted mod to the tooltip. + * + * @param components the tooltip + * @param modId the modid of the mod + */ void appendModIdToTooltips(Tooltip components, String modId); /** - * Gets the mod from an identifier + * Returns the mod from an identifier * * @param identifier the identifier to find * @return the mod name @@ -167,14 +180,25 @@ public interface ClientHelper { } /** - * Gets the mod from a modid + * Returns the mod from a modid * * @param modId the modid of the mod * @return the mod name */ String getModFromModId(String modId); + /** + * Opens the view after the search is complete. + * + * @param builder the view search builder + * @return whether the view was opened + */ boolean openView(ViewSearchBuilder builder); + /** + * 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/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java index fb1985970..f44523e9a 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 @@ -44,6 +44,9 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; +/** + * The runtime of REI. + */ @Environment(EnvType.CLIENT) public interface REIRuntime extends Reloadable { /** @@ -53,37 +56,121 @@ public interface REIRuntime extends Reloadable { return PluginManager.getClientInstance().get(REIRuntime.class); } + /** + * Returns whether the overlay is visible, this is usually toggled by + * the user with a keybind. + * + * @return whether the overlay is visible + */ boolean isOverlayVisible(); + /** + * Toggles the visibility of the overlay. + */ void toggleOverlayVisible(); + /** + * Returns the screen overlay of REI, if available and constructed. + * + * @return the screen overlay + */ default Optional getOverlay() { return getOverlay(false, false); } + /** + * Returns the screen overlay of REI. + *

+ * if {@param reset} is {@code true}, the overlay will be reset, + * and the returned value must not be {@code null}. + * + * @param reset whether to reset the overlay + * @return the screen overlay + */ default Optional getOverlay(boolean reset) { return getOverlay(reset, true); } + /** + * Returns the screen overlay of REI. + *

+ * If {@param reset} is {@code true}, the overlay will be reset, + * and the returned value must not be {@code null}. + *

+ * If the overlay has not been constructed yet, and {@param init} is {@code true}, + * the overlay will be constructed, and the returned value must not be {@code null}. + * + * @param reset whether to reset the overlay + * @param init whether to init the overlay if it has not been constructed yet + * @return the screen overlay + */ Optional getOverlay(boolean reset, boolean init); + /** + * Returns the previous opened container screen, if available. + * + * @return the previous opened container screen, or {@code null} if none + */ @Nullable AbstractContainerScreen getPreviousContainerScreen(); + /** + * Returns the previous opened screen, if available. + * + * @return the previous opened screen, or {@code null} if none + */ @Nullable Screen getPreviousScreen(); + /** + * Returns whether dark mode is enabled. + * + * @return whether dark mode is enabled + * @see ConfigObject#isUsingDarkTheme() + */ boolean isDarkThemeEnabled(); + /** + * Returns the text field used for searching, if constructed. + * + * @return the text field used for searching, or {@code null} if none + */ @Nullable TextField getSearchTextField(); + /** + * Queues a tooltip to be displayed. + * + * @param tooltip the tooltip to display, or {@code null} + * @see Tooltip#queue() + */ void queueTooltip(@Nullable Tooltip tooltip); + /** + * Returns the texture location of the default display background. + *

+ * This is different depending on whether dark mode is enabled. + * + * @return the texture location of the default display background + */ ResourceLocation getDefaultDisplayTexture(); + /** + * Returns the texture location of the default display background. + * + * @param darkTheme whether dark mode is enabled + * @return the texture location of the default display background + */ ResourceLocation getDefaultDisplayTexture(boolean darkTheme); + /** + * Returns the location of the search field, according to the current screen. + *

+ * If the config location is center, and the current screen is too small to display + * the search field at the bottom center, the location returned will be the side. + * + * @return the location of the search field + */ SearchFieldLocation getContextualSearchFieldLocation(); @ApiStatus.ScheduledForRemoval @@ -92,7 +179,18 @@ public interface REIRuntime extends Reloadable { return calculateEntryListArea(ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen)); } + /** + * Calculates the area of the entry list, given the bounds of the overlay. + * + * @param bounds the bounds of the overlay + * @return the area of the entry list + */ Rectangle calculateEntryListArea(Rectangle bounds); + /** + * Calculates the area of the favorites list. + * + * @return the area of the favorites list + */ Rectangle calculateFavoritesListArea(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ExclusionZones.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ExclusionZones.java index 19a58c430..ec2bb7bb5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ExclusionZones.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ExclusionZones.java @@ -30,10 +30,13 @@ import net.minecraft.client.gui.screens.Screen; import java.util.List; +/** + * The registry for querying and registering exclusion zones. + */ @Environment(EnvType.CLIENT) public interface ExclusionZones extends OverlayDecider { /** - * Returns the exclusion zones by the screen class + * Returns the exclusion zones by the screen class. * * @param currentScreenClass the current screen class * @return the list of exclusion zones @@ -45,7 +48,7 @@ public interface ExclusionZones extends OverlayDecider { } /** - * Returns the exclusion zones by the screen class + * Returns the exclusion zones by the screen class. * * @param currentScreenClass the current screen class * @return the list of exclusion zones @@ -55,7 +58,7 @@ public interface ExclusionZones extends OverlayDecider { List getExclusionZones(Class currentScreenClass, boolean sort); /** - * Returns the exclusion zones by the screen + * Returns the exclusion zones by the screen. * * @param screen the screen * @return the list of exclusion zones @@ -65,17 +68,22 @@ public interface ExclusionZones extends OverlayDecider { } /** - * Returns the exclusion zones by the screen + * Returns the exclusion zones by the screen. * * @param screen the screen * @return the list of exclusion zones */ List getExclusionZones(Screen screen, boolean sort); + /** + * Returns the number of exclusion zone providers registered. + * + * @return the number of exclusion zone providers registered + */ int getZonesCount(); /** - * Register an exclusion zone + * Register an exclusion zone. * * @param screenClass the screen class * @param provider the exclusion zone provider, returns a collection of exclusion zones diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/OverlayDecider.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/OverlayDecider.java index 1f9ab4faa..84798f6c5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/OverlayDecider.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/OverlayDecider.java @@ -38,6 +38,13 @@ import static net.minecraft.world.InteractionResult.PASS; */ @Environment(EnvType.CLIENT) public interface OverlayDecider extends Comparable { + /** + * Returns whether this decider should be used to handle the specified screen. + * + * @param screen the screen + * @param the type of the screen + * @return whether this decider should be used to handle the specified screen + */ boolean isHandingScreen(Class screen); @ApiStatus.ScheduledForRemoval @@ -81,6 +88,9 @@ public interface OverlayDecider extends Comparable { return PASS; } + /** + * {@inheritDoc} + */ @Override default int compareTo(OverlayDecider o) { return Double.compare(getPriority(), o.getPriority()); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java index b914a961d..ef932caed 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ScreenRegistry.java @@ -59,6 +59,11 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +/** + * The registry for handling bounds and exclusion details of screens. + * + * @see ScreenRegistry#exclusionZones() for registering exclusion zones. + */ @Environment(EnvType.CLIENT) public interface ScreenRegistry extends Reloadable { /** @@ -168,8 +173,23 @@ public interface ScreenRegistry extends Reloadable { */ Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); + /** + * Returns the focused stack given the mouse position. + * + * @param screen the screen to check + * @param mouse the mouse position + * @param the type of screen + * @return the focused stack, may be {@code null} if there are no focused stack + * @see ScreenRegistry#registerFocusedStack(FocusedStackProvider) + */ @Nullable EntryStack getFocusedStack(T screen, Point mouse); + /** + * Returns the exclusion zones registry for handling + * the registration and query of exclusion zones. + * + * @return the exclusion zones registry + */ ExclusionZones exclusionZones(); /** 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 46b11547a..732990437 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 @@ -61,13 +61,33 @@ public interface TransferHandler extends Comparable { return 0d; } + /** + * Handles the transfer of the specified display. + *

+ * If {@link Context#isActuallyCrafting()} returns {@code false}, + * the transfer handler should not instantiate the transfer. + * + * @param context the context + * @return the result of the transfer + */ Result handle(Context context); + /** + * {@inheritDoc} + */ @Override default int compareTo(TransferHandler o) { return Double.compare(getPriority(), o.getPriority()); } + /** + * Returns the error renderer given the context and the error data. + * + * @param context the context + * @param data the error data + * @return the error renderer, or {@code null} + * @deprecated use {@link Result#renderer(TransferHandlerRenderer)} directly instead + */ @Deprecated @Environment(EnvType.CLIENT) @Nullable @@ -167,11 +187,26 @@ public interface TransferHandler extends Comparable { @Deprecated Result errorRenderer(Object data); + /** + * Sets the renderer of the transfer, to be used when the mouse hovers the plus button. + */ Result renderer(TransferHandlerRenderer renderer); + /** + * Overrides the tooltip renderer completely. + * + * @param renderer the renderer + * @return the result + */ @ApiStatus.Experimental Result overrideTooltipRenderer(BiConsumer renderer); + /** + * Adds a line of tooltip to the result. + * + * @param component the component to add + * @return the result + */ Result tooltip(Component component); /** diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java index cb426d6c1..872b23e14 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java @@ -31,6 +31,9 @@ import me.shedaniel.rei.api.common.registry.Reloadable; import java.util.Collection; public interface Views extends Reloadable { + /** + * @return the instance of {@link Views} + */ static Views getInstance() { return PluginManager.getClientInstance().get(Views.class); } -- cgit