From 6cdcfe90e0e01abb26c9681190ce5c2fb08b3637 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:56:49 +0300 Subject: Refactor AttributeShards to AttributeShardAdder --- .../hysky/skyblocker/mixins/DrawContextMixin.java | 52 ------------ .../skyblocker/skyblock/item/AttributeShards.java | 59 ------------- .../skyblock/item/slottext/SlotTextManager.java | 3 +- .../item/slottext/adders/AttributeShardAdder.java | 97 ++++++++++++++++++++++ 4 files changed, 99 insertions(+), 112 deletions(-) delete mode 100644 src/main/java/de/hysky/skyblocker/skyblock/item/AttributeShards.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/mixins/DrawContextMixin.java b/src/main/java/de/hysky/skyblocker/mixins/DrawContextMixin.java index 7964b114..9f09c37a 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/DrawContextMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/DrawContextMixin.java @@ -2,67 +2,15 @@ package de.hysky.skyblocker.mixins; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; -import com.llamalad7.mixinextras.sugar.ref.LocalRef; -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 net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.Formatting; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(DrawContext.class) public abstract class DrawContextMixin { - @Shadow - @Final - private MatrixStack matrices; - - @Shadow - public abstract int drawText(TextRenderer textRenderer, @Nullable String text, int x, int y, int color, boolean shadow); - - @Inject(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD")) - private void skyblocker$renderAttributeShardDisplay(CallbackInfo ci, @Local(argsOnly = true) TextRenderer textRenderer, @Local(argsOnly = true) ItemStack stack, @Local(argsOnly = true, ordinal = 0) int x, @Local(argsOnly = true, ordinal = 1) int y, @Local(argsOnly = true) LocalRef countOverride) { - if (!SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo) return; - - if (Utils.isOnSkyblock()) { - NbtCompound customData = ItemUtils.getCustomData(stack); - - if (ItemUtils.getItemId(stack).equals("ATTRIBUTE_SHARD")) { - NbtCompound attributesTag = customData.getCompound("attributes"); - String[] attributes = attributesTag.getKeys().toArray(String[]::new); - - if (attributes.length != 0) { - String attributeId = attributes[0]; - int attributeLevel = attributesTag.getInt(attributeId); - - //Set item count - countOverride.set(Integer.toString(attributeLevel)); - - //Draw the attribute name - this.matrices.push(); - this.matrices.translate(0f, 0f, 200f); - - String attributeInitials = AttributeShards.getShortName(attributeId); - - this.drawText(textRenderer, attributeInitials, x, y, Formatting.AQUA.getColorValue(), true); - - 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")) private float skyblocker$modifyItemCooldown(float cooldownProgress, @Local(argsOnly = true) ItemStack stack) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/AttributeShards.java b/src/main/java/de/hysky/skyblocker/skyblock/item/AttributeShards.java deleted file mode 100644 index ed650e26..00000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/AttributeShards.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.hysky.skyblocker.skyblock.item; - -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; - -public class AttributeShards { - private static final Object2ObjectOpenHashMap ID_2_SHORT_NAME = new Object2ObjectOpenHashMap<>(); - - static { - //Weapons - ID_2_SHORT_NAME.put("arachno", "A"); - ID_2_SHORT_NAME.put("attack_speed", "AS"); - ID_2_SHORT_NAME.put("blazing", "BL"); - ID_2_SHORT_NAME.put("combo", "C"); - ID_2_SHORT_NAME.put("elite", "E"); - ID_2_SHORT_NAME.put("ender", "EN"); - ID_2_SHORT_NAME.put("ignition", "I"); - ID_2_SHORT_NAME.put("life_recovery", "LR"); - ID_2_SHORT_NAME.put("mana_steal", "MS"); - ID_2_SHORT_NAME.put("midas_touch", "MT"); - ID_2_SHORT_NAME.put("undead", "U"); - - //Swords & Bows - ID_2_SHORT_NAME.put("warrior", "W"); - ID_2_SHORT_NAME.put("deadeye", "DE"); - - //Armor or Equipment - ID_2_SHORT_NAME.put("arachno_resistance", "AR"); - ID_2_SHORT_NAME.put("blazing_resistance", "BR"); - ID_2_SHORT_NAME.put("breeze", "B"); - ID_2_SHORT_NAME.put("dominance", "D"); - ID_2_SHORT_NAME.put("ender_resistance", "ER"); - ID_2_SHORT_NAME.put("experience", "XP"); - ID_2_SHORT_NAME.put("fortitude", "F"); - ID_2_SHORT_NAME.put("life_regeneration", "HR"); //Health regeneration - ID_2_SHORT_NAME.put("lifeline", "L"); - ID_2_SHORT_NAME.put("magic_find", "MF"); - ID_2_SHORT_NAME.put("mana_pool", "MP"); - ID_2_SHORT_NAME.put("mana_regeneration", "MR"); - ID_2_SHORT_NAME.put("mending", "V"); //Vitality - ID_2_SHORT_NAME.put("speed", "S"); - ID_2_SHORT_NAME.put("undead_resistance", "UR"); - ID_2_SHORT_NAME.put("veteran", "V"); - - //Fishing Gear - ID_2_SHORT_NAME.put("blazing_fortune", "BF"); - ID_2_SHORT_NAME.put("fishing_experience", "FE"); - ID_2_SHORT_NAME.put("infection", "IF"); - ID_2_SHORT_NAME.put("double_hook", "DH"); - ID_2_SHORT_NAME.put("fisherman", "FM"); - ID_2_SHORT_NAME.put("fishing_speed", "FS"); - ID_2_SHORT_NAME.put("hunter", "H"); - ID_2_SHORT_NAME.put("trophy_hunter", "TH"); - - } - - public static String getShortName(String id) { - return ID_2_SHORT_NAME.getOrDefault(id, ""); - } -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java index 1181baeb..55e5960d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java @@ -21,7 +21,8 @@ public class SlotTextManager { new CatacombsLevelAdder.Dungeoneering(), new CatacombsLevelAdder.DungeonClasses(), new CatacombsLevelAdder.ReadyUp(), - new RancherBootsSpeedAdder() + new RancherBootsSpeedAdder(), + new AttributeShardAdder() }; private static final ArrayList currentScreenAdders = new ArrayList<>(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java new file mode 100644 index 00000000..2c75b9d9 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java @@ -0,0 +1,97 @@ +package de.hysky.skyblocker.skyblock.item.slottext.adders; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.item.slottext.PositionedText; +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.utils.ItemUtils; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class AttributeShardAdder extends SlotTextAdder { + private static final Object2ObjectMap ID_2_SHORT_NAME = new Object2ObjectOpenHashMap<>(); + + static { + //Weapons + ID_2_SHORT_NAME.put("arachno", "A"); + ID_2_SHORT_NAME.put("attack_speed", "AS"); + ID_2_SHORT_NAME.put("blazing", "BL"); + ID_2_SHORT_NAME.put("combo", "C"); + ID_2_SHORT_NAME.put("elite", "E"); + ID_2_SHORT_NAME.put("ender", "EN"); + ID_2_SHORT_NAME.put("ignition", "I"); + ID_2_SHORT_NAME.put("life_recovery", "LR"); + ID_2_SHORT_NAME.put("mana_steal", "MS"); + ID_2_SHORT_NAME.put("midas_touch", "MT"); + ID_2_SHORT_NAME.put("undead", "U"); + + //Swords & Bows + ID_2_SHORT_NAME.put("warrior", "W"); + ID_2_SHORT_NAME.put("deadeye", "DE"); + + //Armor or Equipment + ID_2_SHORT_NAME.put("arachno_resistance", "AR"); + ID_2_SHORT_NAME.put("blazing_resistance", "BR"); + ID_2_SHORT_NAME.put("breeze", "B"); + ID_2_SHORT_NAME.put("dominance", "D"); + ID_2_SHORT_NAME.put("ender_resistance", "ER"); + ID_2_SHORT_NAME.put("experience", "XP"); + ID_2_SHORT_NAME.put("fortitude", "F"); + ID_2_SHORT_NAME.put("life_regeneration", "HR"); //Health regeneration + ID_2_SHORT_NAME.put("lifeline", "L"); + ID_2_SHORT_NAME.put("magic_find", "MF"); + ID_2_SHORT_NAME.put("mana_pool", "MP"); + ID_2_SHORT_NAME.put("mana_regeneration", "MR"); + ID_2_SHORT_NAME.put("mending", "V"); //Vitality + ID_2_SHORT_NAME.put("speed", "S"); + ID_2_SHORT_NAME.put("undead_resistance", "UR"); + ID_2_SHORT_NAME.put("veteran", "V"); + + //Fishing Gear + ID_2_SHORT_NAME.put("blazing_fortune", "BF"); + ID_2_SHORT_NAME.put("fishing_experience", "FE"); + ID_2_SHORT_NAME.put("infection", "IF"); + ID_2_SHORT_NAME.put("double_hook", "DH"); + ID_2_SHORT_NAME.put("fisherman", "FM"); + ID_2_SHORT_NAME.put("fishing_speed", "FS"); + ID_2_SHORT_NAME.put("hunter", "H"); + ID_2_SHORT_NAME.put("trophy_hunter", "TH"); + } + + public AttributeShardAdder() { + super(); + } + + @Override + public @NotNull List getText(Slot slot) { + final ItemStack stack = slot.getStack(); + NbtCompound customData = ItemUtils.getCustomData(stack); + + if (!ItemUtils.getItemId(stack).equals("ATTRIBUTE_SHARD")) return List.of(); + + NbtCompound attributesTag = customData.getCompound("attributes"); + String[] attributes = attributesTag.getKeys().toArray(String[]::new); + + if (attributes.length != 1) return List.of(); + String attributeId = attributes[0]; + int attributeLevel = attributesTag.getInt(attributeId); + String attributeInitials = ID_2_SHORT_NAME.getOrDefault(attributeId, ""); + + return List.of( + PositionedText.BOTTOM_RIGHT(Text.literal(String.valueOf(attributeLevel))), + PositionedText.TOP_LEFT(Text.literal(attributeInitials).formatted(Formatting.AQUA)) + ); + } + + @Override + public boolean isEnabled() { + return SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo; + } +} -- cgit