diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-03-16 16:19:25 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-03-16 16:19:25 +0800 |
| commit | 9e990de7685960391d78ca2cca0ff68bebe1a8cd (patch) | |
| tree | 1ce7e36a326d11d0d278bb070df9ba7984515c01 /src/main/java/me/shedaniel/rei/api | |
| parent | 921fbe77b6ebbbb7e5a78dc996ca5c98faf5fcc5 (diff) | |
| download | RoughlyEnoughItems-9e990de7685960391d78ca2cca0ff68bebe1a8cd.tar.gz RoughlyEnoughItems-9e990de7685960391d78ca2cca0ff68bebe1a8cd.tar.bz2 RoughlyEnoughItems-9e990de7685960391d78ca2cca0ff68bebe1a8cd.zip | |
4.0.13
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/api')
9 files changed, 183 insertions, 44 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java index 70ba2dd55..63f1d08a1 100644 --- a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java +++ b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -28,7 +28,7 @@ import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.ScreenWithHandler; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.screen.ScreenHandler; import org.jetbrains.annotations.ApiStatus; @@ -82,8 +82,8 @@ public interface AutoTransferHandler { } interface Context { - static Context create(boolean actuallyCrafting, ScreenWithHandler<?> containerScreen, RecipeDisplay recipeDisplay) { - return new ContextImpl(actuallyCrafting, containerScreen, () -> recipeDisplay); + static Context create(boolean actuallyCrafting, HandledScreen<?> handledScreen, RecipeDisplay recipeDisplay) { + return new ContextImpl(actuallyCrafting, handledScreen, () -> recipeDisplay); } default MinecraftClient getMinecraft() { @@ -92,12 +92,18 @@ public interface AutoTransferHandler { boolean isActuallyCrafting(); - ScreenWithHandler<?> getScreenWithHandler(); + HandledScreen<?> getHandledScreen(); @Deprecated @ApiStatus.ScheduledForRemoval - default ScreenWithHandler<?> getContainerScreen() { - return getScreenWithHandler(); + default HandledScreen<?> getScreenWithHandler() { + return getHandledScreen(); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default HandledScreen<?> getContainerScreen() { + return getHandledScreen(); } RecipeDisplay getRecipe(); @@ -174,12 +180,12 @@ public interface AutoTransferHandler { @ApiStatus.Internal final class ContextImpl implements Context { boolean actuallyCrafting; - ScreenWithHandler<?> screenWithHandler; + HandledScreen<?> handledScreen; Supplier<RecipeDisplay> recipeDisplaySupplier; - private ContextImpl(boolean actuallyCrafting, ScreenWithHandler<?> screenWithHandler, Supplier<RecipeDisplay> recipeDisplaySupplier) { + private ContextImpl(boolean actuallyCrafting, HandledScreen<?> handledScreen, Supplier<RecipeDisplay> recipeDisplaySupplier) { this.actuallyCrafting = actuallyCrafting; - this.screenWithHandler = screenWithHandler; + this.handledScreen = handledScreen; this.recipeDisplaySupplier = recipeDisplaySupplier; } @@ -189,8 +195,8 @@ public interface AutoTransferHandler { } @Override - public ScreenWithHandler<?> getScreenWithHandler() { - return screenWithHandler; + public HandledScreen<?> getHandledScreen() { + return handledScreen; } @Override diff --git a/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java index 77ebfd9f7..cef309c89 100644 --- a/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java +++ b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java @@ -24,10 +24,11 @@ package me.shedaniel.rei.api; import net.minecraft.client.gui.DrawableHelper; +import org.jetbrains.annotations.NotNull; /** * Consumer of a {@link DrawableHelper} and information of mouse and delta. */ public interface DrawableConsumer { - void render(DrawableHelper helper, int mouseX, int mouseY, float delta); + void render(@NotNull DrawableHelper helper, int mouseX, int mouseY, float delta); } diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 376ae2aef..c2d5241e2 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -25,7 +25,9 @@ package me.shedaniel.rei.api; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import me.shedaniel.math.Point; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.impl.EmptyEntryStack; import me.shedaniel.rei.impl.FluidEntryStack; @@ -229,7 +231,22 @@ public interface EntryStack { <T> T get(Settings<T> settings); - @Nullable QueuedTooltip getTooltip(int mouseX, int mouseY); + /** + * @deprecated Use {@link #getTooltip(Point)} + */ + @Nullable + @Deprecated + @ApiStatus.ScheduledForRemoval + default QueuedTooltip getTooltip(int mouseX, int mouseY) { + return null; + } + + @Nullable + default Tooltip getTooltip(Point point) { + QueuedTooltip tooltip = getTooltip(point.x, point.y); + if (tooltip == null) return null; + return Tooltip.create(new Point(tooltip.getX(), tooltip.getY()), tooltip.getText()); + } void render(Rectangle bounds, int mouseX, int mouseY, float delta); diff --git a/src/main/java/me/shedaniel/rei/api/REIHelper.java b/src/main/java/me/shedaniel/rei/api/REIHelper.java index 578d3d4bf..5c8c80209 100644 --- a/src/main/java/me/shedaniel/rei/api/REIHelper.java +++ b/src/main/java/me/shedaniel/rei/api/REIHelper.java @@ -23,10 +23,12 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.gui.widget.TextFieldWidget; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -46,6 +48,15 @@ public interface REIHelper { List<ItemStack> getInventoryStacks(); - void addTooltip(@Nullable QueuedTooltip tooltip); + /** + * @deprecated Use {@link #queueTooltip(Tooltip)} or {@link Tooltip#queue()} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default void addTooltip(@Nullable QueuedTooltip tooltip) { + queueTooltip(tooltip); + } + + void queueTooltip(@Nullable Tooltip tooltip); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 631217963..d491231b8 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -24,12 +24,12 @@ package me.shedaniel.rei.api; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; -import me.shedaniel.rei.gui.widget.PanelWidget; -import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.impl.widgets.PanelWidget; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; @@ -87,7 +87,7 @@ public interface RecipeCategory<T extends RecipeDisplay> { @ApiStatus.ScheduledForRemoval @Deprecated default List<Widget> setupDisplay(Supplier<T> recipeDisplaySupplier, me.shedaniel.math.api.Rectangle bounds) { - return Collections.singletonList(new RecipeBaseWidget(bounds)); + return Collections.singletonList(Widgets.createCategoryBase(bounds)); } /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index dfb2db0bd..122100fb0 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import net.minecraft.client.gui.screen.ingame.ScreenWithHandler; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -220,7 +220,7 @@ public interface RecipeHelper { */ void registerLiveRecipeGenerator(LiveRecipeGenerator<?> liveRecipeGenerator); - void registerScreenClickArea(Rectangle rectangle, Class<? extends ScreenWithHandler<?>> screenClass, Identifier... categories); + void registerScreenClickArea(Rectangle rectangle, Class<? extends HandledScreen<?>> screenClass, Identifier... categories); <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> mappingFunction); @@ -232,7 +232,7 @@ public interface RecipeHelper { boolean arePluginsLoading(); interface ScreenClickArea { - Class<? extends ScreenWithHandler> getScreenClass(); + Class<? extends HandledScreen> getScreenClass(); Rectangle getRectangle(); diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Slot.java b/src/main/java/me/shedaniel/rei/api/widgets/Slot.java index b5db286aa..285dddd22 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Slot.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Slot.java @@ -23,9 +23,11 @@ package me.shedaniel.rei.api.widgets; +import me.shedaniel.math.Point; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -123,5 +125,17 @@ public abstract class Slot extends WidgetWithBounds { public abstract List<EntryStack> getEntries(); - public abstract QueuedTooltip getCurrentTooltip(int mouseX, int mouseY); + /** + * @deprecated use {@link #getCurrentTooltip(Point)} + */ + @Nullable + @Deprecated + public QueuedTooltip getCurrentTooltip(int mouseX, int mouseY) { + return null; + } + + @Nullable + public Tooltip getCurrentTooltip(Point point) { + return getCurrentTooltip(point.x, point.y); + } } diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java b/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java new file mode 100644 index 000000000..147fcbf37 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java @@ -0,0 +1,59 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 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.widgets; + +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.gui.widget.QueuedTooltip; + +import java.util.Collection; +import java.util.List; + +public interface Tooltip { + static Tooltip create(Point point, Collection<String> texts) { + return QueuedTooltip.create(point, texts); + } + + static Tooltip create(Point point, String... texts) { + return QueuedTooltip.create(point, texts); + } + + static Tooltip create(Collection<String> texts) { + return QueuedTooltip.create(texts); + } + + static Tooltip create(String... texts) { + return QueuedTooltip.create(texts); + } + + int getX(); + + int getY(); + + List<String> getText(); + + default void queue() { + REIHelper.getInstance().queueTooltip(this); + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java index 286120716..da1f1ad02 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java @@ -43,96 +43,127 @@ import java.util.function.Consumer; public final class Widgets { private Widgets() {} - public static Widget createDrawableWidget(DrawableConsumer drawable) { + @NotNull + public static Widget createDrawableWidget(@NotNull DrawableConsumer drawable) { return new DrawableWidget(drawable); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds) { return createTexturedWidget(identifier, bounds, 0, 0); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, int width, int height) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, int width, int height) { return createTexturedWidget(identifier, x, y, 0, 0, width, height); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v) { return createTexturedWidget(identifier, bounds, u, v, 256, 256); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height) { return createTexturedWidget(identifier, x, y, u, v, width, height, 256, 256); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, bounds.x, bounds.y, u, v, bounds.width, bounds.height, bounds.width, bounds.height, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, x, y, u, v, width, height, width, height, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, bounds.x, bounds.y, u, v, bounds.width, bounds.height, uWidth, vHeight, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { return createDrawableWidget(new TexturedDrawableConsumer(identifier, x, y, width, height, u, v, uWidth, vHeight, textureWidth, textureHeight)); } - public static Widget createFilledRectangle(Rectangle rectangle, int color) { + @NotNull + public static Widget createFilledRectangle(@NotNull Rectangle rectangle, int color) { return createDrawableWidget(new FillRectangleDrawableConsumer(rectangle, color)); } - public static Label createLabel(Point point, @NotNull String text) { + @NotNull + public static Label createLabel(@NotNull Point point, @NotNull String text) { return new LabelWidget(point, text); } - public static Label createClickableLabel(Point point, @NotNull String text, @Nullable Consumer<Label> onClick) { + @NotNull + public static Label createClickableLabel(@NotNull Point point, @NotNull String text, @Nullable Consumer<Label> onClick) { return new LabelWidget(point, text).clickable().onClick(onClick); } - public static Arrow createArrow(Point point) { + @NotNull + public static Arrow createArrow(@NotNull Point point) { return new ArrowWidget(new Rectangle(point, new Dimension(24, 17))); } - public static BurningFire createBurningFire(Point point) { + @NotNull + public static BurningFire createBurningFire(@NotNull Point point) { return new BurningFireWidget(new Rectangle(point, new Dimension(14, 14))); } - public static Widget createSlotBackground(Point point) { + @NotNull + public static Widget createSlotBackground(@NotNull Point point) { return createSlotBase(new Rectangle(point.x - 1, point.y - 1, 18, 18)); } - public static Widget createResultSlotBackground(Point point) { + @NotNull + public static Widget createResultSlotBackground(@NotNull Point point) { return createSlotBase(new Rectangle(point.x - 5, point.y - 5, 26, 26)); } - public static Panel createRecipeBase(Rectangle rectangle) { + @NotNull + public static Panel createRecipeBase(@NotNull Rectangle rectangle) { return new PanelWidget(rectangle).yTextureOffset(ConfigObject.getInstance().getRecipeBorderType().getYOffset()).rendering(Widgets::shouldRecipeBaseRender); } - private static boolean shouldRecipeBaseRender(Panel panel) { + @NotNull + public static Panel createCategoryBase(@NotNull Rectangle rectangle) { + return new PanelWidget(rectangle).yTextureOffset(ConfigObject.getInstance().getRecipeBorderType().getYOffset()).rendering(Widgets::shouldSlotBaseRender); + } + + private static boolean shouldRecipeBaseRender(@NotNull Panel panel) { return ConfigObject.getInstance().getRecipeBorderType().isRendering() && PanelWidget.isRendering(panel); } - public static Panel createRecipeBase(Rectangle rectangle, int color) { + @NotNull + public static Panel createRecipeBase(@NotNull Rectangle rectangle, int color) { return createRecipeBase(rectangle).color(color); } - public static Panel createSlotBase(Rectangle rectangle) { + @NotNull + public static Panel createCategoryBase(@NotNull Rectangle rectangle, int color) { + return createCategoryBase(rectangle).color(color); + } + + @NotNull + public static Panel createSlotBase(@NotNull Rectangle rectangle) { return new PanelWidget(rectangle).yTextureOffset(-66).rendering(Widgets::shouldSlotBaseRender).innerColor(-7631989, -13619152); } - private static boolean shouldSlotBaseRender(Panel panel) { + private static boolean shouldSlotBaseRender(@NotNull Panel panel) { return true; } - public static Panel createSlotBase(Rectangle rectangle, int color) { + @NotNull + public static Panel createSlotBase(@NotNull Rectangle rectangle, int color) { return createSlotBase(rectangle).color(color); } @SuppressWarnings("deprecation") - public static Slot createSlot(Point point) { + @NotNull + public static Slot createSlot(@NotNull Point point) { return EntryWidget.create(point.x, point.y); } |
