diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
commit | 99773d6a593c444151503de315f127bea6f74d49 (patch) | |
tree | 9ee1ae505e5f82aba62f10c882af85a3acd6e483 /src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java | |
download | skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.gz skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.bz2 skyhanni-99773d6a593c444151503de315f127bea6f74d49.zip |
init lorenz mod
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java new file mode 100644 index 000000000..2feef3817 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java @@ -0,0 +1,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; + } +} |