Skip to content

Commit

Permalink
Merge pull request #945 from Westsi/speed-status-bar
Browse files Browse the repository at this point in the history
Added Speed Status Bar #855
  • Loading branch information
kevinthegreat1 authored Sep 6, 2024
2 parents dd5f0d3 + 1f019f0 commit 04afe1a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +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.
* <p>
* 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.RIGHT;

@SerialEntry
public OldBarPosition experienceBarPosition = OldBarPosition.LAYER1;

public LegacyBarPosition experienceBarPosition = LegacyBarPosition.LAYER2;
}

/**
* Backwards compat
*/
public enum OldBarPosition {
public enum LegacyBarPosition {
LAYER1, LAYER2, RIGHT, NONE
}

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/StatusBarTracker.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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(",", ""));
}
Expand All @@ -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<ItemStack> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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 {
Expand Down Expand Up @@ -66,18 +66,24 @@ 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
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.RIGHT);

CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> {
if (object != null) {
Expand Down Expand Up @@ -110,12 +116,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;
Expand Down Expand Up @@ -306,6 +312,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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,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",
Expand Down Expand Up @@ -815,6 +815,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",
Expand Down Expand Up @@ -1024,7 +1025,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.",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04afe1a

Please sign in to comment.