diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-02-21 22:12:48 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-02-21 22:13:05 +0800 |
| commit | 490a2e3fdd124562ed09f048beec5178555a36a4 (patch) | |
| tree | 35ae6c80dcde25fd829ef8c7ecbde71367947656 /src/main/java/me/shedaniel/rei/api | |
| parent | 4987103190a8bea7c8954512c389f9e768b8d5b3 (diff) | |
| download | RoughlyEnoughItems-490a2e3fdd124562ed09f048beec5178555a36a4.tar.gz RoughlyEnoughItems-490a2e3fdd124562ed09f048beec5178555a36a4.tar.bz2 RoughlyEnoughItems-490a2e3fdd124562ed09f048beec5178555a36a4.zip | |
4.0.4
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/api')
3 files changed, 67 insertions, 3 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index 1bd251725..7efc6d19a 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -12,6 +12,11 @@ import java.util.List; import java.util.function.Supplier; public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler<Screen> { + + static BaseBoundsHandler getInstance() { + return DisplayHelper.getInstance().getBaseBoundsHandler(); + } + /** * Gets the exclusion zones by the screen class * diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 2e1a174b1..a641eb372 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -8,7 +8,9 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.gui.config.SearchFieldLocation; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.util.ActionResult; +import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Supplier; @@ -34,8 +36,20 @@ public interface DisplayHelper { * Gets all registered bounds handlers * * @return the list of registered bounds handlers + * @deprecated see {@link #getAllOverlayDeciders()} */ - List<DisplayBoundsHandler<?>> getAllBoundsHandlers(); + @Deprecated + @ApiStatus.ScheduledForRemoval + default List<DisplayBoundsHandler<?>> getAllBoundsHandlers() { + return (List) CollectionUtils.castAndMap(getAllOverlayDeciders(), DisplayBoundsHandler.class); + } + + /** + * Gets all registered overlay deciders + * + * @return the list of registered overlay deciders + */ + List<OverlayDecider> getAllOverlayDeciders(); /** * Gets all responsible bounds handlers @@ -50,17 +64,31 @@ public interface DisplayHelper { * Registers a bounds handler * * @param handler the handler to register + * @deprecated see {@link #registerHandler(OverlayDecider)} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default void registerBoundsHandler(DisplayBoundsHandler<?> handler) { + registerHandler(handler); + } + + /** + * Registers a bounds decider + * + * @param decider the decider to register */ - void registerBoundsHandler(DisplayBoundsHandler<?> handler); + void registerHandler(OverlayDecider decider); /** * Gets the base bounds handler api for exclusion zones * * @return the base bounds handler + * @see BaseBoundsHandler#getInstance() */ + @ApiStatus.Internal BaseBoundsHandler getBaseBoundsHandler(); - interface DisplayBoundsHandler<T> { + interface DisplayBoundsHandler<T> extends OverlayDecider { /** * Gets the base supported class for the bounds handler * @@ -68,6 +96,11 @@ public interface DisplayHelper { */ Class<?> getBaseSupportedClass(); + @Override + default boolean isHandingScreen(Class<?> screen) { + return getBaseSupportedClass().isAssignableFrom(screen); + } + /** * Gets the left bounds of the overlay * @@ -140,6 +173,7 @@ public interface DisplayHelper { * * @return the priority in float */ + @Override default float getPriority() { return 0f; } diff --git a/src/main/java/me/shedaniel/rei/api/OverlayDecider.java b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java new file mode 100644 index 000000000..4f6120e2a --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/OverlayDecider.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018, 2019, 2020 shedaniel + * Licensed under the MIT License (the "License"). + */ + +package me.shedaniel.rei.api; + +import net.minecraft.util.ActionResult; + +public interface OverlayDecider { + boolean isHandingScreen(Class<?> screen); + + default ActionResult shouldScreenBeOverlayed(Class<?> screen) { + return ActionResult.PASS; + } + + /** + * Gets the priority of the handler, the higher it is, the earlier it is called. + * + * @return the priority in float + */ + default float getPriority() { + return 0f; + } +} |
