From 99773d6a593c444151503de315f127bea6f74d49 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 7 Jul 2022 00:31:50 +0200 Subject: init lorenz mod --- .../skyblockhud/handlers/HeldItemHandler.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java (limited to 'src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java') 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; + } +} -- cgit