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/mixins/MixinItemStack.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java (limited to 'src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java') diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java new file mode 100644 index 000000000..1f372ad40 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinItemStack.java @@ -0,0 +1,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; + } +} -- cgit