blob: 2feef38179eae0408c4827f5a82aea1ac144168e (
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
|
package com.thatgravyboat.skyblockhud.handlers;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.client.gui.Gui;
import net.minecraft.item.ItemStack;
public class HeldItemHandler extends Gui {
private static final Pattern MANA_COST_REGEX = Pattern.compile("Mana Cost: \u00A73([0-9]+)");
public static boolean hasManaCost(ItemStack stack) {
if (stack == null) return false;
if (!stack.hasTagCompound()) return false;
if (!stack.getTagCompound().hasKey("display")) return false;
if (!stack.getTagCompound().getCompoundTag("display").hasKey("Lore")) return false;
String lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8).toString();
return MANA_COST_REGEX.matcher(lore).find();
}
public static int getManaCost(ItemStack stack) {
String lore = stack.getTagCompound().getCompoundTag("display").getTagList("Lore", 8).toString();
Matcher matcher = MANA_COST_REGEX.matcher(lore);
if (matcher.find()) {
try {
return Integer.parseInt(matcher.group(1));
} catch (Exception ignored) {}
}
return 0;
}
}
|