diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2023-08-31 22:53:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 22:53:27 -0400 |
commit | 5d34c99a38af9011559260bb1e211468c41edbc6 (patch) | |
tree | 11c33aeebb1c42d6df41e3151321818348041da3 | |
parent | 1370097922f19815e14bdfd8c9e606cde2bc8f39 (diff) | |
download | Skyblocker-5d34c99a38af9011559260bb1e211468c41edbc6.tar.gz Skyblocker-5d34c99a38af9011559260bb1e211468c41edbc6.tar.bz2 Skyblocker-5d34c99a38af9011559260bb1e211468c41edbc6.zip |
Attribute Shard Info Display (#263)
4 files changed, 114 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 6ddbdf65..3373b71d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -181,6 +181,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Category("itemTooltip") @ConfigEntry.Gui.CollapsibleObject() public ItemTooltip itemTooltip = new ItemTooltip(); + + @ConfigEntry.Category("itemInfoDisplay") + @ConfigEntry.Gui.CollapsibleObject + public ItemInfoDisplay itemInfoDisplay = new ItemInfoDisplay(); @ConfigEntry.Category("hitbox") @ConfigEntry.Gui.CollapsibleObject() @@ -387,6 +391,11 @@ public class SkyblockerConfig implements ConfigData { public boolean enableBazaarPrice = true; public boolean enableMuseumDate = true; } + + public static class ItemInfoDisplay { + @ConfigEntry.Gui.Tooltip + public boolean attributeShardInfo = true; + } public static class Locations { @ConfigEntry.Category("barn") diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java index 6c059741..0a1084cf 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/DrawContextMixin.java @@ -1,12 +1,16 @@ package me.xmrvizzy.skyblocker.mixin; +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.item.AttributeShards; import me.xmrvizzy.skyblocker.utils.ItemUtils; import me.xmrvizzy.skyblocker.utils.Utils; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; @@ -14,6 +18,8 @@ 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; import org.spongepowered.asm.mixin.Shadow; @@ -30,6 +36,9 @@ public abstract class DrawContextMixin { @Shadow public abstract void fill(RenderLayer layer, int x1, int x2, int y1, int y2, int color); + + @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")) public void skyblocker$renderItemBar(@Arg ItemStack stack, @Arg(ordinal = 0) int x, @Arg(ordinal = 1) int y) { @@ -87,4 +96,38 @@ public abstract class DrawContextMixin { matrices.pop(); RenderSystem.enableDepthTest(); } + + @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; + + NbtCompound nbt = stack.getNbt(); + + if (Utils.isOnSkyblock() && nbt != null && nbt.contains("ExtraAttributes")) { + NbtCompound extraAttributes = nbt.getCompound("ExtraAttributes"); + + if (extraAttributes.getString("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); + + //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(); + } + } + } + } }
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/AttributeShards.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/AttributeShards.java new file mode 100644 index 00000000..0f106cdf --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/AttributeShards.java @@ -0,0 +1,59 @@ +package me.xmrvizzy.skyblocker.skyblock.item; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + +public class AttributeShards { + private static final Object2ObjectOpenHashMap<String, String> 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/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 2c2a4a9c..ec1b73b1 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -61,6 +61,9 @@ "text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date", + "text.autoconfig.skyblocker.option.general.itemInfoDisplay": "Item Info Display", + "text.autoconfig.skyblocker.option.general.itemInfoDisplay.attributeShardInfo": "Attribute Shard Info", + "text.autoconfig.skyblocker.option.general.itemInfoDisplay.attributeShardInfo.@Tooltip": "Displays the attribute's level as the stack count and the initials of the attribute's name.", "text.autoconfig.skyblocker.option.general.hitbox": "Hitboxes", "text.autoconfig.skyblocker.option.general.hitbox.oldFarmlandHitbox": "Enable 1.8 farmland hitbox", "text.autoconfig.skyblocker.option.general.hitbox.oldLeverHitbox": "Enable 1.8 lever hitbox", |