From 4671c52193eb5b855d1104d064b98c3c3edb9ef2 Mon Sep 17 00:00:00 2001 From: Westsi <76999267+Westsi@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:04:56 +0100 Subject: [PATCH 1/5] Added speed status bar --- .../config/configs/UIAndVisualsConfig.java | 2 + .../skyblocker/skyblock/StatusBarTracker.java | 40 ++++++++++++++++++ .../skyblock/fancybars/FancyStatusBars.java | 9 +++- .../assets/skyblocker/lang/en_us.json | 5 ++- .../textures/gui/sprites/bars/icons/speed.png | Bin 0 -> 136 bytes 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/assets/skyblocker/textures/gui/sprites/bars/icons/speed.png diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index 7333b1adf2..c387686d4e 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -179,6 +179,8 @@ public static class OldBarPositions { @SerialEntry public OldBarPosition experienceBarPosition = OldBarPosition.LAYER1; + @SerialEntry + public OldBarPosition speedBarPosition = OldBarPosition.LAYER1; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java index 717bd8d6e0..5938f76e1b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java @@ -1,10 +1,12 @@ package de.hysky.skyblocker.skyblock; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import java.util.regex.Matcher; @@ -18,6 +20,7 @@ public class StatusBarTracker { private Resource health = new Resource(100, 100, 0); private Resource mana = new Resource(100, 100, 0); + private Resource speed = new Resource(100, 400, 0); private int defense = 0; public void init() { @@ -37,6 +40,11 @@ public int getDefense() { return this.defense; } + public Resource getSpeed() { + updateSpeed(); + return this.speed; + } + private int parseInt(Matcher m, int group) { return Integer.parseInt(m.group(group).replace(",", "")); } @@ -48,6 +56,38 @@ private void updateMana(Matcher m) { this.mana = new Resource(value, max, overflow); } + private void updateSpeed() { + // Black cat and racing helm are untested - I don't have the money to test atm, but no reason why they shouldn't work + var player = MinecraftClient.getInstance().player; + int value = (int) (player.isSprinting() ? (player.getMovementSpeed() / 1.3f) * 1000 : player.getMovementSpeed() * 1000); + int max = 400; // hardcoded limit (except for with cactus knife, black cat, snail, racing helm, young drag) + if (player.getMainHandStack().getName().getString().contains("Cactus Knife") && Utils.getLocation() == Location.GARDEN) { + max = 500; + } + Iterable armor = player.getArmorItems(); + int youngDragCount = 0; + for (ItemStack armorPiece : armor) { + if (armorPiece.getName().getString().contains("Racing Helmet")) { + max = 500; + } else if (armorPiece.getName().getString().contains("Young Dragon")) { + youngDragCount++; + } + } + if (youngDragCount == 4) { + max = 500; + } + + PetCache.PetInfo pet = PetCache.getCurrentPet(); + if (pet != null) { + if (pet.type().contains("BLACK_CAT")) { + max = 500; + } else if (pet.type().contains("SNAIL")) { + max = 100; + } + } + this.speed = new Resource(value, max, 0); + } + private void updateHealth(Matcher m) { int value = parseInt(m, 1); int max = parseInt(m, 3); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java index c60fdd1afd..74ad928593 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java @@ -27,8 +27,8 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.*; import java.util.List; +import java.util.*; import java.util.concurrent.CompletableFuture; public class FancyStatusBars { @@ -64,6 +64,9 @@ public static void init() { statusBars.put("experience", new StatusBar(Identifier.of(SkyblockerMod.NAMESPACE, "bars/icons/experience"), new Color[]{new Color(100, 230, 70)}, false, new Color(128, 255, 32), Text.translatable("skyblocker.bars.config.experience"))); + statusBars.put("speed", new StatusBar(Identifier.of(SkyblockerMod.NAMESPACE, "bars/icons/speed"), + new Color[]{new Color(255, 255, 255)}, + false, new Color(185, 185, 185), Text.translatable("skyblocker.bars.config.speed"))); // Fetch from old status bar config int[] counts = new int[3]; // counts for RIGHT, LAYER1, LAYER2 @@ -76,6 +79,8 @@ public static void init() { loadOldBarPosition(defense, counts, barPositions.defenceBarPosition); StatusBar experience = statusBars.get("experience"); loadOldBarPosition(experience, counts, barPositions.experienceBarPosition); + StatusBar speed = statusBars.get("speed"); + loadOldBarPosition(speed, counts, barPositions.speedBarPosition); CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> { if (object != null) { @@ -304,6 +309,8 @@ public boolean render(DrawContext context, int scaledWidth, int scaledHeight) { statusBars.get("intelligence").updateValues(intelligence.value() / (float) intelligence.max(), intelligence.overflow() / (float) intelligence.max(), intelligence.value()); int defense = statusBarTracker.getDefense(); statusBars.get("defense").updateValues(defense / (defense + 100.f), 0, defense); + StatusBarTracker.Resource speed = statusBarTracker.getSpeed(); + statusBars.get("speed").updateValues(speed.value() / (float) speed.max(), 0, speed.value()); statusBars.get("experience").updateValues(player.experienceProgress, 0, player.experienceLevel); return true; } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index b0537af03d..8cba06dc4c 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -694,7 +694,7 @@ "skyblocker.config.uiAndVisuals.hideStatusEffectOverlay": "Hide Status Effect Overlay", - "skyblocker.config.uiAndVisuals.bars": "Health, Mana, Defence & XP Bars", + "skyblocker.config.uiAndVisuals.bars": "Health, Mana, Defence, Speed & XP Bars", "skyblocker.config.uiAndVisuals.bars.enableBars": "Enable Bars", "skyblocker.config.uiAndVisuals.chestValue": "Chest Value", @@ -813,6 +813,7 @@ "skyblocker.bars.config.defense": "Defense", "skyblocker.bars.config.intelligence": "Intelligence", "skyblocker.bars.config.experience": "Experience", + "skyblocker.bars.config.speed": "Speed", "skyblocker.bars.config.mainColor": "Main Color", "skyblocker.bars.config.overflowColor": "Overflow Color", "skyblocker.bars.config.textColor": "Text Color", @@ -1022,7 +1023,7 @@ "skyblocker.tips.eventNotifications": "Check out the customizable event notifications in the config.", "skyblocker.tips.signCalculator": "Type an math expression in a sign to have the mod calculate it for you.", "skyblocker.tips.calculateCommand": "Enter an expression after /skyblocker calculate to have the mod calculate it for you.", - "skyblocker.tips.fancierBars": "Customize the look of your health, mana, defense, and experience bars with /skyblocker bars. You can snap and resize bars too!", + "skyblocker.tips.fancierBars": "Customize the look of your health, mana, defense, speed, and experience bars with /skyblocker bars. You can snap and resize bars too!", "skyblocker.tips.crystalWaypointsShare": "Share Crystal Hollows Waypoints with /skyblocker crystalWaypoints share.", "skyblocker.tips.gardenMouseLock": "Lock your mouse while farming in the Skyblocker Garden config.", "skyblocker.tips.newYearCakesHelper": "Open your New Year Cake Bag and Skyblocker will remember them and highlight duplicate cakes red and missing cakes green.", diff --git a/src/main/resources/assets/skyblocker/textures/gui/sprites/bars/icons/speed.png b/src/main/resources/assets/skyblocker/textures/gui/sprites/bars/icons/speed.png new file mode 100644 index 0000000000000000000000000000000000000000..0a110a12bb94ae85b6da6706c90b244e284e7654 GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{VjKx9jP7LeL$-D$|oIG6|Lo|YW zF9dQiC~z=ec>AwCPDJDKqFeF5xF+9FX82NM$uL1>!s Date: Wed, 21 Aug 2024 18:35:33 +0100 Subject: [PATCH 2/5] Update src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java Co-authored-by: Kevin <92656833+kevinthegreat1@users.noreply.github.com> --- .../de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index c387686d4e..e02f86d779 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -179,9 +179,6 @@ public static class OldBarPositions { @SerialEntry public OldBarPosition experienceBarPosition = OldBarPosition.LAYER1; - @SerialEntry - public OldBarPosition speedBarPosition = OldBarPosition.LAYER1; - } /** From 0921866d08f551f8c0994f7fb746c3deaaa8f7b2 Mon Sep 17 00:00:00 2001 From: Westsi <76999267+Westsi@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:35:40 +0100 Subject: [PATCH 3/5] Update src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java Co-authored-by: Kevin <92656833+kevinthegreat1@users.noreply.github.com> --- .../de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java index 74ad928593..c3bba3a6ea 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java @@ -79,8 +79,6 @@ public static void init() { loadOldBarPosition(defense, counts, barPositions.defenceBarPosition); StatusBar experience = statusBars.get("experience"); loadOldBarPosition(experience, counts, barPositions.experienceBarPosition); - StatusBar speed = statusBars.get("speed"); - loadOldBarPosition(speed, counts, barPositions.speedBarPosition); CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> { if (object != null) { From b2a6bee126615d75b0d8a9b5f91fe77a79d24a79 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Thu, 22 Aug 2024 02:01:01 +0800 Subject: [PATCH 4/5] Initialize speed bar --- .../config/configs/UIAndVisualsConfig.java | 23 ++++++++++++------- .../skyblock/fancybars/FancyStatusBars.java | 17 ++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index e02f86d779..f18edf9a3f 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -160,31 +160,38 @@ public static class Bars { public boolean enableBars = true; // Kept in for backwards compatibility, remove if needed + @SuppressWarnings("DeprecatedIsStillUsed") + @Deprecated @SerialEntry - public OldBarPositions barPositions = new OldBarPositions(); + public LegacyBarPositions barPositions = new LegacyBarPositions(); } /** - * Backwards compat + * Backwards compat. + *

+ * Used to load the legacy bar positions, which will not have an effect once the bars are saved in the new format at {@code /skyblocker/status_bars.json}. + * New bars do not need to be added here. */ - public static class OldBarPositions { + @SuppressWarnings("DeprecatedIsStillUsed") + @Deprecated + public static class LegacyBarPositions { @SerialEntry - public OldBarPosition healthBarPosition = OldBarPosition.LAYER1; + public LegacyBarPosition healthBarPosition = LegacyBarPosition.LAYER1; @SerialEntry - public OldBarPosition manaBarPosition = OldBarPosition.LAYER1; + public LegacyBarPosition manaBarPosition = LegacyBarPosition.LAYER1; @SerialEntry - public OldBarPosition defenceBarPosition = OldBarPosition.LAYER1; + public LegacyBarPosition defenceBarPosition = LegacyBarPosition.LAYER1; @SerialEntry - public OldBarPosition experienceBarPosition = OldBarPosition.LAYER1; + public LegacyBarPosition experienceBarPosition = LegacyBarPosition.LAYER1; } /** * Backwards compat */ - public enum OldBarPosition { + public enum LegacyBarPosition { LAYER1, LAYER2, RIGHT, NONE } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java index c3bba3a6ea..081059ceb6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java @@ -71,14 +71,17 @@ public static void init() { // Fetch from old status bar config int[] counts = new int[3]; // counts for RIGHT, LAYER1, LAYER2 StatusBar health = statusBars.get("health"); - UIAndVisualsConfig.OldBarPositions barPositions = SkyblockerConfigManager.get().uiAndVisuals.bars.barPositions; - loadOldBarPosition(health, counts, barPositions.healthBarPosition); + @SuppressWarnings("deprecation") + UIAndVisualsConfig.LegacyBarPositions barPositions = SkyblockerConfigManager.get().uiAndVisuals.bars.barPositions; + initBarPosition(health, counts, barPositions.healthBarPosition); StatusBar intelligence = statusBars.get("intelligence"); - loadOldBarPosition(intelligence, counts, barPositions.manaBarPosition); + initBarPosition(intelligence, counts, barPositions.manaBarPosition); StatusBar defense = statusBars.get("defense"); - loadOldBarPosition(defense, counts, barPositions.defenceBarPosition); + initBarPosition(defense, counts, barPositions.defenceBarPosition); StatusBar experience = statusBars.get("experience"); - loadOldBarPosition(experience, counts, barPositions.experienceBarPosition); + initBarPosition(experience, counts, barPositions.experienceBarPosition); + StatusBar speed = statusBars.get("speed"); + initBarPosition(speed, counts, UIAndVisualsConfig.LegacyBarPosition.LAYER1); CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> { if (object != null) { @@ -111,12 +114,12 @@ public static void init() { } /** - * Loads the bar position from the old config + * Loads the bar position from the old config. Should be used to initialize new bars too. * @param bar the bar to load the position for * @param counts the counts for each bar position (LAYER1, LAYER2, RIGHT) * @param position the position to load */ - private static void loadOldBarPosition(StatusBar bar, int[] counts, UIAndVisualsConfig.OldBarPosition position) { + private static void initBarPosition(StatusBar bar, int[] counts, UIAndVisualsConfig.LegacyBarPosition position) { switch (position) { case RIGHT: bar.anchor = BarPositioner.BarAnchor.HOTBAR_RIGHT; From 1f019f06e0cf1333ca364f57cf26035dd1ecfbec Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:27:15 -0400 Subject: [PATCH 5/5] Update default positions --- .../hysky/skyblocker/config/configs/UIAndVisualsConfig.java | 4 ++-- .../hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index f18edf9a3f..598cbf5498 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -182,10 +182,10 @@ public static class LegacyBarPositions { public LegacyBarPosition manaBarPosition = LegacyBarPosition.LAYER1; @SerialEntry - public LegacyBarPosition defenceBarPosition = LegacyBarPosition.LAYER1; + public LegacyBarPosition defenceBarPosition = LegacyBarPosition.RIGHT; @SerialEntry - public LegacyBarPosition experienceBarPosition = LegacyBarPosition.LAYER1; + public LegacyBarPosition experienceBarPosition = LegacyBarPosition.LAYER2; } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java index 081059ceb6..f49153599d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java @@ -81,7 +81,7 @@ public static void init() { StatusBar experience = statusBars.get("experience"); initBarPosition(experience, counts, barPositions.experienceBarPosition); StatusBar speed = statusBars.get("speed"); - initBarPosition(speed, counts, UIAndVisualsConfig.LegacyBarPosition.LAYER1); + initBarPosition(speed, counts, UIAndVisualsConfig.LegacyBarPosition.RIGHT); CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> { if (object != null) {