diff options
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java index cfe979d0..8cde4973 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java @@ -1,12 +1,13 @@ package me.xmrvizzy.skyblocker.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.mojang.blaze3d.systems.RenderSystem; - import dev.cbyrne.betterinject.annotations.Arg; import dev.cbyrne.betterinject.annotations.Inject; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.skyblock.cooldown.ItemCooldowns; import me.xmrvizzy.skyblocker.skyblock.item.AttributeShards; import me.xmrvizzy.skyblocker.utils.ItemUtils; import me.xmrvizzy.skyblocker.utils.Utils; @@ -18,7 +19,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Formatting; import net.minecraft.util.math.ColorHelper; - import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -73,7 +73,8 @@ public abstract class DrawContextMixin { max = Integer.parseInt(split[1]) * 1000; } break; - } else if (line.contains("uses.")) { + } + else if (line.contains("uses.")) { if (clearFormatting != null) { int startIndex = clearFormatting.lastIndexOf("after") + 6; int endIndex = clearFormatting.indexOf("uses", startIndex); @@ -99,35 +100,45 @@ 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 (!SkyblockerConfig.get().general.itemInfoDisplay.attributeShardInfo) return; + if (!SkyblockerConfig.get().general.itemInfoDisplay.attributeShardInfo) return; + + NbtCompound nbt = stack.getNbt(); + + if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); - NbtCompound nbt = stack.getNbt(); + if (extraAttributes.getString("id").equals("ATTRIBUTE_SHARD")) { + NbtCompound attributesTag = extraAttributes.getCompound("attributes"); + String[] attributes = attributesTag.getKeys().toArray(String[]::new); - if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { - NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + if (attributes.length != 0) { + String attributeId = attributes[0]; + int attributeLevel = attributesTag.getInt(attributeId); - if (extraAttributes.getString("id").equals("ATTRIBUTE_SHARD")) { - NbtCompound attributesTag = extraAttributes.getCompound("attributes"); - String[] attributes = attributesTag.getKeys().toArray(String[]::new); + //Set item count + countOverride.set(Integer.toString(attributeLevel)); - if (attributes.length != 0) { - String attributeId = attributes[0]; - int attributeLevel = attributesTag.getInt(attributeId); + //Draw the attribute name + this.matrices.push(); + this.matrices.translate(0f, 0f, 200f); - //Set item count - countOverride.set(Integer.toString(attributeLevel)); + String attributeInitials = AttributeShards.getShortName(attributeId); - //Draw the attribute name - this.matrices.push(); - this.matrices.translate(0f, 0f, 200f); + this.drawText(textRenderer, attributeInitials, x, y, Formatting.AQUA.getColorValue(), true); - String attributeInitials = AttributeShards.getShortName(attributeId); + this.matrices.pop(); + } + } + } + } - this.drawText(textRenderer, attributeInitials, x, y, Formatting.AQUA.getColorValue(), true); + @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")) + private float skyblocker$modifyItemCooldown(float cooldownProgress, @Local ItemStack stack) { + if (Utils.isOnSkyblock() && ItemCooldowns.isItemOnCooldown(stack)) { + return ItemCooldowns.getItemCooldownEntry(stack).getRemainingCooldownPercent(); + } - this.matrices.pop(); - } - } - } + return cooldownProgress; } -}
\ No newline at end of file +} |