diff options
author | ExternalTime <84183548+ExternalTime@users.noreply.github.com> | 2021-09-03 23:01:59 +0200 |
---|---|---|
committer | ExternalTime <84183548+ExternalTime@users.noreply.github.com> | 2021-09-04 10:52:29 +0200 |
commit | 593f1b69860b127f784f188412106a0e29ab8b4d (patch) | |
tree | 4ad55d4db4de847af3382fd8534c263d3af253de /src | |
parent | b23331eb654e2e26d17d13616c05ffe3af822290 (diff) | |
download | Skyblocker-593f1b69860b127f784f188412106a0e29ab8b4d.tar.gz Skyblocker-593f1b69860b127f784f188412106a0e29ab8b4d.tar.bz2 Skyblocker-593f1b69860b127f784f188412106a0e29ab8b4d.zip |
Moved fancy status bars into a single class and rewrote action bar parsing
Diffstat (limited to 'src')
4 files changed, 129 insertions, 123 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/InGameHudMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/InGameHudMixin.java index b2a6dab2..f8a2a277 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/mixin/InGameHudMixin.java +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/InGameHudMixin.java @@ -3,14 +3,13 @@ package me.xmrvizzy.skyblocker.mixin; import com.mojang.blaze3d.systems.RenderSystem; import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; -import me.xmrvizzy.skyblocker.skyblock.Attribute; +import me.xmrvizzy.skyblocker.skyblock.FancyStatusBars; import me.xmrvizzy.skyblocker.skyblock.HotbarSlotLock; import me.xmrvizzy.skyblocker.skyblock.dungeon.DungeonMap; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.util.math.MatrixStack; @@ -23,15 +22,14 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Environment(EnvType.CLIENT) @Mixin(InGameHud.class) public abstract class InGameHudMixin extends DrawableHelper { private static final Identifier SLOT_LOCK = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/slot_lock.png"); - private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE,"textures/gui/bars.png"); + private final FancyStatusBars statusBars = new FancyStatusBars(); private MatrixStack hotbarMatrices; private int hotbarSlotIndex; @@ -42,15 +40,14 @@ public abstract class InGameHudMixin extends DrawableHelper { private int scaledHeight; @Shadow private int scaledWidth; - @Shadow - public abstract TextRenderer getTextRenderer(); - @ModifyVariable(method = "setOverlayMessage(Lnet/minecraft/text/Text;Z)V", at = @At("HEAD")) - private Text setOverlayMessage(Text message) { + @Inject(method = "setOverlayMessage(Lnet/minecraft/text/Text;Z)V", at = @At("HEAD"), cancellable = true) + private void onSetOverlayMessage(Text message, boolean tinted, CallbackInfo ci) { + if(!Utils.isSkyblock) + return; String msg = message.getString(); - if (msg != null && Utils.isSkyblock && SkyblockerConfig.get().general.bars.enableBars) - msg = Utils.parseActionBar(msg); - return Text.of(msg); + if(statusBars.update(msg)) + ci.cancel(); } @Inject(method = "renderHotbar", at = @At("HEAD")) @@ -80,16 +77,15 @@ public abstract class InGameHudMixin extends DrawableHelper { @Inject(method = "renderStatusBars", at = @At("HEAD"), cancellable = true) private void renderStatusBars(MatrixStack matrices, CallbackInfo ci) { + if(!Utils.isSkyblock) + return; + if(statusBars.render(matrices, scaledWidth, scaledHeight)) + ci.cancel(); + if (Utils.isDungeons && SkyblockerConfig.get().locations.dungeons.enableMap) DungeonMap.render(matrices); - if (Utils.isSkyblock) { - if (SkyblockerConfig.get().general.bars.enableBars) { - ci.cancel(); - renderBars(matrices); - } - this.client.getTextureManager().bindTexture(DrawableHelper.GUI_ICONS_TEXTURE); - } + this.client.getTextureManager().bindTexture(DrawableHelper.GUI_ICONS_TEXTURE); } @Inject(method = "renderMountHealth", at = @At("HEAD"), cancellable = true) @@ -97,56 +93,4 @@ public abstract class InGameHudMixin extends DrawableHelper { if (Utils.isSkyblock && SkyblockerConfig.get().general.bars.enableBars) ci.cancel(); } - - private void renderBars(MatrixStack matrices) { - int left = this.scaledWidth / 2 - 91; - int top = this.scaledHeight - 35; - - int health = (int) ((float)Attribute.HEALTH.get()/(float)Attribute.MAX_HEALTH.get() * 33.0F); - if (health > 33) health = 33; - int mana = (int) ((float)Attribute.MANA.get()/(float)Attribute.MAX_MANA.get() * 33.0F); - if (mana > 33) mana = 33; - int xp = (int) (this.client.player.experienceProgress * 33.0F); - - // Icons -// this.client.getTextureManager().bindTexture(BARS); - RenderSystem.setShaderTexture(0,InGameHudMixin.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, health, 7); - this.drawTexture(matrices, left + 55, top + 1, 0, 23, mana, 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, Attribute.HEALTH.get(), left + 11, top, 16733525); - renderText(matrices, Attribute.MANA.get(), left + 56, top, 5636095); - renderText(matrices, Attribute.DEFENCE.get(), left + 103, top, 12106180); - renderText(matrices, this.client.player.experienceLevel, left + 150, top, 8453920); - - } - - private void renderText(MatrixStack matrices, int value, int left, int top, int color) { - String text = Integer.toString(value); - int x = left + (33 - this.getTextRenderer().getWidth(text)) / 2; - int y = top - 3; - - this.getTextRenderer().draw(matrices, text, (float) (x + 1), (float) y, 0); - this.getTextRenderer().draw(matrices, text, (float) (x - 1), (float) y, 0); - this.getTextRenderer().draw(matrices, text, (float) x, (float) (y + 1), 0); - this.getTextRenderer().draw(matrices, text, (float) x, (float) (y - 1), 0); - this.getTextRenderer().draw(matrices, text, (float) x, (float) y, color); - } - - }
\ No newline at end of file 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 diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java index 538de291..de431aac 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java @@ -2,8 +2,6 @@ package me.xmrvizzy.skyblocker.utils; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import me.xmrvizzy.skyblocker.config.SkyblockerConfig; -import me.xmrvizzy.skyblocker.skyblock.Attribute; import me.xmrvizzy.skyblocker.skyblock.item.PriceInfoTooltip; import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.minecraft.client.MinecraftClient; @@ -16,42 +14,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.regex.Pattern; import java.util.stream.Collectors; public class Utils { public static boolean isSkyblock = false; public static boolean isDungeons = false; public static boolean isInjected = false; - public static String parseActionBar(String msg) { - String[] sections = msg.split(" {3,}"); - List<String> unused = new ArrayList<String>(); - - if (msg.contains("❤") && !msg.contains("❈") && sections.length == 2) { - Attribute.DEFENCE.set(0); - } - - for (String section : sections) { - String clear = Pattern.compile("[^0-9 /]").matcher(section).replaceAll("").trim(); - String[] split = clear.split("/"); - - if (section.contains("❤")) { - if (section.startsWith("§6")) split[0] = split[0].substring(1); - Attribute.HEALTH.set(Integer.parseInt(split[0])); - Attribute.MAX_HEALTH.set(Integer.parseInt(split[1])); - } else if (section.contains("❈")) { - Attribute.DEFENCE.set(Integer.parseInt(clear)); - } else if (section.contains("✎")) { - Attribute.MANA.set(Integer.parseInt(split[0])); - Attribute.MAX_MANA.set(Integer.parseInt(split[1])); - } else { - if (section.contains("Drill Fuel") && SkyblockerConfig.get().locations.dwarvenMines.enableDrillFuel) continue; - unused.add(section); - } - } - - return String.join(" ", unused); - } public static void sbChecker() { List<String> sidebar = getSidebar(); |