diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java b/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java index 41b8e985..10666874 100644 --- a/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java @@ -3,12 +3,13 @@ package de.hysky.skyblocker.mixin; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.ref.LocalRef; -import dev.cbyrne.betterinject.annotations.Arg; -import dev.cbyrne.betterinject.annotations.Inject; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.item.AttributeShards; import de.hysky.skyblocker.skyblock.item.ItemCooldowns; +import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; +import dev.cbyrne.betterinject.annotations.Arg; +import dev.cbyrne.betterinject.annotations.Inject; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; @@ -32,40 +33,38 @@ public abstract class DrawContextMixin { @Inject(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD")) private void skyblocker$renderAttributeShardDisplay(@Arg TextRenderer textRenderer, @Arg ItemStack stack, @Arg(ordinal = 0) int x, @Arg(ordinal = 1) int y, @Local(argsOnly = true) LocalRef<String> countOverride) { - if (!SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo) return; - - NbtCompound nbt = stack.getNbt(); + if (!SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo) return; - if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { - NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + if (Utils.isOnSkyblock()) { + NbtCompound extraAttributes = ItemUtils.getExtraAttributes(stack); - if (extraAttributes.getString("id").equals("ATTRIBUTE_SHARD")) { - NbtCompound attributesTag = extraAttributes.getCompound("attributes"); - String[] attributes = attributesTag.getKeys().toArray(String[]::new); + if (extraAttributes != null && extraAttributes.getString(ItemUtils.ID).equals("ATTRIBUTE_SHARD")) { + NbtCompound attributesTag = extraAttributes.getCompound("attributes"); + String[] attributes = attributesTag.getKeys().toArray(String[]::new); - if (attributes.length != 0) { - String attributeId = attributes[0]; - int attributeLevel = attributesTag.getInt(attributeId); + if (attributes.length != 0) { + String attributeId = attributes[0]; + int attributeLevel = attributesTag.getInt(attributeId); - //Set item count - countOverride.set(Integer.toString(attributeLevel)); + //Set item count + countOverride.set(Integer.toString(attributeLevel)); - //Draw the attribute name - this.matrices.push(); - this.matrices.translate(0f, 0f, 200f); + //Draw the attribute name + this.matrices.push(); + this.matrices.translate(0f, 0f, 200f); - String attributeInitials = AttributeShards.getShortName(attributeId); + String attributeInitials = AttributeShards.getShortName(attributeId); - this.drawText(textRenderer, attributeInitials, x, y, Formatting.AQUA.getColorValue(), true); + this.drawText(textRenderer, attributeInitials, x, y, Formatting.AQUA.getColorValue(), true); - this.matrices.pop(); - } - } - } + this.matrices.pop(); + } + } + } } @ModifyExpressionValue(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ItemCooldownManager;getCooldownProgress(Lnet/minecraft/item/Item;F)F")) + at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ItemCooldownManager;getCooldownProgress(Lnet/minecraft/item/Item;F)F")) private float skyblocker$modifyItemCooldown(float cooldownProgress, @Local ItemStack stack) { return Utils.isOnSkyblock() && ItemCooldowns.isOnCooldown(stack) ? ItemCooldowns.getItemCooldownEntry(stack).getRemainingCooldownPercent() : cooldownProgress; } |