diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-06-17 00:25:50 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-05-29 20:58:05 +0800 |
| commit | 64a563ea081e6219b29befc1e4b7eed4d9dd154e (patch) | |
| tree | 5c326af52686959057b435dec6604533da03cfec /runtime/src/main/java | |
| parent | f72f1a02b30a82cf0c2de1a3bb3c4f054ad90845 (diff) | |
| download | RoughlyEnoughItems-64a563ea081e6219b29befc1e4b7eed4d9dd154e.tar.gz RoughlyEnoughItems-64a563ea081e6219b29befc1e4b7eed4d9dd154e.tar.bz2 RoughlyEnoughItems-64a563ea081e6219b29befc1e4b7eed4d9dd154e.zip | |
Close #910
Diffstat (limited to 'runtime/src/main/java')
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.java | 82 | ||||
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java | 7 |
2 files changed, 89 insertions, 0 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.java new file mode 100644 index 000000000..7afa419ed --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.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.gui.widget; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.impl.display.DisplaySpec; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.world.inventory.tooltip.TooltipComponent; + +import java.util.List; + +public class DisplayTooltipComponent implements TooltipComponent, ClientTooltipComponent { + private final Widget widget; + private final DisplaySpec display; + private final Rectangle bounds; + + public DisplayTooltipComponent(DisplaySpec display) { + Display internalDisplay = display.provideInternalDisplay(); + CategoryRegistry.CategoryConfiguration<Display> configuration = CategoryRegistry.getInstance().get((CategoryIdentifier<Display>) internalDisplay.getCategoryIdentifier()); + DisplayCategory<Display> category = configuration.getCategory(); + this.bounds = new Rectangle(0, 0, category.getDisplayWidth(internalDisplay), category.getDisplayHeight()); + List<Widget> widgets = configuration.getView(internalDisplay).setupDisplay(internalDisplay, bounds); + + this.display = display; + this.widget = Widgets.concat(widgets); + } + + public DisplayTooltipComponent(DisplaySpec display, List<Widget> widgets, Rectangle bounds) { + this.widget = Widgets.concat(widgets); + this.display = display; + this.bounds = bounds; + } + + @Override + public int getHeight() { + return bounds.height + 4; + } + + @Override + public int getWidth(Font font) { + return bounds.width + 4; + } + + @Override + public void renderImage(Font font, int x, int y, PoseStack matrices, ItemRenderer itemRenderer, int z) { + matrices.pushPose(); + matrices.translate(x + 2, y + 2, z); + matrices.translate(-this.bounds.getX(), -this.bounds.getY(), 0); + widget.render(matrices, -1000, -1000, 0); + matrices.popPose(); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index dc442e879..060938c6c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.widget; +import com.google.common.base.Suppliers; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -62,6 +63,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.TextComponent; @@ -73,6 +75,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.function.Supplier; import java.util.function.UnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -100,6 +103,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { private long lastCheckTime = -1; private Display display; + private Supplier<DisplayTooltipComponent> displayTooltipComponent; public EntryWidget(Point point) { this(new Rectangle(point.x - 1, point.y - 1, 18, 18)); @@ -310,6 +314,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, null); if (result.successful) { this.display = display; + this.displayTooltipComponent = Suppliers.memoize(() -> new DisplayTooltipComponent(display)); return result.successfulHandler; } } @@ -333,6 +338,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { } display = null; + displayTooltipComponent = null; lastCheckTime = -1; } @@ -411,6 +417,7 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { if (tooltip != null && getTransferHandler() != null && !(Minecraft.getInstance().screen instanceof DisplayScreen)) { tooltip.add(new TranslatableComponent("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW)); + tooltip.add((ClientTooltipComponent) displayTooltipComponent.get()); } if (tooltip != null) { |
