aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java
blob: c44c8bc7f434d3e9a71805a8bcd68212c4910165 (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
package com.thatgravyboat.skyblockhud.handlers;

import net.minecraft.client.gui.Gui;
import net.minecraft.item.ItemStack;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

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;
    }
}