aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java20
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java55
3 files changed, 45 insertions, 32 deletions
diff --git a/gradle.properties b/gradle.properties
index 5dc2d45..cf9f8c1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,6 +6,6 @@ org.gradle.daemon=false
name=${rootProject.name}
group=com.anthonyhilyard.${name.toLowerCase()}
author=anthonyhilyard
-version=1.0.14
+version=1.0.15
mcVersion=1.17.1
forgeVersion=37.0.90
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
index 5b79256..bbd2d6b 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
@@ -1,6 +1,5 @@
package com.anthonyhilyard.iceberg.mixin;
-import java.util.ArrayList;
import java.util.List;
import com.anthonyhilyard.iceberg.util.StringRecomposer;
@@ -20,16 +19,18 @@ import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.events.AbstractContainerEventHandler;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.client.gui.screens.inventory.tooltip.ClientTextTooltip;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
-import net.minecraft.network.chat.FormattedText;
import net.minecraft.world.item.ItemStack;
+import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.common.MinecraftForge;
@Mixin(Screen.class)
public class ScreenMixin extends AbstractContainerEventHandler
{
+ @Shadow
+ protected Font font = null;
+
@Shadow(remap = false)
private Font tooltipFont = null;
@@ -48,18 +49,7 @@ public class ScreenMixin extends AbstractContainerEventHandler
{
if (!components.isEmpty())
{
- List<FormattedText> standinLines = new ArrayList<>();
- for (ClientTooltipComponent component : components)
- {
- if (component instanceof ClientTextTooltip)
- {
- StringRecomposer recomposer = new StringRecomposer();
- ((ClientTextTooltip)component).text.accept(recomposer);
- standinLines.add(recomposer.getFormattedText());
- }
- }
-
- MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(tooltipStack, standinLines, poseStack, postX, postY, tooltipFont, tooltipWidth, tooltipHeight));
+ MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(tooltipStack, StringRecomposer.recompose(components), poseStack, postX, postY, ForgeHooksClient.getTooltipFont(tooltipFont, tooltipStack, font), tooltipWidth, tooltipHeight));
}
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
index d88ae41..4ad448d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
@@ -1,32 +1,55 @@
package com.anthonyhilyard.iceberg.util;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTextTooltip;
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.FormattedCharSink;
-public class StringRecomposer implements FormattedCharSink
+public class StringRecomposer
{
- private StringBuilder builder = new StringBuilder();
- private MutableComponent text = new TextComponent("").withStyle(Style.EMPTY);
-
- @Override
- public boolean accept(int index, Style style, int charCode)
+ public static List<FormattedText> recompose(List<ClientTooltipComponent> components)
{
- builder.append(Character.toChars(charCode));
-
- if (!style.equals(text.getStyle()))
+ List<FormattedText> recomposedLines = new ArrayList<>();
+ for (ClientTooltipComponent component : components)
{
- text.append(new TextComponent(builder.toString()).withStyle(style));
- builder.setLength(0);
+ if (component instanceof ClientTextTooltip)
+ {
+ RecomposerSink recomposer = new RecomposerSink();
+ ((ClientTextTooltip)component).text.accept(recomposer);
+ recomposedLines.add(recomposer.getFormattedText());
+ }
}
- return true;
+ return recomposedLines;
}
-
- public FormattedText getFormattedText()
+
+ private static class RecomposerSink implements FormattedCharSink
{
- text.append(new TextComponent(builder.toString()).withStyle(text.getStyle()));
- return text;
+ private StringBuilder builder = new StringBuilder();
+ private MutableComponent text = new TextComponent("").withStyle(Style.EMPTY);
+
+ @Override
+ public boolean accept(int index, Style style, int charCode)
+ {
+ builder.append(Character.toChars(charCode));
+
+ if (!style.equals(text.getStyle()))
+ {
+ text.append(new TextComponent(builder.toString()).withStyle(style));
+ builder.setLength(0);
+ }
+ return true;
+ }
+
+ public FormattedText getFormattedText()
+ {
+ text.append(new TextComponent(builder.toString()).withStyle(text.getStyle()));
+ return text;
+ }
}
}