aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java
blob: 1f372ad401d4d55fb9b86cca3e9cd1df01d250d1 (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
package com.thatgravyboat.skyblockhud.mixins;

import com.thatgravyboat.skyblockhud.SkyblockHud;
import com.thatgravyboat.skyblockhud.api.item.IAbility;
import com.thatgravyboat.skyblockhud.handlers.CooldownHandler;
import java.util.regex.Matcher;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ItemStack.class)
public class MixinItemStack implements IAbility {

    private String ability;
    private int abilityTime;

    @Inject(method = "setTagCompound", at = @At("HEAD"))
    public void onNbt(NBTTagCompound nbt, CallbackInfo ci) {
        if (SkyblockHud.config != null && !SkyblockHud.config.misc.hideItemCooldowns) {
            Matcher abilityMatcher = CooldownHandler.getAbility(nbt);
            if (abilityMatcher != null) {
                ability = abilityMatcher.group(1);
                try {
                    abilityTime = Integer.parseInt(abilityMatcher.group(2).trim());
                } catch (Exception ignored) {}
            }
        }
    }

    @Override
    public String getAbility() {
        return ability;
    }

    @Override
    public int getAbilityTime() {
        return abilityTime;
    }
}