aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/util
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2022-11-04 23:15:54 -0700
committerAnthony Hilyard <anthony.hilyard@gmail.com>2022-11-04 23:15:54 -0700
commit379e47c13645498bc9fe3c810bef4bba5994504b (patch)
tree1dd63744699f9f0fc7929f835765084494537410 /src/main/java/com/anthonyhilyard/iceberg/util
parent20077907084aa2167ba5e66ae974c69121366b47 (diff)
downloadIceberg-379e47c13645498bc9fe3c810bef4bba5994504b.tar.gz
Iceberg-379e47c13645498bc9fe3c810bef4bba5994504b.tar.bz2
Iceberg-379e47c13645498bc9fe3c810bef4bba5994504b.zip
Ported 1.0.49 changes.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
index 6bcb2b0..db952f8 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
@@ -16,6 +16,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTextTooltip;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.Rect2i;
@@ -171,12 +172,18 @@ public class Tooltips
poseStack.translate(0.0D, 0.0D, zLevel);
int tooltipTop = rectY;
+ boolean titleRendered = false;
for (int componentNumber = 0; componentNumber < info.getComponents().size(); ++componentNumber)
{
ClientTooltipComponent textComponent = info.getComponents().get(componentNumber);
textComponent.renderText(preEvent.getFont(), rectX, tooltipTop, mat, renderType);
- tooltipTop += textComponent.getHeight() + (componentNumber == 0 ? 2 : 0);
+ tooltipTop += textComponent.getHeight();
+ if (!titleRendered && textComponent instanceof ClientTextTooltip)
+ {
+ tooltipTop += 2;
+ titleRendered = true;
+ }
}
renderType.endBatch();
@@ -345,8 +352,23 @@ public class Tooltips
}
// TODO: If the title is multiple lines, we need to extend this for each one.
+ // Find the title component, which is the first text component.
+ int titleIndex = 0;
+ for (ClientTooltipComponent clienttooltipcomponent : components)
+ {
+ if (clienttooltipcomponent instanceof ClientTextTooltip)
+ {
+ break;
+ }
+ titleIndex++;
+ }
+
+ if (titleIndex >= components.size())
+ {
+ titleIndex = 0;
+ }
- List<FormattedText> recomposedLines = StringRecomposer.recompose(List.of(components.get(0)));
+ List<FormattedText> recomposedLines = StringRecomposer.recompose(List.of(components.get(titleIndex)));
if (recomposedLines.isEmpty())
{
return components;
@@ -355,14 +377,15 @@ public class Tooltips
List<ClientTooltipComponent> result = new ArrayList<>(components);
FormattedCharSequence title = Language.getInstance().getVisualOrder(recomposedLines.get(0));
- while (result.get(0).getWidth(font) < tooltipWidth)
+ while (result.get(titleIndex).getWidth(font) < tooltipWidth)
{
title = FormattedCharSequence.fromList(List.of(SPACE, title, SPACE));
if (title == null)
{
break;
}
- result.set(0, ClientTooltipComponent.create(title));
+
+ result.set(titleIndex, ClientTooltipComponent.create(title));
}
return result;
}