diff options
author | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2023-09-02 00:30:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 00:30:56 -0400 |
commit | 225644de8bf2a15c7a0970d84c548189d5a15ec4 (patch) | |
tree | 1fa27c471d9eec98054f2ff3e9b925f37cb09e00 /src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java | |
parent | 3dba852fc81d0a0fd30fc8f1191327ba0e5ba534 (diff) | |
download | Skyblocker-225644de8bf2a15c7a0970d84c548189d5a15ec4.tar.gz Skyblocker-225644de8bf2a15c7a0970d84c548189d5a15ec4.tar.bz2 Skyblocker-225644de8bf2a15c7a0970d84c548189d5a15ec4.zip |
Add Quiver Warning (#270)
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java new file mode 100644 index 00000000..cf793461 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/QuiverWarning.java @@ -0,0 +1,66 @@ +package me.xmrvizzy.skyblocker.skyblock; + +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.jetbrains.annotations.Nullable; + +public class QuiverWarning { + @Nullable + private static Type warning = null; + + public static void init() { + ClientReceiveMessageEvents.ALLOW_GAME.register(QuiverWarning::onChatMessage); + SkyblockerMod.getInstance().scheduler.scheduleCyclic(QuiverWarning::update, 10); + } + + public static boolean onChatMessage(Text text, boolean overlay) { + String message = text.getString(); + if (SkyblockerConfig.get().general.quiverWarning.enableQuiverWarning && message.endsWith("left in your Quiver!")) { + MinecraftClient.getInstance().inGameHud.setDefaultTitleFade(); + if (message.startsWith("You only have 50")) { + onChatMessage(Type.FIFTY_LEFT); + } else if (message.startsWith("You only have 10")) { + onChatMessage(Type.TEN_LEFT); + } else if (message.startsWith("You don't have any more")) { + onChatMessage(Type.EMPTY); + } + } + return true; + } + + private static void onChatMessage(Type warning) { + if (!Utils.isInDungeons()) { + MinecraftClient.getInstance().inGameHud.setTitle(Text.translatable(warning.key).formatted(Formatting.RED)); + } else if (SkyblockerConfig.get().general.quiverWarning.enableQuiverWarningInDungeons) { + MinecraftClient.getInstance().inGameHud.setTitle(Text.translatable(warning.key).formatted(Formatting.RED)); + QuiverWarning.warning = warning; + } + } + + public static void update() { + if (warning != null && SkyblockerConfig.get().general.quiverWarning.enableQuiverWarning && SkyblockerConfig.get().general.quiverWarning.enableQuiverWarningAfterDungeon && !Utils.isInDungeons()) { + InGameHud inGameHud = MinecraftClient.getInstance().inGameHud; + inGameHud.setDefaultTitleFade(); + inGameHud.setTitle(Text.translatable(warning.key).formatted(Formatting.RED)); + warning = null; + } + } + + private enum Type { + NONE(""), + FIFTY_LEFT("50Left"), + TEN_LEFT("10Left"), + EMPTY("empty"); + private final String key; + + Type(String key) { + this.key = "skyblocker.quiverWarning." + key; + } + } +} |