blob: a6c45d210ea664645bb952df5c5347bfaf2a22c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package de.hysky.skyblocker.skyblock;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
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);
Scheduler.INSTANCE.scheduleCyclic(QuiverWarning::update, 10);
}
public static boolean onChatMessage(Text text, boolean overlay) {
String message = text.getString();
if (SkyblockerConfigManager.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 (SkyblockerConfigManager.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 && SkyblockerConfigManager.get().general.quiverWarning.enableQuiverWarning && SkyblockerConfigManager.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;
}
}
}
|