From 593f1b69860b127f784f188412106a0e29ab8b4d Mon Sep 17 00:00:00 2001 From: ExternalTime <84183548+ExternalTime@users.noreply.github.com> Date: Fri, 3 Sep 2021 23:01:59 +0200 Subject: Moved fancy status bars into a single class and rewrote action bar parsing --- .../me/xmrvizzy/skyblocker/skyblock/Attribute.java | 21 ---- .../skyblocker/skyblock/FancyStatusBars.java | 115 +++++++++++++++++++++ 2 files changed, 115 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/Attribute.java create mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/Attribute.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/Attribute.java deleted file mode 100644 index 45532642..00000000 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/Attribute.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.xmrvizzy.skyblocker.skyblock; - -public enum Attribute { - HEALTH(100), - MAX_HEALTH(100), - MANA(100), - MAX_MANA(100), - DEFENCE(0); - - private int value; - Attribute(int value) { - this.value = value; - } - - public int get() { - return value; - } - public void set(int value) { - this.value = value; - } -} \ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java new file mode 100644 index 00000000..b0bf6191 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java @@ -0,0 +1,115 @@ +package me.xmrvizzy.skyblocker.skyblock; + +import com.mojang.blaze3d.systems.RenderSystem; +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class FancyStatusBars extends DrawableHelper { + private static final MinecraftClient client = MinecraftClient.getInstance(); + private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE,"textures/gui/bars.png"); + private static final Pattern ACTION_BAR_STATUS = Pattern.compile("§[6c]([0-9]+)/([0-9])+❤ +§(a([0-9]+)§a❈ Defense|b-[0-9]+ Mana \\(§6[a-zA-Z ]+§b\\)) +§((b([0-9]+)/([0-9]+)✎ Mana)|[0-9,]+/[0-9,]+k? Drill Fuel)$"); + private final Resource health; + private final Resource mana; + private int defense; + + public FancyStatusBars() { + health = new Resource(100, 100); + mana = new Resource(100, 100); + defense = 0; + } + + public boolean update(String actionBar) { + if(!SkyblockerConfig.get().general.bars.enableBars) + return false; + Matcher matcher = ACTION_BAR_STATUS.matcher(actionBar); + if(!matcher.matches()) { + return false; + } + health.set(matcher.group(1), matcher.group(2)); + if(matcher.group(4) != null) + defense = Integer.parseInt(matcher.group(4)); + if(matcher.group(6) != null) + mana.set(matcher.group(7), matcher.group(8)); + return true; + } + + public boolean render(MatrixStack matrices, int scaledWidth, int scaledHeight) { + if(!SkyblockerConfig.get().general.bars.enableBars) + return false; + int left = scaledWidth / 2 - 91; + int top = scaledHeight - 35; + + int hpBarWidth = (int) (health.getFillLevel() * 33.0F); + if (hpBarWidth > 33) hpBarWidth = 33; + int manaBarWidth = (int) (mana.getFillLevel() * 33.0F); + if (manaBarWidth > 33) manaBarWidth = 33; + int xp = (int) (client.player.experienceProgress * 33.0F); + + // Icons +// this.client.getTextureManager().bindTexture(BARS); + RenderSystem.setShaderTexture(0, BARS); + this.drawTexture(matrices, left, top, 0, 0, 9, 9); + this.drawTexture(matrices, left + 47, top, 9, 0, 7, 9); + this.drawTexture(matrices, left + 92, top, 16, 0, 9, 9); + this.drawTexture(matrices, left + 139, top, 25, 0, 9, 9); + + // Empty Bars + this.drawTexture(matrices, left + 10, top + 1, 0, 9, 33, 7); + this.drawTexture(matrices, left + 55, top + 1, 0, 9, 33, 7); + this.drawTexture(matrices, left + 102, top + 1, 0, 9, 33, 7); + this.drawTexture(matrices, left + 149, top + 1, 0, 9, 33, 7); + + // Progress Bars + this.drawTexture(matrices, left + 10, top + 1, 0, 16, hpBarWidth, 7); + this.drawTexture(matrices, left + 55, top + 1, 0, 23, manaBarWidth, 7); + this.drawTexture(matrices, left + 102, top + 1, 0, 30, 33, 7); + this.drawTexture(matrices, left + 149, top + 1, 0, 37, xp, 7); + + // Progress Texts + renderText(matrices, this.health.getValue(), left + 11, top, 16733525); + renderText(matrices, this.mana.getValue(), left + 56, top, 5636095); + renderText(matrices, this.defense, left + 103, top, 12106180); + renderText(matrices, this.client.player.experienceLevel, left + 150, top, 8453920); + return true; + } + + private void renderText(MatrixStack matrices, int value, int left, int top, int color) { + TextRenderer textRenderer = client.textRenderer; + String text = Integer.toString(value); + int x = left + (33 - textRenderer.getWidth(text)) / 2; + int y = top - 3; + + textRenderer.draw(matrices, text, (float) (x + 1), (float) y, 0); + textRenderer.draw(matrices, text, (float) (x - 1), (float) y, 0); + textRenderer.draw(matrices, text, (float) x, (float) (y + 1), 0); + textRenderer.draw(matrices, text, (float) x, (float) (y - 1), 0); + textRenderer.draw(matrices, text, (float) x, (float) y, color); + } + + private static class Resource { + private int value; + private int max; + public Resource(int value, int max) { + this.value = value; + this.max = max; + } + public void set(String value, String max) { + this.value = Integer.parseInt(value); + this.max = Integer.parseInt(max); + } + public int getValue() { + return value; + } + public double getFillLevel() { + return ((double)value)/((double)max); + } + } +} \ No newline at end of file -- cgit From 2218029deea14b1a1789f51cdf6b491a6eb027d5 Mon Sep 17 00:00:00 2001 From: ExternalTime <84183548+ExternalTime@users.noreply.github.com> Date: Sat, 4 Sep 2021 17:30:36 +0200 Subject: Improved regex and made few cosmetic changes --- .../skyblocker/skyblock/FancyStatusBars.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java index b0bf6191..996c48b6 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java @@ -15,7 +15,7 @@ import java.util.regex.Pattern; public class FancyStatusBars extends DrawableHelper { private static final MinecraftClient client = MinecraftClient.getInstance(); private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE,"textures/gui/bars.png"); - private static final Pattern ACTION_BAR_STATUS = Pattern.compile("§[6c]([0-9]+)/([0-9])+❤ +§(a([0-9]+)§a❈ Defense|b-[0-9]+ Mana \\(§6[a-zA-Z ]+§b\\)) +§((b([0-9]+)/([0-9]+)✎ Mana)|[0-9,]+/[0-9,]+k? Drill Fuel)$"); + private static final Pattern ACTION_BAR_STATUS = Pattern.compile("^§[6c]([0-9]+)/([0-9])+❤ +§(?:a([0-9]+)§a❈ Defense|b-[0-9]+ Mana \\(§6[a-zA-Z ]+§b\\)) +§(?:b([0-9]+)/([0-9]+)✎ Mana|[0-9,]+/[0-9,]+k? Drill Fuel)$"); private final Resource health; private final Resource mana; private int defense; @@ -34,10 +34,10 @@ public class FancyStatusBars extends DrawableHelper { return false; } health.set(matcher.group(1), matcher.group(2)); + if(matcher.group(3) != null) + defense = Integer.parseInt(matcher.group(3)); if(matcher.group(4) != null) - defense = Integer.parseInt(matcher.group(4)); - if(matcher.group(6) != null) - mana.set(matcher.group(7), matcher.group(8)); + mana.set(matcher.group(4), matcher.group(5)); return true; } @@ -47,10 +47,10 @@ public class FancyStatusBars extends DrawableHelper { int left = scaledWidth / 2 - 91; int top = scaledHeight - 35; - int hpBarWidth = (int) (health.getFillLevel() * 33.0F); - if (hpBarWidth > 33) hpBarWidth = 33; - int manaBarWidth = (int) (mana.getFillLevel() * 33.0F); - if (manaBarWidth > 33) manaBarWidth = 33; + int hpFillWidth = (int) (health.getFillLevel() * 33.0F); + if (hpFillWidth > 33) hpFillWidth = 33; + int manaFillWidth = (int) (mana.getFillLevel() * 33.0F); + if (manaFillWidth > 33) manaFillWidth = 33; int xp = (int) (client.player.experienceProgress * 33.0F); // Icons @@ -68,16 +68,16 @@ public class FancyStatusBars extends DrawableHelper { this.drawTexture(matrices, left + 149, top + 1, 0, 9, 33, 7); // Progress Bars - this.drawTexture(matrices, left + 10, top + 1, 0, 16, hpBarWidth, 7); - this.drawTexture(matrices, left + 55, top + 1, 0, 23, manaBarWidth, 7); + this.drawTexture(matrices, left + 10, top + 1, 0, 16, hpFillWidth, 7); + this.drawTexture(matrices, left + 55, top + 1, 0, 23, manaFillWidth, 7); this.drawTexture(matrices, left + 102, top + 1, 0, 30, 33, 7); this.drawTexture(matrices, left + 149, top + 1, 0, 37, xp, 7); // Progress Texts - renderText(matrices, this.health.getValue(), left + 11, top, 16733525); - renderText(matrices, this.mana.getValue(), left + 56, top, 5636095); - renderText(matrices, this.defense, left + 103, top, 12106180); - renderText(matrices, this.client.player.experienceLevel, left + 150, top, 8453920); + renderText(matrices, health.getValue(), left + 11, top, 16733525); + renderText(matrices, mana.getValue(), left + 56, top, 5636095); + renderText(matrices, defense, left + 103, top, 12106180); + renderText(matrices, client.player.experienceLevel, left + 150, top, 8453920); return true; } -- cgit