diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-07-09 10:49:52 +0800 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-07-09 10:49:52 +0800 |
commit | 675913a65470a228eead892a2b1d58a4e2f253f5 (patch) | |
tree | 3e4b32a6e2b8ceaa5434c9b7c31df1f6fcc7da4b /src | |
parent | 85e5615bac19cf70d00653355f1e01e7d1849f37 (diff) | |
download | Skyblocker-675913a65470a228eead892a2b1d58a4e2f253f5.tar.gz Skyblocker-675913a65470a228eead892a2b1d58a4e2f253f5.tar.bz2 Skyblocker-675913a65470a228eead892a2b1d58a4e2f253f5.zip |
Update Title Container rendering
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java | 13 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java | 32 |
2 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java index 7dfef3d9..4f6b2fb4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java @@ -11,8 +11,8 @@ import net.minecraft.util.Formatting; */ public class Title { private MutableText text; - protected float lastX = 0; - protected float lastY = 0; + protected float x = -1; + protected float y = -1; /** * Constructs a new title with the given translation key and formatting to be applied. @@ -45,4 +45,13 @@ public class Title { public void setFormatting(Formatting formatting) { this.text.formatted(formatting); } + + protected boolean isDefaultPos() { + return x == -1 && y == -1; + } + + protected void resetPos() { + this.x = -1; + this.y = -1; + } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java index 10b2553a..a4e445ee 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainer.java @@ -55,8 +55,7 @@ public class TitleContainer { */ public static boolean addTitle(Title title) { if (titles.add(title)) { - title.lastX = 0; - title.lastY = SkyblockerConfig.get().general.titleContainer.y; + title.resetPos(); return true; } return false; @@ -126,10 +125,6 @@ public class TitleContainer { } for (Title title : titles) { - //Translate the matrix to the texts position and scale - context.getMatrices().push(); - context.getMatrices().translate(title.lastX, title.lastY, 200); - context.getMatrices().scale(scale, scale, scale); //Calculate which x the text should use float xToUse; @@ -144,10 +139,27 @@ public class TitleContainer { x - (textRenderer.getWidth(title.getText()) * scale) : //if right aligned we need the text position to be aligned on the right side. x; } + + //Start displaying the title at the correct position, not at the default position + if (title.isDefaultPos()) { + title.x = xToUse; + title.y = y; + } + //Lerp the texts x and y variables - title.lastX = MathHelper.lerp(tickDelta * 0.5F, title.lastX, xToUse); - title.lastY = MathHelper.lerp(tickDelta * 0.5F, title.lastY, y); + title.x = MathHelper.lerp(tickDelta * 0.5F, title.x, xToUse); + title.y = MathHelper.lerp(tickDelta * 0.5F, title.y, y); + + //Translate the matrix to the texts position and scale + context.getMatrices().push(); + context.getMatrices().translate(title.x, title.y, 200); + context.getMatrices().scale(scale, scale, scale); + + //Draw text + context.drawTextWithShadow(textRenderer, title.getText(), 0, 0, 0xFFFFFF); + context.getMatrices().pop(); + //Calculate the x and y positions for the next title if (direction == SkyblockerConfig.Direction.HORIZONTAL) { if (alignment == SkyblockerConfig.Alignment.MIDDLE || alignment == SkyblockerConfig.Alignment.LEFT) { //Move to the right if middle or left aligned @@ -162,10 +174,6 @@ public class TitleContainer { //Y always moves by the same amount if vertical y += textRenderer.fontHeight * scale + 10; } - - //Draw text - context.drawTextWithShadow(textRenderer, title.getText(), 0, 0, 0xFFFFFF); - context.getMatrices().pop(); } } }
\ No newline at end of file |