From 47cb993e9d3a2c6f17764435590c4c125e7995d0 Mon Sep 17 00:00:00 2001 From: Waffles Date: Tue, 25 Jun 2024 12:59:10 -0400 Subject: [PATCH 1/5] fixed bug bug where if u had 0 arrows it still shows 0 instead of nothing --- .../org/polyfrost/evergreenhud/hud/Armour.kt | 125 ++++++++++++++++-- 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt index 8847f2f..f17e6cc 100644 --- a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt +++ b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt @@ -5,13 +5,20 @@ import cc.polyfrost.oneconfig.config.core.OneColor import cc.polyfrost.oneconfig.hud.BasicHud import cc.polyfrost.oneconfig.libs.universal.UGraphics import cc.polyfrost.oneconfig.libs.universal.UMatrixStack -import cc.polyfrost.oneconfig.libs.universal.UMinecraft import cc.polyfrost.oneconfig.platform.Platform import cc.polyfrost.oneconfig.renderer.TextRenderer import cc.polyfrost.oneconfig.utils.dsl.mc +import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper +import net.minecraft.client.renderer.Tessellator +import net.minecraft.client.renderer.WorldRenderer +import net.minecraft.client.renderer.vertex.DefaultVertexFormats import net.minecraft.init.Items +import net.minecraft.item.Item +import net.minecraft.item.ItemBow import net.minecraft.item.ItemStack +import net.minecraft.util.EnumChatFormatting import org.polyfrost.evergreenhud.config.HudConfig import kotlin.math.ceil @@ -90,12 +97,16 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { ) var type = false - @DualOption( - name = "Display Type", - left = "Down", - right = "Up" + @Switch( + name = "Reversed" ) - var displayType = false + var reversed = false + + @Switch(name = "Show durability bar") + var durabilityBar = true + + @Switch(name = "Show Item Amount") + var itemAmount = true @Dropdown( name = "Extra Info", @@ -103,6 +114,11 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { ) var extraInfo = 0 + @Switch( + name = "Dynamic Durability Color" + ) + var dynamicTextColor = false + @Color( name = "Text Color" ) @@ -112,15 +128,24 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { var textType = 0 @DualOption( - name = "Text Alignment", + name = "Text Position", left = "Left", right = "Right", + size = 2 ) var alignment = true @Transient private var actualWidth = 5F @Transient private var actualHeight = 5F @Transient private var translation = 0F + @Exclude private val COLORS = linkedMapOf( + 10 to "4", + 25 to "c", + 40 to "6", + 60 to "e", + 80 to "a", + 100 to "f" + ) override fun draw(matrices: UMatrixStack?, x: Float, y: Float, scale: Float, example: Boolean) { draw(matrices, x, y, scale, getItems(example)) @@ -137,19 +162,19 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { //$$ if (showOffhand) add(shield) //#endif - if (displayType) reverse() + if (reversed) reverse() return@run this } } else { arrayListOf().run { //#if MC<10900 - val inventory = UMinecraft.getPlayer()!!.inventory + val inventory = mc.thePlayer!!.inventory if (showHelmet) inventory.armorInventory[3]?.let { add(it) } if (showChestplate) inventory.armorInventory[2]?.let { add(it) } if (showLeggings) inventory.armorInventory[1]?.let { add(it) } if (showBoots) inventory.armorInventory[0]?.let { add(it) } @Suppress("UNNECESSARY_SAFE_CALL") // on 1.8 ItemStacks can be null - if (showMainHand) UMinecraft.getPlayer()!!.heldItem?.let { add(it) } + if (showMainHand) mc.thePlayer!!.heldItem?.let { add(it) } //#else //$$ if (showHelmet) UMinecraft.getPlayer()!!.getItemStackFromSlot(EntityEquipmentSlot.HEAD).let { if (!it.isEmpty) add(it) } //$$ if (showChestplate) UMinecraft.getPlayer()!!.getItemStackFromSlot(EntityEquipmentSlot.CHEST).let { if (!it.isEmpty) add(it) } @@ -159,11 +184,23 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { //$$ if (showOffhand) UMinecraft.getPlayer()!!.getItemStackFromSlot(EntityEquipmentSlot.OFFHAND).let { if (!it.isEmpty) add(it) } //#endif - if (displayType) reverse() + if (reversed) reverse() return@run this } } + private fun getItemAmount(item: Item): Int { + return mc.thePlayer.inventory.mainInventory.toMutableList().filter { + it?.item == item + }.sumOf { + //#if MC>=11202 + //$$ item.getCount() + //#else + it.stackSize + //#endif + } + } + private fun draw(matrices: UMatrixStack?, x: Float, y: Float, scale: Float, items: List) { val iconSize = 16f val offset = iconSize + padding @@ -194,7 +231,7 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { UGraphics.GL.translate(x / scale, y / scale, 0f) items.forEachIndexed { i: Int, stack: ItemStack -> - val (text, textWidth) = texts[i] + var (text, textWidth) = texts[i] if (!type) actualWidth += texts[i].second + iconSize + if (textWidth > 0) iconPadding else 0 @@ -214,18 +251,31 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { if (!type && i > 0) translation += offset + texts[i - 1].second + if (texts[i - 1].second > 0) iconPadding else 0 + val amount = if (stack.item is ItemBow && !getItemAmount(Items.arrow).toString().equals("0")) getItemAmount(Items.arrow).toString() else null RenderHelper.enableGUIStandardItemLighting() mc.renderItem.zLevel = 200f mc.renderItem.renderItemAndEffectIntoGUI(stack, itemX.toInt() + translation.toInt(), itemY.toInt()) - mc.renderItem.renderItemOverlayIntoGUI(mc.fontRendererObj, stack, itemX.toInt() + translation.toInt(), itemY.toInt(), null) + renderItemOverlayIntoGUI(mc.fontRendererObj, stack, itemX.toInt() + translation.toInt(), itemY.toInt(), amount) RenderHelper.disableStandardItemLighting() + val renderColor = if (dynamicTextColor) java.awt.Color(255, 255, 255).rgb else textColor.rgb + + if (dynamicTextColor && stack.isItemStackDamageable) { + val percentage = ceil((stack.maxDamage - stack.itemDamage).toFloat() / stack.maxDamage.toFloat() * 100f).toInt() + for (color in COLORS) { + if (percentage <= color.key) { + text = "§" + color.value + text + break + } + } + } + UGraphics.GL.pushMatrix() TextRenderer.drawScaledString( text, textX + translation, itemY.toFloat() + mc.fontRendererObj.FONT_HEIGHT / 2f, - textColor.rgb, + renderColor, TextRenderer.TextType.toType(textType), 1f ) @@ -234,6 +284,53 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { UGraphics.GL.popMatrix() } + fun renderItemOverlayIntoGUI(fr: FontRenderer, stack: ItemStack?, xPosition: Int, yPosition: Int, text: String?) { + if (stack != null) { + if (durabilityBar && stack.item.showDurabilityBar(stack)) { + val health = stack.item.getDurabilityForDisplay(stack) + val j = Math.round(13.0 - health * 13.0).toInt() + val i = Math.round(255.0 - health * 255.0).toInt() + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableTexture2D() + GlStateManager.disableAlpha() + GlStateManager.disableBlend() + val tessellator = Tessellator.getInstance() + val worldrenderer = tessellator.worldRenderer + this.draw(worldrenderer, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255) + this.draw(worldrenderer, xPosition + 2, yPosition + 13, 12, 1, (255 - i) / 4, 64, 0, 255) + this.draw(worldrenderer, xPosition + 2, yPosition + 13, j, 1, 255 - i, i, 0, 255) + GlStateManager.enableAlpha() + GlStateManager.enableTexture2D() + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + + if (itemAmount && (stack.stackSize != 1 || text != null)) { + var s = text ?: stack.stackSize.toString() + if (text == null && stack.stackSize < 1) { + s = EnumChatFormatting.RED.toString() + stack.stackSize.toString() + } + + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + fr.drawStringWithShadow(s, (xPosition + 19 - 2 - fr.getStringWidth(s)).toFloat(), (yPosition + 6 + 3).toFloat(), 16777215) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + } + } + + private fun draw(renderer: WorldRenderer, x: Int, y: Int, width: Int, height: Int, red: Int, green: Int, blue: Int, alpha: Int) { + renderer.begin(7, DefaultVertexFormats.POSITION_COLOR) + renderer.pos((x + 0).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + 0).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + renderer.pos((x + width).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() + Tessellator.getInstance().draw() + } + override fun getWidth(scale: Float, example: Boolean): Float = actualWidth * scale override fun getHeight(scale: Float, example: Boolean): Float = actualHeight * scale From eeec9b0850e11cb3d6efa224c0824c8bac0dfa1b Mon Sep 17 00:00:00 2001 From: Waffles Date: Tue, 25 Jun 2024 20:58:34 -0400 Subject: [PATCH 2/5] Update Armour.kt --- .../org/polyfrost/evergreenhud/hud/Armour.kt | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt index a97023c..e12ed76 100644 --- a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt +++ b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt @@ -5,20 +5,18 @@ import cc.polyfrost.oneconfig.config.core.OneColor import cc.polyfrost.oneconfig.hud.BasicHud import cc.polyfrost.oneconfig.libs.universal.UGraphics import cc.polyfrost.oneconfig.libs.universal.UMatrixStack +import cc.polyfrost.oneconfig.libs.universal.UMinecraft import cc.polyfrost.oneconfig.platform.Platform import cc.polyfrost.oneconfig.renderer.TextRenderer import cc.polyfrost.oneconfig.utils.dsl.mc import net.minecraft.client.gui.FontRenderer +import net.minecraft.client.gui.Gui import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper -import net.minecraft.client.renderer.Tessellator -import net.minecraft.client.renderer.WorldRenderer -import net.minecraft.client.renderer.vertex.DefaultVertexFormats import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraft.item.ItemBow import net.minecraft.item.ItemStack -import net.minecraft.util.EnumChatFormatting import org.polyfrost.evergreenhud.config.HudConfig import kotlin.math.ceil @@ -26,7 +24,7 @@ import kotlin.math.ceil //$$ import net.minecraft.inventory.EntityEquipmentSlot //#endif -class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { +class Armour : HudConfig("ArmourHud", "evergreenhud/armour.json", false) { @HUD(name = "Main") var hud = ArmourHud() @@ -135,10 +133,14 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { ) var alignment = true - @Transient private var actualWidth = 5F - @Transient private var actualHeight = 5F - @Transient private var translation = 0F - @Exclude private val COLORS = linkedMapOf( + @Transient + private var actualWidth = 5F + @Transient + private var actualHeight = 5F + @Transient + private var translation = 0F + @Exclude + private val COLORS = linkedMapOf( 10 to "4", 25 to "c", 40 to "6", @@ -168,13 +170,13 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { } else { arrayListOf().run { //#if MC<10900 - val inventory = mc.thePlayer!!.inventory + val inventory = UMinecraft.getPlayer()!!.inventory if (showHelmet) inventory.armorInventory[3]?.let { add(it) } if (showChestplate) inventory.armorInventory[2]?.let { add(it) } if (showLeggings) inventory.armorInventory[1]?.let { add(it) } if (showBoots) inventory.armorInventory[0]?.let { add(it) } @Suppress("UNNECESSARY_SAFE_CALL") // on 1.8 ItemStacks can be null - if (showMainHand) mc.thePlayer!!.heldItem?.let { add(it) } + if (showMainHand) UMinecraft.getPlayer()!!.heldItem?.let { add(it) } //#else //$$ if (showHelmet) UMinecraft.getPlayer()!!.getItemStackFromSlot(EntityEquipmentSlot.HEAD).let { if (!it.isEmpty) add(it) } //$$ if (showChestplate) UMinecraft.getPlayer()!!.getItemStackFromSlot(EntityEquipmentSlot.CHEST).let { if (!it.isEmpty) add(it) } @@ -194,7 +196,7 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { it?.item == item }.sumOf { //#if MC>=11202 - //$$ item.getCount() + //$$ it.getCount() //#else it.stackSize //#endif @@ -251,8 +253,9 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { if (!type && i > 0) translation += offset + texts[i - 1].second + if (texts[i - 1].second > 0) iconPadding else 0 - val amount = if (stack.item is ItemBow && !getItemAmount(Items.arrow).toString().equals("0")) getItemAmount(Items.arrow).toString() else null - + val amount = getItemAmount(Items.arrow).let { + if (stack.item is ItemBow && it != 0) it.toString() else null + } RenderHelper.enableGUIStandardItemLighting() mc.renderItem.zLevel = 200f mc.renderItem.renderItemAndEffectIntoGUI(stack, itemX.toInt() + translation.toInt(), itemY.toInt()) @@ -296,21 +299,28 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { GlStateManager.disableTexture2D() GlStateManager.disableAlpha() GlStateManager.disableBlend() - val tessellator = Tessellator.getInstance() - val worldrenderer = tessellator.worldRenderer - this.draw(worldrenderer, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255) - this.draw(worldrenderer, xPosition + 2, yPosition + 13, 12, 1, (255 - i) / 4, 64, 0, 255) - this.draw(worldrenderer, xPosition + 2, yPosition + 13, j, 1, 255 - i, i, 0, 255) + val x = xPosition + 2 + val y = yPosition + 13 + Gui.drawRect(x, y, x + 13, y + 2, java.awt.Color(0, 0, 0).rgb) + Gui.drawRect(x, y, x + 12, y + 1, java.awt.Color((255 - i) / 4, 64, 0).rgb) + Gui.drawRect(x, y, x + j, y + 1, java.awt.Color(255 - i, i, 0, 255).rgb) GlStateManager.enableAlpha() GlStateManager.enableTexture2D() GlStateManager.enableLighting() GlStateManager.enableDepth() } - if (itemAmount && (stack.stackSize != 1 || text != null)) { - var s = text ?: stack.stackSize.toString() - if (text == null && stack.stackSize < 1) { - s = EnumChatFormatting.RED.toString() + stack.stackSize.toString() + val stackSize = + //#if MC>=11202 + //$$ stack.getCount() + //#else + stack.stackSize + //#endif + + if (itemAmount && (stackSize != 1 || text != null)) { + var s = text ?: stackSize.toString() + if (text == null && stackSize < 1) { + s = "§c$stackSize" } GlStateManager.disableLighting() @@ -323,15 +333,6 @@ class Armour: HudConfig("ArmourHud", "evergreenhud/armour.json", false) { } } - private fun draw(renderer: WorldRenderer, x: Int, y: Int, width: Int, height: Int, red: Int, green: Int, blue: Int, alpha: Int) { - renderer.begin(7, DefaultVertexFormats.POSITION_COLOR) - renderer.pos((x + 0).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() - renderer.pos((x + 0).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() - renderer.pos((x + width).toDouble(), (y + height).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() - renderer.pos((x + width).toDouble(), (y + 0).toDouble(), 0.0).color(red, green, blue, alpha).endVertex() - Tessellator.getInstance().draw() - } - override fun getWidth(scale: Float, example: Boolean): Float = actualWidth * scale override fun getHeight(scale: Float, example: Boolean): Float = actualHeight * scale From a19a19ff33d83aa4a5ae2e2ca32cbcaf923c4669 Mon Sep 17 00:00:00 2001 From: Waffles Date: Fri, 5 Jul 2024 17:23:17 -0400 Subject: [PATCH 3/5] Update Armour.kt --- src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt index be5ab02..0a3e8c7 100644 --- a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt +++ b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt @@ -254,7 +254,9 @@ class Armour : HudConfig("ArmourHud", "evergreenhud/armour.json", false) { if (!type && i > 0) translation += offset + texts[i - 1].second + if (texts[i - 1].second > 0) iconPadding else 0 val amount = getItemAmount(if (stack.item is ItemBow) Items.arrow else stack.item).let { - if (it != 0) it.toString() else null + + if (it != 0 && it != 1) it.toString() + else null } RenderHelper.enableGUIStandardItemLighting() From 91b507a164eeb66d5773de4ddcae1401c5155e5d Mon Sep 17 00:00:00 2001 From: Waffles Date: Sun, 28 Jul 2024 09:46:23 -0400 Subject: [PATCH 4/5] Update Armour.kt --- .../org/polyfrost/evergreenhud/hud/Armour.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt index 0a3e8c7..70f8311 100644 --- a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt +++ b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt @@ -15,8 +15,17 @@ import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper import net.minecraft.init.Items import net.minecraft.item.Item +import net.minecraft.item.ItemAxe import net.minecraft.item.ItemBow +import net.minecraft.item.ItemFishingRod +import net.minecraft.item.ItemFlintAndSteel +import net.minecraft.item.ItemHoe +import net.minecraft.item.ItemPickaxe +import net.minecraft.item.ItemShears +import net.minecraft.item.ItemSpade import net.minecraft.item.ItemStack +import net.minecraft.item.ItemSword +import net.minecraft.item.ItemTool import org.polyfrost.evergreenhud.config.HudConfig import kotlin.math.ceil @@ -255,7 +264,16 @@ class Armour : HudConfig("ArmourHud", "evergreenhud/armour.json", false) { val amount = getItemAmount(if (stack.item is ItemBow) Items.arrow else stack.item).let { - if (it != 0 && it != 1) it.toString() + if (it != 0 && it != 1 && + !(stack.item is ItemHoe) && + !(stack.item is ItemPickaxe) && + !(stack.item is ItemShears) && + !(stack.item is ItemSword) && + !(stack.item is ItemAxe) && + !(stack.item is ItemFishingRod) && + !(stack.item is ItemFlintAndSteel) && + !(stack.item is ItemSpade)) + it.toString() else null } From 10cf3cd348f5dbc9973386c07b007f3ee832f980 Mon Sep 17 00:00:00 2001 From: Waffles Date: Sun, 28 Jul 2024 09:57:51 -0400 Subject: [PATCH 5/5] Update Armour.kt --- src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt index b00232b..1cb1839 100644 --- a/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt +++ b/src/main/kotlin/org/polyfrost/evergreenhud/hud/Armour.kt @@ -262,7 +262,7 @@ class Armour : HudConfig("ArmourHud", "evergreenhud/armour.json", false) { if (!type && i > 0) translation += offset + texts[i - 1].second + if (texts[i - 1].second > 0) iconPadding else 0 - val amount = getItemAmount(if (stack.item is ItemBow) Items.arrow else stack.item).let { + val amount = getItemAmount(if (stack.item is ItemBow) ItemStack(Items.arrow) else stack).let { if (it != 0 && it != 1 && !(stack.item is ItemHoe) &&