From b3a00f75cc13425a0732b7acf4dbb7141dfda709 Mon Sep 17 00:00:00 2001 From: Julian Chang Date: Wed, 2 Dec 2026 03:32:20 -0500 Subject: [PATCH 1/2] Add potion effect letters on potion icons --- .../mixin/RenderItemMixin_PotionLetters.java | 23 +++++ .../glintcolorizer/config/GlintConfig.kt | 37 ++++++++ .../handler/PotionLetterHandler.kt | 86 +++++++++++++++++++ src/main/resources/mixins.glintcolorizer.json | 1 + 4 files changed, 147 insertions(+) create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_PotionLetters.java create mode 100644 src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_PotionLetters.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_PotionLetters.java new file mode 100644 index 0000000..a74b260 --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/RenderItemMixin_PotionLetters.java @@ -0,0 +1,23 @@ +package org.polyfrost.glintcolorizer.mixin; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; +import org.polyfrost.glintcolorizer.handler.PotionLetterHandler; +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(RenderItem.class) +public class RenderItemMixin_PotionLetters { + + @Inject( + method = "renderItemOverlayIntoGUI", + at = @At("TAIL") + ) + private void glintColorizer$drawPotionLetter(FontRenderer font, ItemStack stack, int x, int y, String text, CallbackInfo ci) { + PotionLetterHandler.INSTANCE.render(font, stack, x, y); + } + +} diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt index a8f8d14..e9e444b 100644 --- a/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/config/GlintConfig.kt @@ -177,6 +177,43 @@ object GlintConfig : Config( ) var potionBasedColor = false + @Switch( + title = "Potion Effect Letters", + description = "Draws a short code for the potion's effect on potion icons, e.g. S = Speed, ST = Strength, H = Instant Health.", + category = "Potion Letters" + ) + var potionLetters = false + + @Slider( + title = "Letter Scale", + min = 0.5f, + max = 1f, + step = 0.05f, + category = "Potion Letters" + ) + var potionLetterScale = 0.75f + + @Dropdown( + title = "Letter Corner", + options = ["Top Left", "Top Right", "Bottom Left", "Bottom Right"], + category = "Potion Letters" + ) + var potionLetterCorner = 0 + + @Checkbox( + title = "Show Potion Level", + description = "Adds the level for level II and higher, e.g. S2 for Speed II.", + category = "Potion Letters" + ) + var potionLetterLevel = false + + @Checkbox( + title = "Potion Colored Letters", + description = "Uses the potion's color instead of white.", + category = "Potion Letters" + ) + var potionLetterColored = false + private var rebound = false override fun initialize(byConfigManager: Boolean) { diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt new file mode 100644 index 0000000..27a14b3 --- /dev/null +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt @@ -0,0 +1,86 @@ +package org.polyfrost.glintcolorizer.handler + +import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.item.ItemPotion +import net.minecraft.item.ItemStack +import net.minecraft.potion.Potion +import net.minecraft.util.StatCollector +import org.polyfrost.glintcolorizer.config.GlintConfig +import org.polyfrost.glintcolorizer.hook.RenderItemHook + +object PotionLetterHandler { + + private val abbreviations: Map = mapOf( + Potion.moveSpeed.id to "S", + Potion.moveSlowdown.id to "SL", + Potion.digSpeed.id to "HA", + Potion.digSlowdown.id to "MF", + Potion.damageBoost.id to "ST", + Potion.heal.id to "H", + Potion.harm.id to "D", + Potion.jump.id to "J", + Potion.confusion.id to "N", + Potion.regeneration.id to "R", + Potion.resistance.id to "RE", + Potion.fireResistance.id to "F", + Potion.waterBreathing.id to "WB", + Potion.invisibility.id to "I", + Potion.blindness.id to "B", + Potion.nightVision.id to "NV", + Potion.hunger.id to "HU", + Potion.weakness.id to "W", + Potion.poison.id to "P", + Potion.wither.id to "WI", + Potion.healthBoost.id to "HB", + Potion.absorption.id to "A", + Potion.saturation.id to "SA", + ) + + private val labels = HashMap() + + val isEnabled: Boolean + get() = GlintConfig.enabled && GlintConfig.potionLetters + + fun drawsLetter(stack: ItemStack?): Boolean = isEnabled && labelFor(stack) != null + + fun labelFor(stack: ItemStack?): String? { + val item = stack?.item as? ItemPotion ?: return null + val effect = item.getEffects(stack)?.firstOrNull() ?: return null + val id = effect.potionID + val showLevel = GlintConfig.potionLetterLevel && effect.amplifier > 0 + val key = (id shl 9) or ((effect.amplifier and 0xFF) shl 1) or (if (showLevel) 1 else 0) + return labels.getOrPut(key) { + val base = abbreviations[id] ?: fallbackAbbreviation(id) + if (showLevel) base + (effect.amplifier + 1) else base + } + } + + private fun fallbackAbbreviation(id: Int): String { + val potion = Potion.potionTypes.getOrNull(id) ?: return "?" + return StatCollector.translateToLocal(potion.name).take(2).uppercase() + } + + fun render(font: FontRenderer, stack: ItemStack?, x: Int, y: Int) { + if (!isEnabled) return + val label = labelFor(stack) ?: return + val scale = GlintConfig.potionLetterScale + val width = font.getStringWidth(label) * scale + val height = font.FONT_HEIGHT * scale + val corner = GlintConfig.potionLetterCorner + val left = if (corner == 1 || corner == 3) x + 16f - width else x.toFloat() + val top = if (corner >= 2) y + 16f - height + scale else y.toFloat() + val color = if (GlintConfig.potionLetterColored) RenderItemHook.getPotionColor(stack!!) else 0xFFFFFFFF.toInt() + + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + GlStateManager.pushMatrix() + GlStateManager.translate(left, top, 0f) + GlStateManager.scale(scale, scale, 1f) + font.drawStringWithShadow(label, 0f, 0f, color) + GlStateManager.popMatrix() + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } +} diff --git a/src/main/resources/mixins.glintcolorizer.json b/src/main/resources/mixins.glintcolorizer.json index b42be1c..efdffcd 100644 --- a/src/main/resources/mixins.glintcolorizer.json +++ b/src/main/resources/mixins.glintcolorizer.json @@ -5,6 +5,7 @@ "mixins": [ "LayerArmorBaseMixin", "RenderItemMixin_GlintCustomizer", + "RenderItemMixin_PotionLetters", "RenderItemMixin_ShinyEffect", "accessor.RenderItemAccessor" ], From 8ee96e135295d12e6674fa13aa4873956d497cf5 Mon Sep 17 00:00:00 2001 From: Julian Chang Date: Wed, 2 Dec 2026 04:28:13 -0500 Subject: [PATCH 2/2] Fix potion letters with Argentum and PolyCompose hotbar --- .../compat/GuiItemIconsMixin_Argentum.java | 3 +- .../McItemDecorationsMixin_PolyCompose.java | 27 ++++++++++++ .../handler/PotionLetterHandler.kt | 41 +++++++++++++++---- src/main/resources/mixins.glintcolorizer.json | 1 + 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/polyfrost/glintcolorizer/mixin/compat/McItemDecorationsMixin_PolyCompose.java diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/GuiItemIconsMixin_Argentum.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/GuiItemIconsMixin_Argentum.java index 2a07106..62444e3 100644 --- a/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/GuiItemIconsMixin_Argentum.java +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/GuiItemIconsMixin_Argentum.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.item.ItemStack; +import org.polyfrost.glintcolorizer.handler.PotionLetterHandler; import org.polyfrost.glintcolorizer.hook.RenderItemHook; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; @@ -13,7 +14,7 @@ public class GuiItemIconsMixin_Argentum { @ModifyReturnValue(method = "canBake", at = @At("RETURN"), require = 0) private static boolean glintColorizer$shinyPotsStayVanilla(boolean original, ItemStack item) { - return original && !RenderItemHook.INSTANCE.drawsShinyEffect(item); + return original && !RenderItemHook.INSTANCE.drawsShinyEffect(item) && !PotionLetterHandler.INSTANCE.drawsLetter(item); } } diff --git a/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/McItemDecorationsMixin_PolyCompose.java b/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/McItemDecorationsMixin_PolyCompose.java new file mode 100644 index 0000000..ac973dd --- /dev/null +++ b/src/main/java/org/polyfrost/glintcolorizer/mixin/compat/McItemDecorationsMixin_PolyCompose.java @@ -0,0 +1,27 @@ +package org.polyfrost.glintcolorizer.mixin.compat; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import net.minecraft.item.ItemStack; +import org.polyfrost.compose.render.RenderContext; +import org.polyfrost.glintcolorizer.handler.PotionLetterHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(targets = "org.polyfrost.compose.minecraft.mc.McItemDecorations", remap = false) +public class McItemDecorationsMixin_PolyCompose { + + @Inject(method = "draw", at = @At("TAIL"), require = 0) + private void glintColorizer$drawPotionLetter(RenderContext ctx, ItemStack stack, float x, float y, float size, String countOverride, CallbackInfo ci) { + PotionLetterHandler.INSTANCE.render(ctx, stack, x, y, size); + } + + @ModifyReturnValue(method = "key", at = @At("RETURN"), require = 0) + private long glintColorizer$potionLetterKey(long original, ItemStack stack) { + return original * 31 + PotionLetterHandler.INSTANCE.decorationKey(stack); + } + +} diff --git a/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt b/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt index 27a14b3..5af419c 100644 --- a/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt +++ b/src/main/kotlin/org/polyfrost/glintcolorizer/handler/PotionLetterHandler.kt @@ -1,5 +1,6 @@ package org.polyfrost.glintcolorizer.handler +import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer import net.minecraft.client.renderer.GlStateManager import net.minecraft.item.ItemPotion @@ -7,7 +8,9 @@ import net.minecraft.item.ItemStack import net.minecraft.potion.Potion import net.minecraft.util.StatCollector import org.polyfrost.glintcolorizer.config.GlintConfig +import org.polyfrost.compose.render.RenderContext import org.polyfrost.glintcolorizer.hook.RenderItemHook +import java.util.Objects object PotionLetterHandler { @@ -65,22 +68,44 @@ object PotionLetterHandler { if (!isEnabled) return val label = labelFor(stack) ?: return val scale = GlintConfig.potionLetterScale - val width = font.getStringWidth(label) * scale - val height = font.FONT_HEIGHT * scale - val corner = GlintConfig.potionLetterCorner - val left = if (corner == 1 || corner == 3) x + 16f - width else x.toFloat() - val top = if (corner >= 2) y + 16f - height + scale else y.toFloat() - val color = if (GlintConfig.potionLetterColored) RenderItemHook.getPotionColor(stack!!) else 0xFFFFFFFF.toInt() GlStateManager.disableLighting() GlStateManager.disableDepth() GlStateManager.disableBlend() GlStateManager.pushMatrix() - GlStateManager.translate(left, top, 0f) + GlStateManager.translate(x + offsetX(font, label), y + offsetY(font), 0f) GlStateManager.scale(scale, scale, 1f) - font.drawStringWithShadow(label, 0f, 0f, color) + font.drawStringWithShadow(label, 0f, 0f, color(stack!!)) GlStateManager.popMatrix() + GlStateManager.color(1f, 1f, 1f, 1f) GlStateManager.enableLighting() GlStateManager.enableDepth() } + + fun render(ctx: RenderContext, stack: ItemStack, x: Float, y: Float, size: Float) { + if (!isEnabled) return + val label = labelFor(stack) ?: return + val font = Minecraft.getMinecraft().fontRendererObj + val unit = size / 16f + ctx.mcText(label, x + offsetX(font, label) * unit, y + offsetY(font) * unit, color(stack), true, GlintConfig.potionLetterScale * unit) + } + + fun decorationKey(stack: ItemStack): Int { + if (!isEnabled) return 0 + val label = labelFor(stack) ?: return 0 + return Objects.hash(label, GlintConfig.potionLetterScale, GlintConfig.potionLetterCorner, color(stack)) + } + + private fun offsetX(font: FontRenderer, label: String): Float { + val corner = GlintConfig.potionLetterCorner + return if (corner == 1 || corner == 3) 16f - font.getStringWidth(label) * GlintConfig.potionLetterScale else 0f + } + + private fun offsetY(font: FontRenderer): Float { + val scale = GlintConfig.potionLetterScale + return if (GlintConfig.potionLetterCorner >= 2) 16f - font.FONT_HEIGHT * scale + scale else 0f + } + + private fun color(stack: ItemStack): Int = + if (GlintConfig.potionLetterColored) RenderItemHook.getPotionColor(stack) else 0xFFFFFFFF.toInt() } diff --git a/src/main/resources/mixins.glintcolorizer.json b/src/main/resources/mixins.glintcolorizer.json index efdffcd..b0e4659 100644 --- a/src/main/resources/mixins.glintcolorizer.json +++ b/src/main/resources/mixins.glintcolorizer.json @@ -14,6 +14,7 @@ "compat.GuiItemGlintsMixin_Argentum", "compat.GuiItemIconsMixin_Argentum", "compat.LegacyGlintMixin_OverflowAnimations", + "compat.McItemDecorationsMixin_PolyCompose", "compat.McItemGlintMixin_PolyCompose", "ItemEntityRendererMixin_HandleCameraTransforms", "ItemRendererMixin_HandleCameraTransforms"