Skip to content

Commit

Permalink
Quiver HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Nov 9, 2024
1 parent e324106 commit 24704c8
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void onInitialize() {
HUDS.add(new FpsHUD());

HUDS.add(new TickerHUD());
HUDS.add(new QuiverHUD());

HudRenderCallback.EVENT.register((context, tickCounter) -> {
HUDS.forEach(hud -> hud.render(context, false));
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/wtf/cheeze/sbt/command/SBTCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public static void registerEvents() {
return 1;
}))


.then(literal("dumpComponents")
.then(literal("hand")
.executes(context -> {
Expand All @@ -342,7 +343,18 @@ public static void registerEvents() {
});
return 1;
}))
.then(literal("slot")
.then(literal("inventory")
.then(argument("number" , IntegerArgumentType.integer())
.executes(context -> {
var components = SkyblockTweaks.mc.player.getInventory().getStack(IntegerArgumentType.getInteger(context, "number")).getComponents();
components.forEach((component) -> {
context.getSource().sendFeedback(Text.of(PREFIX + " §3" + component.toString()));
});
return 1;
})

))
.then(literal("container")
.then(argument("number" , IntegerArgumentType.integer())
.executes(context -> {
new Thread(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config)
.group(RealTimeHUD.Config.getGroup(defaults, config))
.group(FpsHUD.Config.getGroup(defaults, config))
.group(TickerHUD.Config.getGroup(defaults, config))
.group(QuiverHUD.Config.getGroup(defaults, config))
.build();
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/wtf/cheeze/sbt/config/categories/Huds.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class Huds {
@SerialEntry
public TickerHUD.Config ticker = new TickerHUD.Config();

@SerialEntry
public QuiverHUD.Config quiver = new QuiverHUD.Config();

public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config) {
return ConfigCategory.createBuilder()
.name(Text.translatable("sbt.config.huds"))
Expand All @@ -99,6 +102,7 @@ public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config)
.group(RealTimeHUD.Config.getGroup(defaults, config))
.group(FpsHUD.Config.getGroup(defaults, config))
.group(TickerHUD.Config.getGroup(defaults, config))
.group(QuiverHUD.Config.getGroup(defaults, config))
.build();
}
}
3 changes: 2 additions & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import wtf.cheeze.sbt.hud.bases.BarHUD;
import wtf.cheeze.sbt.hud.utils.HudInformation;
import wtf.cheeze.sbt.utils.render.Colors;
import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils;

import java.awt.Color;

Expand Down Expand Up @@ -59,7 +60,7 @@ public String getName() {
@Override
public boolean shouldRender(boolean fromHudScreen) {
if (!super.shouldRender(fromHudScreen)) return false;
if ((SkyblockTweaks.DATA.inSB && SBTConfig.huds().drillFuelBar.enabled) && SkyblockTweaks.DATA.isThePlayerHoldingADrill() || fromHudScreen) return true;
if ((SkyblockTweaks.DATA.inSB && SBTConfig.huds().drillFuelBar.enabled) && SkyblockUtils.isThePlayerHoldingADrill() || fromHudScreen) return true;
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import wtf.cheeze.sbt.hud.bases.TextHUD;
import wtf.cheeze.sbt.hud.components.SingleHudLine;
import wtf.cheeze.sbt.utils.render.Colors;
import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils;

import java.awt.Color;

Expand Down Expand Up @@ -64,7 +65,7 @@ public DrillFuelHUD() {
@Override
public boolean shouldRender(boolean fromHudScreen) {
if (!super.shouldRender(fromHudScreen)) return false;
if ((SkyblockTweaks.DATA.inSB && SBTConfig.huds().drillFuel.enabled) && SkyblockTweaks.DATA.isThePlayerHoldingADrill() || fromHudScreen) return true;
if ((SkyblockTweaks.DATA.inSB && SBTConfig.huds().drillFuel.enabled) && SkyblockUtils.isThePlayerHoldingADrill() || fromHudScreen) return true;
return false;
}

Expand Down
155 changes: 155 additions & 0 deletions src/main/java/wtf/cheeze/sbt/features/huds/QuiverHUD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package wtf.cheeze.sbt.features.huds;

import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionGroup;
import dev.isxander.yacl3.api.controller.ColorControllerBuilder;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.config.ConfigImpl;
import wtf.cheeze.sbt.config.SBTConfig;
import wtf.cheeze.sbt.hud.bases.TextHUD;
import wtf.cheeze.sbt.hud.components.SingleHudLine;
import wtf.cheeze.sbt.hud.utils.AnchorPoint;
import wtf.cheeze.sbt.hud.utils.DrawMode;
import wtf.cheeze.sbt.hud.utils.HudInformation;
import wtf.cheeze.sbt.utils.TextUtils;
import wtf.cheeze.sbt.utils.render.Colors;
import wtf.cheeze.sbt.utils.skyblock.IconDict;
import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils;

import java.awt.*;

public class QuiverHUD extends TextHUD {
@Override
public String getName() {
return "Quiver HUD";
}


public QuiverHUD() {
INFO = new HudInformation(
() -> SBTConfig.huds().quiver.x,
() -> SBTConfig.huds().quiver.y,
() -> SBTConfig.huds().quiver.scale,
() -> SBTConfig.huds().quiver.anchor,
x -> SBTConfig.huds().quiver.x = (float) x,
y -> SBTConfig.huds().quiver.y = (float) y,
scale -> SBTConfig.huds().quiver.scale = (float) scale,
anchor -> SBTConfig.huds().quiver.anchor = anchor
);
line = new SingleHudLine(
() -> Colors.WHITE,
() -> SBTConfig.huds().quiver.outlineColor,
() -> SBTConfig.huds().quiver.mode,
() -> {
var quiver = SkyblockUtils.getQuiverData();
return TextUtils.join(
quiver.arrowName,
TextUtils.SPACE,
TextUtils.withColor("x" + quiver.arrowCount, Colors.GRAY)
);
},
() -> IconDict.ARROW,
() -> SBTConfig.huds().quiver.icon
);

}

@Override
public boolean shouldRender(boolean fromHudScreen) {
if (!super.shouldRender(fromHudScreen)) return false;
if ((SkyblockTweaks.DATA.inSB && SBTConfig.huds().quiver.enabled && SkyblockUtils.quiverActive()) || fromHudScreen) return true;
return false;
}


public static class Config {
@SerialEntry
public boolean enabled = false;

@SerialEntry
public DrawMode mode = DrawMode.SHADOW;

@SerialEntry // Not handled by YACL Gui
public float x = 0;

@SerialEntry // Not handled by YACL Gui
public float y = 0.9f;

@SerialEntry
public float scale = 1.0f;

@SerialEntry
public int outlineColor = Colors.BLACK;

@SerialEntry
public AnchorPoint anchor = AnchorPoint.LEFT;

@SerialEntry
public boolean icon = true;

public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
var enabled = Option.<Boolean>createBuilder()
.name(key("quiver.enabled"))
.description(keyD("quiver.enabled"))
.controller(SBTConfig::generateBooleanController)
.binding(
defaults.huds.quiver.enabled,
() -> config.huds.quiver.enabled,
value -> config.huds.quiver.enabled = (Boolean) value
)
.build();
var icon = Option.<Boolean>createBuilder()
.name(key("quiver.icon"))
.description(keyD("quiver.icon"))
.controller(SBTConfig::generateBooleanController)
.binding(
defaults.huds.quiver.icon,
() -> config.huds.quiver.icon,
value -> config.huds.quiver.icon = (Boolean) value
)
.build();



var outline = Option.<Color>createBuilder()
.name(key("quiver.outlineColor"))
.description(keyD("quiver.outlineColor"))
.controller(ColorControllerBuilder::create)
.available(config.huds.quiver.mode == DrawMode.OUTLINE)
.binding(
new Color(defaults.huds.quiver.outlineColor),
() -> new Color(config.huds.quiver.outlineColor),
value -> config.huds.quiver.outlineColor = value.getRGB()

)
.build();

var mode = Option.<DrawMode>createBuilder()
.name(key("quiver.mode"))
.description(keyD("quiver.mode"))
.controller(SBTConfig::generateDrawModeController)
.binding(
defaults.huds.quiver.mode,
() -> config.huds.quiver.mode,
value -> {
config.huds.quiver.mode = value;
if (value == DrawMode.OUTLINE) outline.setAvailable(true);
else outline.setAvailable(false);
}
)
.build();

return OptionGroup.createBuilder()
.name(key("quiver"))
.description(keyD("quiver"))
.option(enabled)
.option(icon)
.option(outline)
.option(mode)
.collapsed(true)
.build();
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/hud/HudIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class HudIcon {
@Nullable private Identifier iconTexture;
@Nullable private ItemStack iconStack;
private Mode mode;
private final Mode mode;

public HudIcon(Identifier iconTexture) {
this.iconTexture = iconTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NotificationHandler {

public static void registerEvents() {
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
if (NOTIFICATION_QUEUE.size() == 0) return;
if (NOTIFICATION_QUEUE.isEmpty()) return;
new Thread(() -> {
try {
Thread.sleep(2500);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/wtf/cheeze/sbt/utils/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TextUtils {
public static String removeColorCodes(String text) {
return text.replaceAll("§[a-f0-9k-o]", "");
}
public static final Text SPACE = Text.literal(" ");

public static Text getTextThatLinksToURL(String text, String hovered, String url) {
return Text.literal(text).styled(style -> {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void checkForUpdates() {
if (remote.latestAlpha == null) {
break;
}

internalRun(remote.latestAlpha.get(SkyblockTweaks.mc.getGameVersion()));
}
case NotificationStream.BETA -> {
Expand All @@ -64,6 +65,7 @@ public static void checkForUpdates() {
}

private static void internalRun(Version.RemoteVersion remoteVersion) {
if (remoteVersion == null) return;
var version = new Version(remoteVersion.versionString);
var comparison = Version.compareVersions(version, SkyblockTweaks.VERSION);
if (comparison == Version.VersionComparison.GREATER) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/render/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class Colors {

public static final int WHITE = 0xFFFFFFFF;
public static final int BLACK = 0xFF000000;
public static final int GRAY = 0xFFAAAAAA;
public static final int DARK_GRAY = 0xFF555555;

public static final int BLUE = 0xFF5555FF;
public static final int RED = 0xFFFF5555;
Expand All @@ -18,4 +20,6 @@ public class Colors {





}
2 changes: 2 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/skyblock/IconDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class IconDict {
Map.entry(Skills.SOCIAL, new HudIcon(ofItem("emerald"))
));

public static final HudIcon ARROW = new HudIcon(ofItem("arrow"));

private static Identifier ofItem(String name) {
return Identifier.ofVanilla("textures/item/" + name + ".png");
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/skyblock/QuiverData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package wtf.cheeze.sbt.utils.skyblock;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import wtf.cheeze.sbt.SkyblockTweaks;
import wtf.cheeze.sbt.features.huds.QuiverHUD;

import java.util.regex.Pattern;

public class QuiverData {
private static final Pattern QUIVER_PATTERN = Pattern.compile("Active Arrow: (.+) \\((\\d+)\\)");

public final Text arrowName;
public final int arrowCount;

QuiverData (ItemStack stack) {
var lines = stack.getOrDefault(DataComponentTypes.LORE, LoreComponent.DEFAULT).lines();
var line = lines.get(4);
var matcher = QUIVER_PATTERN.matcher(line.getString());
if (matcher.matches()) {
arrowCount = Integer.parseInt(matcher.group(2));
var type = line.getSiblings().get(1);
arrowName = Text.literal(type.getString().trim()).setStyle(type.getStyle());
} else {
arrowCount = 0;
arrowName = Text.of("Placeholder Arrow");
}
}
}
4 changes: 0 additions & 4 deletions src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockData.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public float damageReduction() {
return (defense / (defense + 100f)) * 100;
}

public boolean isThePlayerHoldingADrill() {
return MinecraftClient.getInstance().player.getMainHandStack().getName().getString().contains("Drill");
}

/**
* Provides the profile ID with an appended "_ALPHA" if the player is in the alpha network
* We do this so that what players do on the Alpha network does not affect persistent data for their main profile
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/skyblock/SkyblockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package wtf.cheeze.sbt.utils.skyblock;

import net.minecraft.client.MinecraftClient;
import wtf.cheeze.sbt.SkyblockTweaks;

public class SkyblockUtils {

public static SkyblockConstants.Rarity castStringToRarity(String input) {
Expand Down Expand Up @@ -80,4 +83,21 @@ public static SkyblockConstants.Skills strictCastStringToSkill(String skill) {
default -> SkyblockConstants.Skills.UNKNOWN;
};
}

public static boolean isThePlayerHoldingADrill() {
return MinecraftClient.getInstance().player.getMainHandStack().getName().getString().contains("Drill");
}

public static boolean quiverActive() {
return SkyblockTweaks.mc.player.getInventory().getStack(8).getName().getString().startsWith("Quiver");
}

/**
* Please qualify calls to this with a call to quiverActive
*/
public static QuiverData getQuiverData() {
return new QuiverData(SkyblockTweaks.mc.player.getInventory().getStack(8));
}


}
Loading

0 comments on commit 24704c8

Please sign in to comment.